Share Pastebin
Guest
Public paste!

DrLecter

By: a guest | Feb 9th, 2010 | Syntax: Python | Size: 2.15 KB | Hits: 15 | Expires: Never
Copy text to clipboard
  1. from tkinter import *
  2. from math import *
  3.  
  4. def reset():
  5.     global zoom,smooth,limit
  6.     zoom=30
  7.     smooth=6
  8.     limit=360
  9.     espiral()
  10.  
  11. def zoomin():
  12.     global zoom
  13.     if zoom<100:
  14.         zoom+=10
  15.     espiral()
  16.  
  17. def zoomout():
  18.     global zoom
  19.     if zoom>10:
  20.         zoom-=10
  21.     espiral()
  22.  
  23. def smoothup():
  24.     global smooth
  25.     if smooth<10:
  26.         smooth+=1
  27.     espiral()
  28.  
  29. def smoothdown():
  30.     global smooth
  31.     if smooth>1:
  32.         smooth-=1
  33.     espiral()
  34.  
  35. def limitup():
  36.     global limit
  37.     if limit<1000:
  38.         limit+=10
  39.     espiral()
  40.  
  41. def limitdown():
  42.     global limit
  43.     if limit>10:
  44.         limit-=10
  45.     espiral()
  46.  
  47. def punto_cartesiano(x,y,x0,y0,color1,color2):
  48.     global zoom
  49.     A1=(x*zoom+250)
  50.     A2=(500-(y*zoom+250))
  51.     A3=(x0*zoom+250)
  52.     A4=(500-(y0*zoom+250))
  53.     l.create_line(A1,A2,A3,A4,fill=color1)
  54.     l.create_line(A1,A2,A1+1,A2-1,fill=color2)
  55.  
  56. def espiral():
  57.   global zoom,smooth,limit
  58.   l.delete(ALL)
  59.   l.create_line(0,250,500,250,fill="#B0B0B0")
  60.   l.create_line(250,0,250,500,fill="#A0A0A0")
  61.   l.create_text(62,12,text="Z:"+str(zoom)+",S:"+str(smooth)+",A:"+str(limit))
  62.   x0,y0,x1,y1=[0]*4
  63.   for J in range(0,limit):
  64.     rho=J/smooth
  65.     r=sqrt(rho)
  66.     s=r*-1
  67.     x,y=r*cos(rho),r*sin(rho)
  68.     x2,y2=s*cos(rho),s*sin(rho)
  69.     punto_cartesiano(x,y,x0,y0,"red","green")
  70.     punto_cartesiano(x2,y2,x1,y1,"blue","cyan")
  71.     x0,y0,x1,y1=x,y,x2,y2
  72.  
  73. #main/UI:
  74. U = Tk()
  75. U.title("La espiral de Fermat")
  76. l=Canvas(U,width=500,height=500,bg="white")
  77. l.pack()
  78. b1=Button(U,text="Zoom +",command=zoomin)
  79. b1.pack(side=LEFT,padx=1,pady=1)
  80. b2=Button(U,text="Zoom -",command=zoomout)
  81. b2.pack(side=LEFT,padx=1,pady=1)
  82. b3=Button(U,text="Smooth +",command=smoothup)
  83. b3.pack(side=LEFT,padx=1,pady=1)
  84. b4=Button(U,text="Smooth -",command=smoothdown)
  85. b4.pack(side=LEFT,padx=1,pady=1)
  86. b5=Button(U,text="A +",command=limitup)
  87. b5.pack(side=LEFT,padx=1,pady=1)
  88. b6=Button(U,text="A -",command=limitdown)
  89. b6.pack(side=LEFT,padx=1,pady=1)
  90. b7=Button(U,text="Reset",command=reset)
  91. b7.pack(side=LEFT,padx=1,pady=1)
  92. b8=Button(U,text="Salir",command=exit)
  93. b8.pack(side=LEFT,padx=1,pady=1)
  94.  
  95.  
  96. reset()