User:Lidia.Pereira/PNM/Turtle: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 23: Line 23:


[[File:Networked3.png]]
[[File:Networked3.png]]
First (successful) attempt to draw a grid with the turtle:
<syntaxhighlight lang="python">
import turtle
import random
def Poly(n,x):
angle = 360/n
for i in range(n):
turtle.forward(x)
turtle.left(angle)
def makeFlower(p):
for i in range(12):
print Poly(9,p)
turtle.left(30)
def makeTriple():
for i in range(3):
i = (i+1)*5
turtle.color(random.random(),random.random(),random.random())
print makeFlower(i)
xa = - 255
y = - 244
turtle.penup()
turtle.setpos(xa,y)
turtle.pendown()
def column():
for i in range(5):
i=(i+1)*100
makeTriple()
turtle.penup()
turtle.sety(y+i)
turtle.pendown()
def finalGrid():
for i in range(5):
i=(i+1)*100
column()
turtle.penup()
turtle.setx(xa+i)
turtle.penup()
turtle.sety(y)
turtle.pendown()
</syntaxhighlight>
[[File:TurtleGrid.png]]

Revision as of 10:49, 19 September 2013

First experiences with the turtle! (Thank you very much Tamas and Lucia for technical support)

import turtle
import random

def Poly(n,x):
	angle = 360/n
	for i in range(n):
		turtle.forward(x)
		turtle.left(angle)

def loopieLoopie(p):
    for i in range(12):
            print Poly(9,p)
            turtle.left(30)

while(1):
    print loopieLoopie(random.randint(40,100)) 
    turtle.color(random.randint(0,1),random.randint(0,1),random.randint(0,1))

Networked3.png

First (successful) attempt to draw a grid with the turtle:

import turtle
import random

def Poly(n,x):
	angle = 360/n
	for i in range(n):
		turtle.forward(x)
		turtle.left(angle)

def makeFlower(p):
	for i in range(12):
		print Poly(9,p)
		turtle.left(30)

def makeTriple():
	for i in range(3):
		i = (i+1)*5
		turtle.color(random.random(),random.random(),random.random())
		print makeFlower(i)


xa = - 255
y = - 244
turtle.penup()
turtle.setpos(xa,y)
turtle.pendown()

def column():
	for i in range(5):
		i=(i+1)*100
		makeTriple()
		turtle.penup()
		turtle.sety(y+i)
		turtle.pendown()

def finalGrid():
	for i in range(5):	
		i=(i+1)*100
		column()
		turtle.penup()
		turtle.setx(xa+i)
		turtle.penup()
		turtle.sety(y)
		turtle.pendown()

TurtleGrid.png