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 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 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(): 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() t(*args) # perform transformation t args[-1]() # call function f p.popMatrix()
def wrapped_f(): p.pushMatrix() t(*args) # perform transformation t args[-1]() # call last argument as function p.popMatrix()
def wrapped_f(): p.pushMatrix() p.translate(0, 240) p.rotate(-math.pi / 2) f() p.popMatrix()