Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- from math import trunc
- import numpy
- import numpy as np
- def x_to_px(x_, x_max, x_min):
- return (x_ - x_min)/(x_max - x_min) * width
- def y_to_px(y_, y_max, y_min):
- return (y_max - y_) / (y_max - y_min) * height
- def draw_small_graph(points: list):
- for coord in range(len(points)):
- fll = points[coord][2]
- size = 1
- c.create_oval(points[coord][0] - size, points[coord][1] - size, points[coord][0] + size,
- points[coord][1] + size, fill=fll, outline=fll)
- def is_int(number):
- if int(number) == float(number):
- return True
- return False
- def gcd(n, m):
- n, m = abs(float(n)), abs(float(m))
- if is_int(n) and is_int(m):
- try:
- if n > m:
- r = n % m
- if r == 0:
- return m
- else:
- return gcd(m, r)
- else:
- r = m % n
- if r == 0:
- return n
- else:
- return gcd(r, n)
- except RecursionError:
- return 1
- except ZeroDivisionError:
- return 1
- else:
- return 1
- def math_of_graph1(x_len, y_len):
- points = []
- for x in np.arange(-x_len, x_len, 0.006):
- for y in np.arange(-y_len, y_len, 0.006):
- if (abs(x**5-y**5)+abs(x**5+y**5)<2) and (x**2+abs(y) >= 1):
- color = "#00FF7F"
- points.append([x, y, color])
- return points
- def math_of_graph2(x_len, y_len):
- points = []
- for x in np.arange(-x_len, x_len, 0.06):
- for y in np.arange(-y_len, y_len, 0.06):
- if (trunc(x)**2 + trunc(y)**2 <= 9) ^ (trunc(x)**2+trunc(y**2) > 4):
- color = "#00FF7F"
- points.append([x, y, color])
- return points
- def convert_to_pixels(points: list, x_max, x_min, y_max, y_min):
- px_points = []
- for i in points:
- px_points.append((x_to_px(i[0], x_max, x_min), y_to_px(i[1], y_max, y_min), i[2]))
- return px_points
- root = Tk()
- root.title("The Plot")
- width = 700
- height = 700
- c = Canvas(root, width=width, height=height, bg="gray15")
- c.pack()
- # Функции. Что бы посмотреть на другой граф, раскомментируйте одну функцию, и закомментируйте другую.
- # draw_small_graph(convert_to_pixels(math_of_graph1(1.5, 1.5), x_max=1.5, x_min=-1.5, y_max=1.5, y_min=-1.5))
- draw_small_graph(convert_to_pixels(math_of_graph2(6, 6), x_max=6, x_min=-6, y_max=6, y_min=-6))
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement