Dress up Little Ghost

Jujie Xu
Data Mining the City
2 min readNov 1, 2017

Choose hat shape: Topper(t), Pointed Hat(p), or Cap(c)!

Choose hat band color: Red(r), Blue(b), or Yellow(y)!

Choose hat brim size: Long(l) or Short(s)!

Dress up this cute ghost for Halloween!

Halloween Special
from hat import *
def setup():
size(800,1000)
background(0)
img = loadImage("ghost.png")
image(img, 0, 0)


def draw():
textSize(15)
fill(255)
text('HAT SHAPE: t/p/c',600,820)
text('HAT BAND COLOR: r/b/y',600,840)
text('HAT BRIM TYPE: l/s',600,860)
hat = Hat('None','None','None')
if (keyPressed):
hat.hatShape = key
if (keyPressed):
hat.hatBand = key
if (keyPressed):
hat.hatBrim = key

hat.draw()

Class Hat

class Hat(object):

def __init__(self, hatShape,hatBand,hatBrim):
self.hatShape = hatShape
self.hatBand = hatBand
self.hatBrim = hatBrim

def draw(self):
if self.hatShape == 'p':
fill(137,137,137)
noStroke
#drawing the triangle hat
triangle(215,157,202,480,456,383)
if self.hatShape == 't':
fill(137,137,137)
noStroke
#drawing the square hat
quad(202,480,456,383,385,200,133,297)
if self.hatShape == 'c':
fill(137,137,137)
noStroke
#drawing the round hat
arc(329, 431.5, 272, 272, PI-atan(48.5/127), TWO_PI-atan(48.5/127))

if self.hatBand == 'b':
fill(126,206,244)#blue
quad(202,480,456,383,443,356,192,452)
if self.hatBand == 'r':
fill(237,105,65)#red
quad(202,480,456,383,443,356,192,452)
if self.hatBand == 'y':
fill(255,244,92)#yellow
quad(202,480,456,383,443,356,192,452)

if self.hatBrim == 's':
fill(83,83,83)
quad(202,480,456,383,459,389,202,487)
if self.hatBrim == 'l':
fill(83,83,83)
quad(174,486,178,496,504,372,500,362)

--

--