|
@@ -13,12 +13,12 @@ from tkinter import *
|
13
|
13
|
# Create a funktion that draw the rectangles with selected color of the
|
14
|
14
|
# every single pixels in the canvas
|
15
|
15
|
|
16
|
|
-def Mandelbrot(Xmin, Xmax, Ymin, Ymax):
|
|
16
|
+def Mandelbrot(Xmin, Xmax, Ymin, Ymax, lenth, pointssize):
|
17
|
17
|
|
18
|
|
- xscale = float(canvas["width"]) / (Xmax - Xmin) # Calculate the x axis zoom scale of canvas width and range of real part of c
|
19
|
|
- yscale = float(canvas["height"]) / (Ymax - Ymin) # Calculate the y axis zoom scale of canvas height and range of imaginary part of c
|
20
|
|
- xstep = (Xmax - Xmin) / (float(canvas["width"])) # Calculate the changing step im x axis
|
21
|
|
- ystep = (Ymax - Ymin) / (float(canvas["height"])) # Calculate the changing step im y axis
|
|
18
|
+ xscale = lenth / (Xmax - Xmin) # Calculate the x axis zoom scale of canvas width and range of real part of c
|
|
19
|
+ yscale = lenth / (Ymax - Ymin) # Calculate the y axis zoom scale of canvas height and range of imaginary part of c
|
|
20
|
+ xstep = (Xmax - Xmin) / lenth # Calculate the changing step im x axis
|
|
21
|
+ ystep = (Ymax - Ymin) / lenth # Calculate the changing step im y axis
|
22
|
22
|
|
23
|
23
|
x = Xmin # x change from the inputed minimum value Xmin to the inputed maximum value Xmax
|
24
|
24
|
while x < Xmax:
|
|
@@ -30,11 +30,12 @@ def Mandelbrot(Xmin, Xmax, Ymin, Ymax):
|
30
|
30
|
else:
|
31
|
31
|
color = colorlist[c] # If not give it the color with help of the getColor funktion
|
32
|
32
|
|
33
|
|
- canvas.create_rectangle((x - Xmin)*xscale, (y - Ymin)*yscale, # Draw the squares of every single pixels with side length 1 and selected color
|
34
|
|
- (x - Xmin)*xscale, (y - Ymin)*yscale, # The positions have been also multiplied by the zoom scale so it can fit to the
|
35
|
|
- fill=color, outline = color) # canvas when it has been changed
|
36
|
|
- y += ystep
|
37
|
|
- x += xstep
|
|
33
|
+ canvas.create_rectangle((x - Xmin)*xscale, (y - Ymin)*yscale, # Draw a square for every single point
|
|
34
|
+ (x - Xmin)*xscale + pointssize, # with pointssize 4
|
|
35
|
+ (y - Ymin)*yscale + pointssize,
|
|
36
|
+ fill=color,outline="black") # and with selected fillcolor from the colorlist and outline in black in this case (blue outline looks wierd)
|
|
37
|
+ y += pointssize*ystep
|
|
38
|
+ x += pointssize*xstep
|
38
|
39
|
|
39
|
40
|
#--------------------------------------------------------------------------
|
40
|
41
|
# Create a funktion that calculate the time of iterations with gived c and
|
|
@@ -56,26 +57,28 @@ def c_count(c):
|
56
|
57
|
def getColor(iter):
|
57
|
58
|
|
58
|
59
|
for iter in range(i_limit): # The time of iterations changes from 0 to the count limit.
|
59
|
|
- if iter < 3 : # If it's 0 - 2(time of interations: 1 - 3), set the color as 'magenta'.
|
|
60
|
+ if iter < 3 : # If it's 0 - 2 (time of interations: 1 - 3), set the color as 'magenta'.
|
60
|
61
|
colorlist.append('magenta')
|
61
|
|
- elif iter < 7 : # If it's 3 - 6(time of interations: 4 - 7), set the color as 'blue' .
|
|
62
|
+ elif iter < 7 : # If it's 3 - 6 (time of interations: 4 - 7), set the color as 'blue' .
|
62
|
63
|
colorlist.append('blue')
|
63
|
|
- elif iter < 11 : # If it's 7 - 10(time of interations: 8 - 11), set the color as 'green'.
|
64
|
|
- colorlist.append('#00FF00') # I tried just 'green' but it showed dark green instead, so I used rgb color here so the right color can be showed
|
65
|
|
- elif iter < 15 : # If it's 11 - 14(time of interations: 12 - 15), set the color as 'yellow'.
|
|
64
|
+ elif iter < 11 : # If it's 7 - 10 (time of interations: 8 - 11), set the color as 'green'.
|
|
65
|
+ colorlist.append('#00FF00') # I tried just 'green' but it showed dark green instead, so I used rgb color here therefor the right color can be showed
|
|
66
|
+ elif iter < 15 : # If it's 11 - 14 (time of interations: 12 - 15), set the color as 'yellow'.
|
66
|
67
|
colorlist.append('yellow')
|
67
|
|
- else : # If it's 15 or greater(time of interations: 16 or greater), set the color as 'red'.
|
|
68
|
+ else : # If it's 15 or greater (time of interations: 16 or greater), set the color as 'red'.
|
68
|
69
|
colorlist.append('red')
|
69
|
70
|
|
70
|
71
|
#------------------------------------------------------------------------------
|
71
|
72
|
# Main programm
|
72
|
73
|
|
73
|
74
|
i_limit = 20 # The time of iterations will be limited within 20
|
74
|
|
-Xmin = -2.0 # The minimum of real part set -2
|
75
|
|
-Xmax = 0.5 # The maxmimum of real part set 0.5
|
76
|
|
-Ymin = -1 # The minimum of imaginary part set -1
|
77
|
|
-Ymax = 1 # The maximum of imaginary part set 1
|
78
|
|
-lenth = 400 # Set the width and the height of the canvas 400
|
|
75
|
+Xmin = -2.0 # The minimum of real part set as -2
|
|
76
|
+Xmax = 0.5 # The maxmimum of real part set as 0.5
|
|
77
|
+Ymin = -1 # The minimum of imaginary part set as -1
|
|
78
|
+Ymax = 1 # The maximum of imaginary part set as 1
|
|
79
|
+pointsamount = 100 # The amount of points in the both sides set as 100
|
|
80
|
+pointssize = 4 # The size of points set as 4
|
|
81
|
+lenth = pointsamount * pointssize # Set the width and the height of the canvas
|
79
|
82
|
|
80
|
83
|
iter = 0 # Iterations has been initialized
|
81
|
84
|
colorlist = [] # Colorlist has been initialized
|
|
@@ -87,6 +90,6 @@ root.title("Mandelbrotmenge - By Yuan Chen")
|
87
|
90
|
canvas = Canvas(root, width=lenth, height=lenth, bg="white") # The size and background of the window has been set
|
88
|
91
|
canvas.pack() # The window will be showed
|
89
|
92
|
|
90
|
|
-Mandelbrot(Xmin, Xmax, Ymin, Ymax) # The color of every pixel in the canvas has been calculated with help of the Mandelbrot funktion
|
|
93
|
+Mandelbrot(Xmin, Xmax, Ymin, Ymax, lenth, pointssize) # The color of every point has been calculated and showed on th canvas with help of the Mandelbrot funktion
|
91
|
94
|
|
92
|
|
-root.mainloop()
|
|
95
|
+root.update()
|