def draw(self): pyp.pushMatrix() pyp.noStroke() pyp.fill(self.fill_color) pyp.translate(*self.position) self.draw_poly() pyp.popMatrix()
def branches(height): height *= 0.66 # draw left and right branch for angle in [-0.5, 0.5]: p.pushMatrix() p.rotate(angle) p.line(0, 0, 0, -height) p.translate(0, -height) p.popMatrix()
def wrapped_f(): p.pushMatrix() p.translate(240, 0) p.applyMatrix( -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) f() p.popMatrix()
def draw(): p.background(0) # draw tree trunk and move to its top p.translate(200, 400) p.line(0, 0, 0, -120) p.translate(0, -120) # draw the branches branches(120)
def draw(): p.background(255) mouse = np.array([p.mouse.x, p.mouse.y]) center = np.array([width/2, height/2]) mouse = mouse - center p.translate(width/2, height/2) p.strokeWeight(2) p.stroke(0) p.line(0, 0, mouse[0], mouse[1])
def draw(): p.background(0) # draw tree trunk and move to its top p.translate(200, 400) p.line(0, 0, 0, -120) p.translate(0, -120) angle = math.pi * p.mouse.x / 800 # draw the branches branches(120, angle)
def draw(): pp.background(0x000000) pp.translate(width/2.0, height/2.0, -height/4.0 + 500) # +500 is a kludge to make big defineLights() update() pp.lights() try: data = queue.get_nowait() if data: set_values(data) except: pass drawLEDs(network)
def drag_segment(i, head_x, head_y): # find the inclination of a segment with respect to X axis angle = math.atan2(head_y - y[i], head_x - x[i]) # find tail position by rotating a segment around its head point x[i] = head_x - math.cos(angle) * LENGTH y[i] = head_y - math.sin(angle) * LENGTH # draw a segment (tail to head) p.pushMatrix() p.translate(x[i], y[i]) p.rotate(angle) p.line(0, 0, LENGTH, 0) p.popMatrix()
def branches(height, angle): height *= 0.66 # finish branching when height is small if height < 3: return # draw left and right branch for angle in [-angle, angle]: p.pushMatrix() p.rotate(angle) p.line(0, 0, 0, -height) p.translate(0, -height) branches(height, angle) p.popMatrix()
def draw(): p.background(255) mouse = np.array([p.mouse.x, p.mouse.y]) center = np.array([width/2, height/2]) mouse -= center m = np.linalg.norm(mouse) p.fill(0) p.noStroke() p.rect(0,0,m,10) p.translate(width/2, height/2) p.strokeWeight(2) p.stroke(0) p.line(0, 0, mouse[0], mouse[1])
def drawLEDs(network): for n in network.G.nodes_iter(): pp.pushMatrix() pp.noStroke() pp.translate(*n.coords) pp.fill(pp.color(100, 100, 100)) #all nodes are grey for now pp.sphere(1) pp.popMatrix() pp.strokeWeight(3) for e in network.G.edges_iter(data=True): pp.pushMatrix() pp.stroke( pp.color(*e[2]['color']) ) (x1, y1, z1) = e[0].coords (x2, y2, z2) = e[1].coords pp.line( x1, y1, z1, x2, y2, z2 ) pp.popMatrix()
def draw(): p.background(255) # vector that points to the mouse location mouse = np.array([p.mouse.x, p.mouse.y], dtype=float) # vector that points to the center of the window center = np.array([width/2, height/2]) # subtract center from mouse, gives vector pointing from center to mouse mouse -= center # normalize the vector mouse /= np.linalg.norm(mouse) # multiply length mouse *= 150 # draw the resulting vector p.translate(width/2, height/2) p.strokeWeight(2) p.stroke(0) p.line(0, 0, mouse[0], mouse[1])
def draw(): p5.colorMode(p5.RGB) p5.background(0) if len(projection): p5.pushMatrix() p5.colorMode(p5.HSB) p5.translate(width/4, height/4) p5.scale(width/2, height/2) for point, label in zip(projection, labels): p5.stroke(p5.color(label * 26., 255, 255)) p5.point(point[0], point[1]) p5.popMatrix() #send osc to MaxPatch probability_lda = model.predict_proba([getAmplitude(recent)]) send_osc_message("/lda",probability_lda) probability_svc = clf.predict_proba([getAmplitude(recent)]) send_osc_message("/svm",probability_svc) cur = model.transform([getAmplitude(recent)]) cur = cur[0] cur = (cur - p_min) / (p_max - p_min) global predicted if predicted == None: predicted = cur else: predicted = predicted * .9 + cur * .1 p5.stroke(p5.color(0, 0, 255)) p5.ellipse(width/4 + predicted[0] * width/2, height/4 + predicted[1] * height/2, 10, 10) elif len(recent): # draw time-amplitude p5.pushMatrix() p5.translate(0, height/2) p5.scale(width / N, height/2) p5.stroke(255) p5.noFill() p5.beginShape() for x, y in enumerate(recent): p5.vertex(x, y) p5.endShape() p5.popMatrix() # draw frequency-amplitude amp = getAmplitude(recent) p5.pushMatrix() p5.translate(0, height) p5.scale(width, -height) p5.stroke(255) p5.noFill() p5.beginShape() for x, y in enumerate(amp): p5.vertex(math.log(1+x, len(amp)), pow(y, .5)) p5.endShape() p5.popMatrix()
def wrapped_f(): p.pushMatrix() p.translate(0, 240) p.rotate(-math.pi / 2) f() p.popMatrix()
#!/usr/bin/evn python # coding=utf-8 """ Star. """ import math import pyprocessing as p p.size(400, 400) p.colorMode(p.HSB, 360, 100, 100, 100) p.noStroke() p.background(0) # TODO: try to change the alpha value p.fill(0, 100, 100, 40) # shift the (0, 0) point p.translate(200, 200) # TODO: try to change the number of triangles for i in range(10): # rotate around (0, 0) by 1/10th of a full angle p.rotate(2 * math.pi / 10) p.triangle(0, -200, 100, 100, -100, 100) p.run()
def flip(f): p.translate(240, 0) p.scale(-1, 1)
def above(*args): scale = 1.0 / len(args) p.scale(1, scale) for f in args[:-1]: f() p.translate(0, 240)
def rotate(f): p.translate(0, 240) p.rotate(-math.pi / 2)
#!/usr/bin/evn python # coding=utf-8 """ Composition. Square Limit. """ import math import pyprocessing as p p.size(800, 800) p.background(255) p.translate(300, 300) img = p.loadImage("fish.png") def fish(): p.image(img, -80, -80) def transform(t, *args): def wrapper(*args): def wrapped_f(): p.pushMatrix() t(*args) # perform transformation t args[-1]() # call function f p.popMatrix() return wrapped_f return wrapper @transform def rotate(f): p.translate(0, 240)
def beside(*args): scale = 1.0 / len(args) p.scale(scale, 1) for f in args[:-1]: f() p.translate(240, 0)
def beside(f, g): p.scale(0.5, 1) f() p.translate(240, 0)
def above(f, g): p.scale(1, 0.5) f() p.translate(0, 240)