User:Lucia Dossin/Protyping/Assignment 1: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "= Python & Turtle = circle.py import turtle #by changing the value of step, the resulting graphic changes #the larger step is, the less accurate the curve is (and the fas...")
 
No edit summary
 
Line 1: Line 1:
= Python & Turtle =
= Python & Turtle =
circle.py
circle.py
<source lang="python">
  import turtle
  import turtle
   
   
Line 16: Line 17:
   
   
  turtle.exitonclick()
  turtle.exitonclick()
</source>


graphical result (used 60, 50, 10, 1, 0.5 and 0.1 as step)
graphical result (used 60, 50, 10, 1, 0.5 and 0.1 as step)

Latest revision as of 10:57, 30 September 2013

Python & Turtle

circle.py

 import turtle
 
 #by changing the value of step, the resulting graphic changes
 #the larger step is, the less accurate the curve is (and the faster the circle is rendered)
 step = 10
 #to have a full circle path, divide 360 by the step value. int() assures the result is an integer
 rg = int(360 / step)
 
 for i in range(rg):
     turtle.forward(step)
     turtle.left(step)
     #if you print(i) you will see the number of steps that were needed to make the circle
     #print(i) 
 
 turtle.exitonclick()

graphical result (used 60, 50, 10, 1, 0.5 and 0.1 as step) Circles.png

circle_function.py

import turtle

#turtle.circle(radius, extent=None, steps=None)

for i in range(0, 180, 30):
    turtle.circle(i)

turtle.exitonclick()

graphical result

Circle function.png

circle_function_centric.py same as previous function, but reseting the turtle position so that the circles have the same center

import turtle

for i in range(0, 180, 30):    
    turtle.pd()
    turtle.circle(i)
    turtle.pu()
    turtle.goto(0,-i)

turtle.exitonclick()

graphical result

Circle function centric.png

centric_expansion.py

import turtle

for i in range(360):
    turtle.forward(i)
    turtle.left(i)

graphical result

Centric-expansion.png