Created
October 20, 2015 22:34
-
-
Save chaosct/bb982af4bd67b517428d to your computer and use it in GitHub Desktop.
Demo ofxPython presentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#test | |
import random | |
from openframeworks import * | |
print "-"*30 | |
class circle(object): | |
def __init__(self): | |
self.behavior = self.move() | |
def update(self): | |
self.behavior.next() | |
def draw(self): | |
ofSetColor(100,100,100) | |
ofCircle(self.pos.x,self.pos.y,self.size) | |
def move(self): | |
# set initial state | |
direction = ofVec2f() | |
self.pos = ofVec2f(ofRandomWidth(),ofRandomHeight()) | |
self.size = 0 | |
# just wait | |
for _ in range(int(ofRandom(400))): | |
yield | |
# grow | |
while self.size < 9.9: | |
self.size = self.size * 0.9 + 1 | |
yield | |
# move until out of window | |
while ofGetWindowRect().inside(self.pos.x, self.pos.y): | |
# move in the direction | |
self.pos += direction | |
# randomly changing direction | |
direction.x += ofRandomf() | |
direction.y += ofRandomf() | |
# move direction towards buttom-left | |
direction.rotate(0.04*direction.angle(ofVec2f(-1,1))) | |
# reduce size | |
self.size *= 0.99 | |
yield | |
# we regenerate our behavior before ending | |
self.behavior = self.move() | |
yield | |
class myApp(object): | |
def __init__(self): | |
self.obj = [circle() for _ in range(400)] | |
def update(self): | |
for o in self.obj: | |
o.update() | |
def draw(self): | |
for o in self.obj: | |
o.draw() | |
def mouseMoved(self, x, y): | |
pass | |
def mousePressed(self, x, y, button): | |
pass | |
def mouseDragged(self, x, y, buton): | |
pass | |
def mouseReleased(self, x, y, button): | |
pass | |
def keyPressed(self, key): | |
pass | |
def keyReleased(self, key): | |
pass | |
def windowResized(self, width, height): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment