Beispiel #1
0
def draw():
	p.background(0)
	for e in elements:
		p.ellipse(e.x, e.y, e.size, e.size)
		p.line(e.x, e.y, e.x + e.velocity[0] * e.size / 2,
			e.y + e.velocity[1] * e.size / 2)

	# 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:
		# draw lines between elements
		for line in lines:
			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()
Beispiel #2
0
def draw():
    global y
    background(0)
    y = y - 1
    if y < 0:
        y = height
    line(0, y, width, y)
Beispiel #3
0
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 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')
Beispiel #5
0
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()
Beispiel #6
0
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])
Beispiel #8
0
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)
Beispiel #9
0
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 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()
Beispiel #11
0
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()
Beispiel #12
0
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)
	
	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])
Beispiel #14
0
def jitter_line(pa, pb, segment_length, jitter, death_rate=0, fork_rate=0):
    from pyprocessing import line

    if death_rate and random.random() < death_rate:
        return

    if distance(pa, pb) < segment_length:
        line(pa, pb)
    else:
        px = get_point(pa, pb, segment_length)
        jpx = jitter_point(px, jitter)
        line(pa, jpx)

        if fork_rate and random.random() < fork_rate:
            jitter_line(jpx, pb, segment_length, jitter)
            jitter_line(jpx, pb, segment_length, jitter)
        else:
            jitter_line(jpx, pb, segment_length, jitter)            
Beispiel #15
0
def draw():
    p.background(0)
    for e in elements:
        p.ellipse(e.x, e.y, e.size, e.size)
        p.line(e.x, e.y, e.x + e.velocity[0] * e.size / 2, e.y + e.velocity[1] * e.size / 2)

        # find all elements touching another element
    touching = {}
    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):
            touching[a] = True
            touching[b] = True

            # rotate and move all elements
    for e in elements:
        if e in touching:
            e.rotate()
        e.move()
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])
Beispiel #17
0
def draw():
    stroke_cap(1)
    line(10, 10, 50, 10)
    point(70, 10)

    stroke_cap(2)
    line(10, 30, 50, 30)
    point(70, 30)

    stroke_cap(4)
    line(10, 50, 50, 50)
    point(70, 50)
Beispiel #18
0
 def make_y(y):
     line(0, y*U, Y, y*U)
Beispiel #19
0
 def make_l(x):
     line(x*U, 0, X, x*U)
Beispiel #20
0
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()
Beispiel #21
0
def draw():
    global y
    y = y - 1
    if y < 0:
        y = height
    line(0, y, width, y)
Beispiel #22
0
# 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()
Beispiel #23
0
    def draw_poly(self):
        pyp.sphere(self.size)

        pyp.line(self.position, PVector(0, 0, 0))
Beispiel #24
0
 def make_x(x):
     line(x*U, 0, x*U, X)
Beispiel #25
0
def mouseDragged():
	# draw a line between previous and current mouse position
	p.line(p.pmouse.x, p.pmouse.y, p.mouse.x, p.mouse.y)