Exemplo n.º 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()
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def draw():
	p.background(0)

	for i in range(20):
		angle = i * 0.2
		x = i * 20
		y = (math.sin(angle) + 1) * 200
		p.ellipse(x, y, 16, 16)
Exemplo n.º 4
0
def draw():
	p.background(0)

	for i in range(width / 20 + 1):
		for j in range(height / 20 + 1):
			size = p.dist(p.mouse.x, p.mouse.y, i * 20, j * 20)
			size = size / MAX_DISTANCE * 66
			p.ellipse(i * 20, j * 20, size, size)
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
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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')
Exemplo n.º 8
0
    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 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 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 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.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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
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 display(self):
     p.stroke(0)
     p.strokeWeight(2)
     p.fill(127)
     p.ellipse(self.location.x, self.location.y, 48, 48)
Exemplo n.º 16
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()
	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)	
Exemplo n.º 18
0
#!/usr/bin/evn python
# 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()
Exemplo n.º 19
0
"""
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()
Exemplo n.º 20
0
def draw():
	p.background(0)
	for e in elements:
		p.ellipse(e.x, e.y, e.radius, e.radius)
Exemplo n.º 21
0
def draw():
	p.background(0)
	for e in elements:
		p.ellipse(e.x, e.y, e.size, e.size)
		e.move()