Making a Class

Shimry Bao
Data Mining the City
1 min readNov 7, 2017

--

from window import *def setup():
size(500,500)

global window_1
window_1 = Window(10,10,12,30, color(255,255,255))

print window_1.windowWidth
print window_1.area()

global buildingWindows
buildingWindows = []

for w in xrange(5, 150, 5):
window = Window(w*10, 100,w,90,color(255,188,188))
buildingWindows.append(window)
def draw():
background(25,25,25)
# window_1.draw()

for window in buildingWindows:
window.draw()

In the Class Window:

class Window(object):

def __init__(self, x, y, windowWidth, windowHeight, glazing):
self.x = x
self.y = y
self.windowWidth = windowWidth
self.windowHeight = windowHeight
self.glazing = glazing

def area(self):
return self.windowWidth * self.windowHeight

def draw(self):
# fill(self.glazing)
# rect(10, 10, 10 + self.windowWidth, 10 + self.windowHeight)

if self.x < mouseX and mouseX < self.x + self.windowWidth:
fill(0)
#drawing the face
fill(66,188,188)
ellipse(self.x + 20,self.y + 15,20,20)
stroke(255, 255, 255)
fill(255, 0, 0)
ellipse(self.x + 14,self.y + 14,5,5)
ellipse(self.x + 24,self.y + 14,5,5)
line(self.x + 10,self.y + 20,self.x + 30,self.y + 20)
noFill()

else:
fill(self.glazing)

rect(self.x, self.y+10, 10 + self.windowWidth, 10 + self.windowHeight/3)
rect(self.x, self.y, 10 + self.windowWidth, 10 + self.windowHeight)

--

--