works off mouse with graphics

This commit is contained in:
Robin Clark 2019-12-23 14:33:23 +00:00
parent cbd27bef46
commit 83e651b2fa

View File

@ -16,10 +16,48 @@ def redrawAll(canvas):
# draw semi-transparent rectangles in the middle # draw semi-transparent rectangles in the middle
def leftclick(event): def leftclick(event):
print("left") print("player 1")
print event.x, event.y print event.x, event.y
r = event.x/1000.0*3.0 -2.0 + rseed
i = (1000-event.y)/1000.0*2.0 -1.0 + iseed
print "as coords in mandel plane r=",r," i=",i
ro = event.x
io = 1000-event.y
print "as coords to plot x=",ro," y=",1000-io
mm = mandelbrot(r,i,100)
col = get_col(mm)
io = 1000 - io
canvas.create_rectangle(ro, io, ro+10, io+10, fill=col)
if mm > 98:
print "you are in the STABLE zone "
if mm < 21 and mm > 2:
print "you are in the CHAOS zone "
print "Stability factor=",mm," x=",ro,"y=",io
if mm > 20 and mm < 80:
print "you found the RAGGED EDGE OF CHAOS YOU WON PLAYER 2"
draw_complete()
def middleclick(event): def middleclick(event):
print("middle") print("player 2")
print event.x, event.y
r = event.x/1000.0*3.0 -2.0 + rseed
i = (1000-event.y)/1000.0*2.0 -1.0 + iseed
print "as coords in mandel plane r=",r," i=",i
ro = event.x
io = 1000-event.y
print "as coords to plot x=",ro," y=",1000-io
mm = mandelbrot(r,i,100)
col = get_col(mm)
io = 1000 - io
canvas.create_rectangle(ro, io, ro+10, io+10, fill=col)
if mm > 98:
print "you are in the STABLE zone "
if mm < 21 and mm > 2:
print "you are in the CHAOS zone "
print "Stability factor=",mm," x=",ro,"y=",io
if mm > 20 and mm < 80:
print "you found the RAGGED EDGE OF CHAOS YOU WON PLAYER 2"
draw_complete()
def rightclick(event): def rightclick(event):
print("right") print("right")
@ -56,6 +94,8 @@ def get_col(mm):
return "blue" return "blue"
if ( mm > 80 ): if ( mm > 80 ):
return "green" return "green"
if ( mm > 16 ):
return "pink"
if ( mm > 12 ): if ( mm > 12 ):
return "red" return "red"
if ( mm > 8 ): if ( mm > 8 ):
@ -89,21 +129,27 @@ rseed = r
iseed = i iseed = i
def draw_complete(): def draw_complete():
print "draw complete called" print "draw complete called"
for rr in range (0, 100): for rr in range (0, 1000, 10):
print " rr ", rr print " rr ", rr
for ii in range (0, 100): for ii in range (0, 1000, 10):
# for the mandelbrot r = rr/1000.0*3.0 -2.0 + rseed
# the middle of this part is defined by the seeds i = ii/1000.0*2.0 -1.0 + iseed
# rr goes from 0 to 1000 but it means -2.0 to 1.0 #print "as coords in mandel plane r=",r," i=",i
# ii goes from 0 to 1000 but it means -1.0 to 1.0 ro = rr
# the mid point 500,500 is the seed io = 1000-ii
Re = (((rr-500) * 2.0))/100.0 - 1.0 #+ rseed print "as coords to plot x=",ro," y=",1000-io
Im = (((ii-500) * 3.0))/100.0 - 2.0 #+ iseed mm = mandelbrot(r,i,100)
mm = mandelbrot(Re,Im,100) col = get_col(mm)
col = get_col(mm) io = 1000 - io
canvas.create_rectangle(rr*10, 1000-ii*10, rr*10+10, 1000-ii*10+10, fill=col) canvas.create_rectangle(ro, io, ro+10, io+10, fill=col)
if mm > 98:
print "you are in the STABLE zone "
if mm < 21 and mm > 2:
print "you are in the CHAOS zone "
print "Stability factor=",mm," x=",ro,"y=",io
if mm > 20 and mm < 80:
print "you found the RAGGED EDGE OF CHAOS YOU WON PLAYER 2"