Advertisement
Rendier

Theodorus Spiral First Draft

Sep 26th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import turtle
  5. import tkinter as tk
  6. from math import *
  7.  
  8. def forward(): # Pixels
  9.     t.forward(100)
  10.  
  11. def back(): # Pixels
  12.     t.back(100)
  13.  
  14. def left(): # Deg
  15.     t.left(90)
  16.  
  17. def right(): # Deg
  18.     t.right(90)
  19.    
  20. def theodorusSpiral():
  21.    
  22.     unit = 100 # Pixels
  23.     radius = 100 * sqrt(2)
  24.     lastradius = 1
  25.     angle = 45
  26.     lastangle = 0
  27.    
  28.     triangle(radius, angle)
  29.     for i in range(1, 17):
  30.        
  31.         print("R:", radius, "A:", angle, "LR:", lastradius, "LA:", lastangle)
  32.  
  33.         # Angle Growth Rate = arctan(1/sqrt(n))
  34.         # Radius Growth Rate = sqrt(n + 1) - sqrt(n)
  35.  
  36.         if i == 1: # Skipping first number because of bug TODO
  37.            
  38.             pass
  39.        
  40.         else:
  41.            
  42.             t.setheading(lastangle)
  43.             t.forward(lastradius)
  44.             t.left(90)# Deg
  45.             t.forward(unit)
  46.             t.goto(0, 0)
  47.        
  48.         lastangle = angle
  49.         angle += atan(1 / sqrt(i + 1)) * (180 / pi)
  50.         lastradius = radius
  51.         radius += 100 * (sqrt(i + 2) - sqrt(i + 1))
  52.    
  53.     pass
  54.  
  55. def triangle(radius, angle, unit=100):
  56.    
  57.     t.forward(100)
  58.     t.left(90)
  59.     t.forward(unit)
  60.     t.left(180 + angle)
  61.     t.goto(0, 0)
  62.     t.setheading(0)
  63.    
  64.     # t.left(angle)
  65.     # t.forward(radius)
  66.     # t.right(180 - angle)
  67.     # t.forward(unit)
  68.     # t.right(90)
  69.     # t.goto(0, 0)
  70.     # t.setheading(0)
  71.    
  72.    
  73.     pass
  74.  
  75. root = tk.Tk()
  76. canvas = tk.Canvas(master = root, width = 900, height = 700)
  77. canvas.pack()
  78.  
  79. t = turtle.RawTurtle(canvas)
  80. t.pencolor("#ff0000") # Red
  81.  
  82. t.penup()   # Regarding one of the comments
  83. t.pendown() # Regarding one of the comments
  84.  
  85. tk.Button(master = root, text = "Forward", command = forward).pack(side = tk.LEFT)
  86. tk.Button(master = root, text = "Back", command = back).pack(side = tk.LEFT)
  87. tk.Button(master = root, text = "Left", command = left).pack(side = tk.LEFT)
  88. tk.Button(master = root, text = "Right", command = right).pack(side = tk.LEFT)
  89. tk.Button(master = root, text = 'Spiral', command = theodorusSpiral).pack(side = tk.LEFT)
  90.  
  91. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement