Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <SFML/Window.hpp>
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <cmath>
- sf::Vector2f c = { -1, 0 };
- double n = 1000, m = 1000;
- int mode = 0;
- bool Process2(double x, double y) {
- double p = (x - 0.25) * (x - 0.25) + y * y;
- double pc = (0.5 - 0.5 * cos(std::atan2l(y, x - 0.25)));
- return p < pc;
- }
- int Process(double x, double y) {
- /*if (Process2(x, y)) {
- return -1;
- }*/
- int ans = 0;
- sf::Vector2f z(0, 0);
- sf::Vector2f c(x, y);
- /*if (mode == 0) {
- c = { x, y };
- z = { 0, 0 };
- }
- else {
- z = { x, y };
- }*/
- while (z.x * z.x + z.y * z.y < 4) {
- z = sf::Vector2f(z.x * z.x - z.y * z.y + c.x, z.x * z.y * 2 + c.y);
- ++ans;
- if (ans > 100) {
- return -1;
- }
- }
- return ans;
- }
- void Create(sf::VertexArray& dots, double crop = 0.002, sf::Vector2f start = { -1, -1 }) {
- double x = start.x;
- int xd = 0;
- while (xd < n) {
- int yd = 0;
- double y = start.y;
- while (yd < m) {
- int k = Process(x, y);
- sf::Vector2f dot(xd, yd);
- dots.append(dot);
- if (k == -1) {
- dots[dots.getVertexCount() - 1].color = sf::Color(0, 0, 0);
- }
- else {
- if (k > 5) {
- dots[dots.getVertexCount() - 1].color = sf::Color(-100 + k * 10,0 + k * 10 , -200 + k * 10);
- }
- else {
- dots[dots.getVertexCount() - 1].color = sf::Color(10 + k * 5, 10 + k * 5, 10 + k * 5);
- }
- //std::cout << k << " ";
- }
- yd += 1;
- y += crop;
- }
- xd += 1;
- x += crop;
- }
- }
- int main() {
- sf::Font font;
- if (!font.loadFromFile("Hack-regular.ttf")) {
- std::cout << "NO FONT";
- return 0;
- }
- sf::VertexArray dots(sf::Points), square(sf::LineStrip);
- sf::RenderWindow window(sf::VideoMode(1000, 1000), "AA");
- int iteration = 0;
- std::vector<std::pair<double, sf::Vector2f>> history;
- sf::Vector2f zoomCords1, zoomCords2;
- bool pressed = false;
- double crop = 0.003;
- sf::Vector2f start = { -2.2, -1.5 };
- Create(dots, crop, start);
- while (window.isOpen()) {
- sf::Event event;
- while (window.pollEvent(event)) {
- if (event.type == sf::Event::Closed) {
- window.close();
- }
- /*if (event.type == sf::Event::KeyPressed) {
- if (event.key == sf::Event::KeyEvent::alt)
- }*/
- if (event.type == sf::Event::MouseButtonPressed) {
- if (event.mouseButton.button == sf::Mouse::Left) {
- zoomCords1.x = event.mouseButton.x;
- zoomCords1.y = event.mouseButton.y;
- pressed = true;
- zoomCords2.x = sf::Mouse::getPosition(window).x;
- zoomCords2.y = sf::Mouse::getPosition(window).y;
- square.clear();
- square.append(zoomCords1);
- square.append(sf::Vector2f(zoomCords1.x, zoomCords2.y));
- square.append(zoomCords2);
- square.append(sf::Vector2f(zoomCords2.x, zoomCords1.y));
- square.append(zoomCords1);
- }
- if (event.mouseButton.button == sf::Mouse::Right) {
- pressed = false;
- dots.clear();
- if (history.size()) {
- std::pair<double, sf::Vector2f> pair = *(history.end() - 1);
- history.pop_back();
- crop = pair.first;
- start = pair.second;
- Create(dots, pair.first, pair.second);
- }
- }
- }
- if (event.type == sf::Event::MouseMoved) {
- if (pressed) {
- zoomCords2.x = sf::Mouse::getPosition(window).x;
- zoomCords2.y = sf::Mouse::getPosition(window).y;
- square.clear();
- square.append(zoomCords1);
- square.append(sf::Vector2f(zoomCords1.x, zoomCords2.y));
- square.append(zoomCords2);
- square.append(sf::Vector2f(zoomCords2.x, zoomCords1.y));
- square.append(zoomCords1);
- }
- }
- if (event.type == sf::Event::MouseButtonReleased) {
- if (event.mouseButton.button == sf::Mouse::Left) {
- pressed = false;
- history.push_back(std::make_pair(crop, start));
- double height = abs(square[0].position.y - square[1].position.y);
- double width = abs(square[0].position.x - square[2].position.x);
- sf::Vector2f topLeft(std::min(square[0].position.x, square[2].position.x),std::min(square[0].position.y, square[1].position.y));
- if (height > width) {
- start.y = start.y + topLeft.y * crop;
- start.x = start.x + (topLeft.x) * crop;
- crop = crop * (height / 1000);
- }
- else {
- start.y = start.y + topLeft.y * crop;
- start.x = start.x + (topLeft.x) * crop;
- crop = crop * (width / 1000);
- }
- square.clear();
- dots.clear();
- Create(dots, crop, start);
- }
- }
- }
- window.clear(sf::Color::Black);
- window.draw(dots);
- if (pressed) {
- window.draw(square);
- }
- window.display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement