repl.it
@jessenaomi1/

jesse23

Python (with Turtle)

jesseamaya

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import turtle, random

# Create a new turtle called t
t = turtle.Turtle()
# Setting the speed to 0 makes the turtle 
# move as fast as it can
t.speed(0)

t.pencolor("lightgreen")
# The turtle's pen is normally down and if left in this
# position will draw a line from its starting
# point to where the mouse is clicked
t.penup()

screen = turtle.Screen()
# Set the screen background color to black
screen.bgcolor("black")

def get_mouse_click_coordinates(x, y):
  # Call the draw_spiral function passing in the x y
  # coordiantes and the turtle
  draw_spiral(t,x,y) 

# When the screen is clicked the get_mouse_click_coordinates
# function is called and passed the x, y 
# coordinates of the mouse
screen.onscreenclick(get_mouse_click_coordinates)


# The variables length, step and num_sides are given 
# default values. This means they can be omitted when the
# function is called, and the default values will be used
def draw_spiral(t, x, y, length = 20, step = 2, num_sides = 40):
  # Move the turtle to where the mouse was clicked
  t.goto(x,y)
  # Calculate a random angle between 90 and 180 degrees
  # for it to turn through at each corner of the spiral
  angle = random.randint(90, 180)
  t.pendown()
  for i in range(num_sides):
    t.forward(length)    
    t.left(angle)
    length += step
  t.penup()
result
console
?