def draw(): # find all elements touching another element lines = [] for a, b in itertools.combinations(elements, 2): distance = math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2) if distance < 0.5 * (a.size + b.size): a.touching.append(b) b.touching.append(a) lines.append((a.x, a.y, b.x, b.y, distance)) if lines: # sort lines by length lines.sort(key=lambda x: x[-1]) # map distance to colour # TODO: try using a smaller hue range scale = 360.0 / len(lines) colours = (scale * i for i in range(len(lines))) # draw lines between elements for colour, line in itertools.izip(colours, lines): # TODO: try removing the alpha channel p.stroke(colour, 100, 100, 10) p.line(line[0], line[1], line[2], line[3]) # move all elements for e in elements: if e.touching: e.rotate() e.move_away() else: e.move()
def setup(): size(100, 100) background(255) fill(0) stroke(0) stroke_weight(10) frame_rate(60)
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 display(self): p.ellipseMode(p.CENTER) p.strokeWeight(4) p.stroke(0) if self.dragging: p.fill(50) elif self.rollover: p.fill(100) else: p.fill(175,200) p.ellipse(self.location.x, self.location.y, self.mass*2, self.mass*2)
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) # pick a random number and increase the count index = randint(0,len(randomCounts)-1) randomCounts[index] += 1 # draw a rectangle to graph results p.stroke(0); p.strokeWeight(2); p.fill(127); w = width/len(randomCounts) for x in range(0,len(randomCounts)): p.rect(x*w, height-randomCounts[x], w-1, randomCounts[x])
def draw(): global x,y,xspeed,yspeed p.background(255) x += xspeed y += yspeed if x > width or x < 0: xspeed *= -1 if y > height or y < 0: yspeed *= -1 p.stroke(0) p.strokeWeight(2) p.fill(127) p.ellipse(x, y, 48, 48)
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 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 draw(): p.noStroke() p.fill(255,10) p.rect(0,0,width,height) # add current speed to location location.add(velocity) if location.x > width or location.x < 0: velocity.x *= -1 if location.y > height or location.y < 0: velocity.y *= -1 # display circle at location p.stroke(0) p.fill(175) p.ellipse(location.x, location.y, 16, 16)
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])
#!/usr/bin/evn python # coding=utf-8 """ Pattern. """ import pyprocessing as p p.size(255, 255) for x in range(256): for y in range(256): colour = x ^ y p.stroke(colour) p.point(x, y) p.run() """ ^ is bitwise exclusive or (xor) 0 ^ 0 = 1 ^ 1 = 0 1 ^ 0 = 0 ^ 1 = 1 Example: 100101 ^ 101001 = 001100 """
def setup(): p.size(400, 400) p.stroke(255)
def display(self): p.stroke(0) p.strokeWeight(2) p.fill(127) p.ellipse(self.location.x, self.location.y, 48, 48)
def draw_screen(points, slopes, line_segments, arc_segments): # Setup processing import pyprocessing as proc proc.size(VIEW_WIDTH, VIEW_HEIGHT) proc.smooth() proc.background(255, 255, 255) proc.ellipseMode(proc.RADIUS) # Prepare camera bbox = BoundingBox(points) eye_x = bbox.min_x + bbox.width / 2.0 eye_y = bbox.min_y + bbox.height / 2.0 eye_z = (1.5 * max(bbox.width, bbox.height) / 2.0) / sin(radians(50)) center_x = bbox.min_x + bbox.width / 2.0 center_y = bbox.min_y + bbox.height / 2.0 proc.camera( eye_x, eye_y, eye_z, center_x, center_y, 0, 0, 1, 0) if RENDER_CIRCLES: proc.noFill() proc.stroke(232, 232, 232) for arc in arc_segments: proc.ellipse(arc.c[0], arc.c[1], arc.r, arc.r) if RENDER_SLOPES: proc.stroke(127, 127, 127) for k in range(len(points)): if slopes[k]: p = points[k] s = slopes[k].vector / norm(slopes[k].vector) # normalize x0 = p.x() - s[0] * SLOPE_LENGTH y0 = p.y() - s[1] * SLOPE_LENGTH x1 = p.x() + s[0] * SLOPE_LENGTH y1 = p.y() + s[1] * SLOPE_LENGTH proc.line(x0, y0, x1, y1) # line_segments proc.stroke(0, 0, 0, 255) for line in line_segments: proc.line(line.a.x(), line.a.y(), line.b.x(), line.b.y()) # arc_segments proc.noFill() proc.stroke(255, 0, 0, 255) for arc in arc_segments: proc.arc(arc.c[0], arc.c[1], arc.r, arc.r, arc.alfa, arc.beta) # Points proc.fill(255, 0, 0) proc.stroke(0, 0, 0) for p in points: proc.rect(p.x() - BOX_WIDTH / 2.0, p.y() - BOX_WIDTH / 2.0, BOX_WIDTH, BOX_WIDTH) # Execute! :-) proc.run()
def display(self): """Displays mover as circle.""" p.stroke(0) p.strokeWeight(2) p.fill(127) p.ellipse(self.location.x, self.location.y, 48, 48)
def draw(self): stroke(53) text(self.char, self.x, self.y, U*5, U*5) self.tick()
def setup(): size(640, 360) stroke(255) frame_rate(60) background(0)
def setup(): p.size(400, 400) p.strokeWeight(10) p.stroke(255, 200)
def setup(): size(640, 360) stroke(255) frame_rate(30)
def render(self): p.stroke(0) p.point(self.x, self.y)
def __init__(self, draw): stroke(153) self.draw = draw
def setup(): p.size(SIZE, SIZE) p.noFill() p.stroke(255)