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 draw(): line(50, 100, 150, 100) circle(200, 100, 50) ellipse(300, 100, 50, 25) square(400, 100, 50) rect(500, 100, 50, 25) triangle(50, 200, 300, 250, 100, 300) quad(400, 200, 500, 250, 350, 300, 375, 100) arc(200, 400, 80, 80, 0, PI + QUARTER_PI, 'PIE')
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(): 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(): 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 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 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()
# coding=utf-8 """ Shapes. """ import pyprocessing as p p.size(400, 500) # screen width and height # body p.triangle(100, 410, 200, 200, 300, 410) # 3 points (x,y) # hands p.ellipse(100, 300, 40, 40) # centre point (x,y) p.ellipse(300, 300, 40, 40) # and size (width,height) # face p.ellipse(200, 180, 190, 200) # mouth p.line(183, 246, 245, 230) # 2 points (x,y) # frames p.line(107, 163, 295, 163) # lenses p.rect(132, 150, 50, 40) # top left corner (x,y) p.rect(215, 150, 50, 40) # and size (width,height) p.run()
def display(self): p.noStroke() p.fill(50) p.rect(self.x, self.y, self.w, self.h)
def empty(self): pyp.fill(self.emptycolor) pyp.rect(self.xposition, self.yposition,self.size,self.size);
def fill(self): pyp.fill(self.fillcolor); pyp.rect(self.xposition, self.yposition,self.size,self.size);