def circle(x, radius, level): p.fill(126 * level / 4) p.ellipse(x, 200, radius * 2, radius * 2) if level > 1: circle(x - 0.5 * radius, 0.5 * radius, level - 1) circle(x + 0.5 * radius, 0.5 * radius, level - 1)
def draw(): p.background(50) # grey scale p.fill(255, 150) # grey scale + alpha size = p.mouse.y / 2 p.rect(p.mouse.x, 200, size + 10, size + 10) p.rect(400 - p.mouse.x, 200, 210 - size, 210 - size)
def setup(): size(100, 100) background(255) fill(0) stroke(0) stroke_weight(10) frame_rate(60)
def draw(self): pyp.pushMatrix() pyp.noStroke() pyp.fill(self.fill_color) pyp.translate(*self.position) self.draw_poly() pyp.popMatrix()
def draw(): sd = 60 # standard deviation mean = width/2 # mean xloc = gauss(mean, sd) # gets gaussian random number p.noStroke() p.fill(0,10) p.ellipse(xloc, height/2, 16,16) # draw ellipse at our random location
def draw(self): p.fill(*self.colour) for i in range(self.n): angle = i * 2 * math.pi / self.n + self.angle new_x = self.x + math.cos(angle) * self.radius new_y = self.y + math.sin(angle) * self.radius p.ellipse(new_x, new_y, self.size, self.size) self.angle += self.speed
def simple_multi_modal(): source, text = animation_q.get_nowait() # non-blocking check for items in animation_q. # If queue is empty a Queue.Empty exception is raised. if source == 'gesture': p.fill(0, 102, randint(50,150)) p.textSize(48) elif source == 'speech': p.fill(102, randint(50,150), 0) p.textSize(32) else: pass p.text(text, randint(50,550), randint(50,550))
def labelDisplay(emotionCount): textSize(12) fill(120, 225, 255) text("Sadness: {0}".format(emotionCount[0]), 5, 15) fill(255, 167, 0) text("Joy: {0}".format(emotionCount[1]), 5, 30) fill(0, 0, 0) text("Fear: {0}".format(emotionCount[2]), 5, 45) fill(141, 85, 36) text("Disgust: {0}".format(emotionCount[3]), 5, 60) fill(214, 45, 32) text("Anger: {0}".format(emotionCount[4]), 5, 75)
def draw(): z.step() angle = (2*np.pi-z.state[0]-np.pi/2) pyp.background(200,50) pyp.line(xcenter,ycenter,xcenter+ pendulum_length*np.cos(angle),ycenter+ pendulum_length*np.sin(angle)); pyp.fill(255) pyp.ellipse(xcenter+ pendulum_length*np.cos(angle),ycenter+ pendulum_length*np.sin(angle),100,100) action_taken = z.action_taken for i in range(len(indicators)): #print action_taken if i == action_taken: indicators[i].fill() else: indicators[i].empty()
def simple_multi_modal(): source, recognized_input = animation_q.get_nowait() # non-blocking check for items in animation_q. # If queue is empty a Queue.Empty exception is raised. # data read from queue is a tuple of strings: (source, recognized_input) if source == 'gesture': p.fill(0, 102, randint(50, 150)) p.textSize(48) elif source == 'speech': p.fill(102, randint(50, 150), 0) p.textSize(32) else: pass p.text(recognized_input, randint(50, 550), randint(50, 550))
def draw(self, millis): background(51) items = self.ring.get() (x,self.y) = (0, self.y_step * len(items)) self.update(millis) for item in items: try: if item is not None: fill(item.color) text(item.text, x, self.y) else: text("Something bad happened", x, self.y) except UnicodeDecodeError: text("Unsupported Language Tweeted", x, self.y) self.y-= self.y_step
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(): 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) # 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 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.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 rings(): p.background(292, 40, 30) for i in range(30): x = random.randint(0, 600) y = random.randint(0, 200) n = random.randint(3, 30) radius = random.randint(10, 100) size = random.randint(3, 15) colour = random.choice(COLOURS) p.fill(*colour) for i in range(n): angle = i * 2*math.pi / n new_x = x + math.cos(angle) * radius new_y = y + math.sin(angle) * radius p.ellipse(new_x, new_y, size, size)
def draw(): p.background(255) liquid.display() for mover in movers: if liquid.contains(mover): dragForce = liquid.drag(mover) mover.applyForce(dragForce) gravity = p.PVector(0, 0.1 * mover.mass) mover.applyForce(gravity) mover.update() mover.checkEdges() mover.display() p.fill(0) p.text("click mouse to reset", 10, 30)
def dimming(): global lights_activated source, text = animation_q.get_nowait() # non-blocking check for items in animation_q. # If queue is empty a Queue.Empty exception is raised. if source == 'dim' and lights_activated: d = int(float(text)) if d < 200: r = d g = d else: r = 255 g = 255 b = d - 20 p.background(200) p.fill(r,g,b) p.rect(0,0,600,600) elif text == 'LIGHTS': lights_activated = True else: pass
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 lighting(): source, text = animation_q.get_nowait() # non-blocking check for items in animation_q. # If queue is empty a Queue.Empty exception is raised. d = text.split(' ') (a, r, g, b) = list(map(int, d)) # max values: 37889 if source == 'lighting': p.fill(a,a,a) p.rect(200,100,200,100) p.fill(r,0,0,a) p.rect(100,300,100,100) p.fill(0,g,0,a) p.rect(250,300,100,100) p.fill(0,0,b,a) p.rect(400,300,100,100) else: pass
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 setup(): size(640, 360) stroke(0) fill(255) frame_rate(60) background(127)
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 setup(): p.size(400, 400) p.colorMode(p.HSB, 360, 100, 100) p.fill(30, 100, 100) p.noStroke() p.noLoop()
def empty(self): pyp.fill(self.emptycolor) pyp.rect(self.xposition, self.yposition,self.size,self.size);
#!/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 display(self): p.noStroke() p.fill(50) p.rect(self.x, self.y, self.w, self.h)
def display(self): p.stroke(0) p.strokeWeight(2) p.fill(127) p.ellipse(self.location.x, self.location.y, 48, 48)
def fill(self): pyp.fill(self.fillcolor); pyp.rect(self.xposition, self.yposition,self.size,self.size);
""" Rings. """ import math import random import pyprocessing as p COLOURS = [(45,25,100), (345,50,65), (10,60,90), (30,50,100)] p.size (600, 200) p.colorMode(p.HSB, 360, 100, 100) p.noStroke() p.background(292, 40, 30) x = random.randint(200, 400) y = random.randint(5, 150) n = random.randint(3, 30) radius = random.randint(10, 100) size = random.randint(3, 15) colour = random.choice(COLOURS) p.fill(*colour) for i in range(n): angle = i * 2*math.pi / n new_x = x + math.cos(angle) * radius new_y = y + math.sin(angle) * radius p.ellipse(new_x, new_y, size, size) p.run()