Skip to content

Instantly share code, notes, and snippets.

@villares
Last active October 31, 2017 14:08
Show Gist options
  • Save villares/d059f624a2bdd597f949dabfd9e8f9f7 to your computer and use it in GitHub Desktop.
Save villares/d059f624a2bdd597f949dabfd9e8f9f7 to your computer and use it in GitHub Desktop.
def setup():
""" Create a Bandeirinha instance """
global flag
size(100, 100) # Canvas size
flag = Bandeirinha(width / 2, height / 2)
def draw():
""" The 'main loop' invoked by Processing """
background(0) # Cleans the canvas, with black
flag.plot()
flag.move()
class Bandeirinha(object):
def __init__(self, x, y, flag_size = 50):
self.x = x
self.y = y
self.size = flag_size
def plot(self):
half_flag = self.size / 2
with pushMatrix(): # preserve the original coordinate system
translate(self.x, self.y) # change the origin
beginShape() # start a shape/polygon
vertex(-half_flag, -half_flag)
vertex(-half_flag, half_flag)
vertex(0, 0)
vertex(half_flag, half_flag)
vertex(half_flag, -half_flag)
endShape(CLOSE) # ends the polygon, closing on 1st vertex
def move(self):
self.x += 1 # increments x
self.y += 1 # increments y
if self.x > width + 25:
self.x = -25
if self.y > height + 25:
self.y = -25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment