Dying to make some ghosts?!
'Tracy the Turtle' is a Pythonic mechanism that allows CodeHS Python programmers to create simple graphical images. The image to the right was made by Tracy. You can see her work by watching the attached movie.
We loved this project so much, we adapted to the JavaScript world! See the Aggie Ghost Challenge inspired by Tracy! Also, check out James C.'s Creating Casper P5JS Processing animation with ghostly variations!
Tracy's Source Code
#----- imports -------------------------------
#----- global variables -----------------------
#----- functions ----------------------------
def hide_tracy():
penup()
setposition(250, 250)
#end hide_tracy
def draw_head(center, r, c):
penup()
setposition(center[0], center[1])
right(90)
forward(r)
left(90)
pendown()
color(c)
begin_fill()
circle(r)
end_fill()
#end draw_head
def draw_body(head_center, r, height, c):
#assumes tracy facing east
if height < r:
height = r
penup()
setposition(head_center[0], head_center[1])
backward(r)
right(90)
pendown()
color(c)
begin_fill()
for side in range(2):
forward(height)
left(90)
forward(2*r)
left(90)
#end for
end_fill()
left(90) #leave no trac(y): boy scouts put her back facing east!
#end draw_body
def draw_feet(head_center, r, height, n, c):
#assumes tracy facing east
if height < r:
height = r
if n < 0:
n = 0
if n > 8:
n = 8
if n == 0: return
#dwr! division is EVIL -
toe_radius = float(r)/n
penup()
setposition(head_center[0], head_center[1])
backward(r)
right(90)
forward(height + toe_radius)
left(90)
forward(toe_radius)
color(c)
for t in range(n):
pendown()
begin_fill()
circle(toe_radius)
end_fill()
penup()
forward(2*toe_radius)
#end for
end_fill()
#end draw_feet
def draw_left_eye(head_center, head_radius, colors):
#assume eye span is 80% of head diameter and is along diameter
#assume eye distance is 4% of head diameter
#assume pupils are at zero degrees from eye center, tangent
#to eye and are 45% of eye width
penup()
setposition(head_center[0], head_center[1])
eye_span = .80*(head_radius * 2)
eye_dist = .04*(head_radius * 2)
eye_radius = (eye_span - eye_dist)/4.0
pupil_radius = .45*eye_radius
backward(eye_dist + eye_radius)
right(90)
forward(eye_radius)
left(90)
pendown()
color(colors[0])
begin_fill()
circle(eye_radius)
end_fill()
penup();
forward(eye_radius)
left(90)
forward(eye_radius)
color(colors[1])
begin_fill()
circle(pupil_radius)
end_fill()
penup();
right(90) #face east
#end draw_left_eye
def draw_right_eye(head_center, head_radius, colors):
#assume eye span is 80% of head diameter and is along diameter
#assume eye distance is 4% of head diameter
#assume pupils are at zero degrees from eye center, tangent
#to eye and are 45% of eye width
penup()
setposition(head_center[0], head_center[1])
eye_span = .80*(head_radius * 2)
eye_dist = .04*(head_radius * 2)
eye_radius = (eye_span - eye_dist)/4.0
pupil_radius = .45*eye_radius
forward(eye_dist + eye_radius)
right(90)
forward(eye_radius)
left(90)
pendown()
color(colors[0])
begin_fill()
circle(eye_radius)
end_fill()
penup();
forward(eye_radius)
left(90)
forward(eye_radius)
color(colors[1])
begin_fill()
circle(pupil_radius)
end_fill()
penup();
right(90) #face east
#end draw_left_eye
def draw_eyes(head_center, head_radius, colors):
#assume eye span is 80% of head diameter and is along diameter
#assume eye distance is 4% of head diameter
#assume pupils are at zero degrees from eye center, tangent
#to eye and are 45% of eye width
draw_left_eye(head_center, head_radius, colors)
draw_right_eye(head_center, head_radius, colors)
#end draw_eyes
def draw_ghost(center, r, height, eye_colors, n, c):
draw_head(center, r, c)
draw_body(center, r, height, c)
draw_feet(center, r, height, n, c)
draw_eyes(center, r, eye_colors)
#end draw_ghost
#----- setup -------------------------------
rate = 4
speed(rate)
#----- main event --------------------------
#guinea pig ghost showing various parts
center = (0,0) #tuple
head_radius = 50
draw_head(center, head_radius, "blue")
draw_body(center, head_radius, 150, "green")
draw_feet(center, head_radius, 150, 10, "pink")
colors = ["yellow", "black"]
draw_left_eye(center, head_radius, colors)
draw_right_eye(center, head_radius, colors)
#orange ghost
center = (100,80)
head_radius = 20
draw_head(center, head_radius, "orange")
draw_body(center, head_radius, 70, "orange")
draw_feet(center, head_radius, 70, 0, "orange")
colors = ["white", "blue"]
draw_left_eye(center, head_radius, colors)
draw_right_eye(center, head_radius, colors)
#purple ghost
center = (-120,150)
head_radius = 30
draw_head(center, head_radius, "purple")
draw_body(center, head_radius, 10, "purple")
draw_feet(center, head_radius, 10, 3, "purple")
colors = ["white", "blue"]
draw_left_eye(center, head_radius, colors)
draw_right_eye(center, head_radius, colors)
#red ghost
center = (-120,-60)
head_radius = 40
draw_head(center, head_radius, "red")
draw_body(center, head_radius, 10, "red")
draw_feet(center, head_radius, 10, 1, "red")
colors = ["white", "red"]
draw_left_eye(center, head_radius, colors)
draw_right_eye(center, head_radius, colors)
#pink ghost
center = (130,-80)
head_radius = 40
height = 90
eye_colors = ["white", "red"]
draw_ghost(center, head_radius, height, eye_colors, 5, "pink")
hide_tracy()
Tracy's Ghostly Challenge
This is Stage 1 of a 'saga' involving making random ghosts.