예제 #1
0
파일: process4-6.py 프로젝트: MoMaT/slides
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()
예제 #2
0
파일: recursion.py 프로젝트: MoMaT/slides
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)
예제 #3
0
파일: wave-1.py 프로젝트: MoMaT/slides
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)
예제 #4
0
파일: dark_light.py 프로젝트: MoMaT/slides
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
예제 #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()
예제 #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')
예제 #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)
예제 #13
0
파일: rings-2.py 프로젝트: MoMaT/slides
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)
예제 #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)
예제 #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)	
예제 #18
0
파일: shapes.py 프로젝트: MoMaT/slides
#!/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()
예제 #19
0
파일: rings-1.py 프로젝트: MoMaT/slides
"""
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()
예제 #20
0
파일: process4-1.py 프로젝트: MoMaT/slides
def draw():
	p.background(0)
	for e in elements:
		p.ellipse(e.x, e.y, e.radius, e.radius)
예제 #21
0
파일: process4-3.py 프로젝트: MoMaT/slides
def draw():
	p.background(0)
	for e in elements:
		p.ellipse(e.x, e.y, e.size, e.size)
		e.move()