Created
February 21, 2014 03:26
-
-
Save macloo/9128214 to your computer and use it in GitHub Desktop.
Use random numbers to make 100 circles with Python's turtle module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # fun with turtle, a Python module | |
| # draw 100 circles of many colors | |
| # http://docs.python.org/3.1/library/turtle.html | |
| # http://static.michael0x2a.com/turtle_examples.html | |
| # http://www.eg.bucknell.edu/~hyde/Python3/TurtleDirections.html | |
| import random | |
| import time | |
| import turtle | |
| t = turtle.Pen() | |
| win = turtle.Screen() | |
| win.bgcolor("lightgreen") | |
| win.title("Love Turtles") | |
| def mycircle(red, green, blue): | |
| t.color(red, green, blue) | |
| t.begin_fill() | |
| x = random.randint(10,100) | |
| t.circle(x) # draw a circle of random radius | |
| t.end_fill() | |
| t.up() # pick up pen | |
| y = random.randint(0,360) | |
| t.seth(y) # set heading to random direction | |
| # t.xcor() is turtle's x; t.ycor() is turtle's y | |
| if t.xcor() < -300 or t.xcor() > 300: | |
| t.goto(0, 0) # this is the center | |
| elif t.ycor() < -300 or t.ycor() > 300: | |
| t.goto(0, 0) # this is the center | |
| z = random.randint(0,100) | |
| t.forward(z) # move a random number of pixels | |
| t.down() # pen down | |
| for i in range(0, 100): | |
| a = random.randint(0,100)/100.0 | |
| b = random.randint(0,100)/100.0 | |
| c = random.randint(0,100)/100.0 | |
| mycircle(a, b, c) # feed a random color to the function | |
| time.sleep(10) |
import turtle import random x=random.randint screen=turtle.Screen() screen.setup(620,620) screen.bgcolor('black') turtle.pensize(3) turtle.speed(0) n=-1 for angle in range(0,360,15): n=n+1 if n==6: n=-1 turtle.color("red") turtle.seth(angle) turtle.circle(100) turtle.penup() turtle.setpos(150,-270) turtle.pendown() turtle.pencolor('olive') turtle.write('modified by Rick Weinberg',font=("Arial", 12, "normal")) turtle.ht()
I want to use your random.randint method for making my pen color random. I want my circles not to be all red but random colors. Please help?
Wooooooooooow It's so amazing
great
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need help with understanding all of this.