Beispiel #1
0
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)
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():
	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 #4
0
def setup():
    size(100, 100)
    background(255)
    fill(0)
    stroke(0)
    stroke_weight(10)
    frame_rate(60)
Beispiel #5
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)
def setup():
	p.size(800,200)
	p.smooth()
	p.background(255)

	global location, velocity
	location = p.PVector(100,100)
	velocity = p.PVector(2.5,5)
Beispiel #7
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)
Beispiel #8
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()
Beispiel #9
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)
	
	wind = p.PVector(0.01,0)
	gravity = p.PVector(0,0.1)
	m.applyForce(wind)
	m.applyForce(gravity)

	m.update()
	m.checkEdges()
	m.display()
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 #12
0
def draw():
    background(200)
    bindings = {
        'H': clear,
        'G': show_grid,
        'L': pretty_lines
    }
    if key.pressed and key.char in bindings.keys():
        bindings[key.char]()

    map(lambda obj: obj.draw(), actors)
def draw():
	p.background(255)

	force = a.attract(m)
	m.applyForce(force)
	m.update()
	
	a.drag()
	a.hover(p.mouse.x, p.mouse.y)
	
	a.display()
	m.display()
Beispiel #14
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 #15
0
def draw():
    """ Required for pyprocessing.run() """
    global screen_size
    global camera_pos
    global spawner
    global frame_count
    global swarm
    global back_col
    global img_dir

    pyp.camera(camera_pos.x, camera_pos.y, camera_pos.z, 0, 0, 0, 1, 0, 0)

    s = max(screen_size)

    pyp.pointLight(255, 255, 255, 10 * s, 0, 0)
    pyp.pointLight(255, 255, 255, 0, 10 * s, 0)
    pyp.pointLight(255, 255, 255, 0, 0, 10 * s)

    pyp.background(back_col)

    #calculate spawner angle
    animation_angle = 2.0 * pi * (frame_count % frame_cycles) / frame_cycles
    spawner.angle = 65 * animation_angle
    # print 'spawner', pformat({
    #     'angle':spawner.angle,
    #     'position':spawner.spawn_position
    # })

    seed(animation_angle)

    swarm.spawn(orientation=PVector(s / 50, 0, 0),
                position=spawner.spawn_position,
                velocity=PVector((sin(animation_angle)) * s / 100,
                                 (cos(animation_angle)) * s / 100,
                                 (1 - random() * 2) * s / 100),
                active=True)

    for particle in swarm:
        # print 'particle', pformat({
        #     'position': particle.position,
        #     'velocity': particle.velocity,
        #     'orientation': particle.orientation
        # })
        particle.draw()
        particle.step()

    frame_count += 1

    if frame_count in range(360, 720):
        img = pyp.get()
        # print type(img)
        pyp.save(os.path.join(img_dir, 'image_%s.jpg' % (frame_count)))
Beispiel #16
0
def draw():
    pp.background(0x000000)
    pp.translate(width/2.0, height/2.0, -height/4.0 + 500) # +500 is a kludge to make big
    defineLights()
    update()
    pp.lights()
    try:
        data = queue.get_nowait()
        if data:
            set_values(data)
    except:
        pass
    drawLEDs(network)
def draw():
	p.background(255)
	
	wind = p.PVector(0.01,0)
	gravity = p.PVector(0,0.1)

	for mover in movers:
		mover.applyForce(wind)
		mover.applyForce(gravity)

		mover.update()
		mover.checkEdges()
		mover.display()
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 #19
0
 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)
	
	# rather than a double-nested loop, taking advantage of itertools' combination
	# method to give all possible pairs with no repeats
	for (m1,m2) in combinations(movers,2):
		force = m1.attract(m2)
		m2.applyForce(force)
		# flip the force and apply it back (avoids duplicate calculations)
		force.mult(-1.)
		m1.applyForce(force)
		
	for m in movers:
		m.update()
		m.display()
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)
	
	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])
Beispiel #24
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)
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)
Beispiel #26
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()
Beispiel #27
0
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 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 #29
0
def draw():
    global m, learn, z
    pyp.background(200,50)

    learn.collect_data()
    m = learn.get_mean()


    pyp.loadPixels()
    m = np.atleast_2d(m)
    norm = normalize(vmin=min(min(m)), vmax=max(max(m)))
    cmap = get_cmap('jet')
    m_normed = norm(m)
    rgba_data=cmap(m_normed)*255
    r = rgba_data[0,:,0].astype('uint32')
    g = rgba_data[0,:,1].astype('uint32')
    b = rgba_data[0,:,2].astype('uint32')
    a = rgba_data[0,:,3].astype('uint32')
    pyp.screen.pixels = a << 24 | r << 16 | g << 8 | b
    pyp.updatePixels()
def draw():
	p.background(255)
	c = 0.05
	
	for mover in movers:
		
		wind = p.PVector(0.01,0)
		gravity =  p.PVector(0,0.1*mover.mass)
		friction = mover.velocity.get()
		friction.mult(-1)
		if friction.mag() > 0:
			friction.normalize()
			friction.mult(c)
		
		mover.applyForce(wind)
		mover.applyForce(gravity)
		mover.applyForce(friction)

		mover.update()
		mover.checkEdges()
		mover.display()
def draw():
    p.background(255)
    mover.update()
    mover.checkEdges()
    mover.display()
Beispiel #32
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 setup():		
	p.size(800,200)
	p.background(255)
	p.smooth()
Beispiel #34
0
def clear():
    background(200)
Beispiel #35
0
def setup():
    size(640, 360)
    stroke(255)
    frame_rate(60)
    background(0)
Beispiel #36
0
def draw():
    p.background(292, 40, 30)
    for ring in rings:
        ring.draw()
Beispiel #37
0
def setup():
	p.size(SIZE, SIZE)
	p.background(0)
	p.colorMode(p.HSB, 360, 100, 100)
Beispiel #38
0
#!/usr/bin/evn python
# coding=utf-8
"""
Composition. Square Limit.

"""
import math
import pyprocessing as p

p.size(800, 800)
p.background(255)
p.translate(300, 300)

img = p.loadImage("fish.png")

def fish():
	p.image(img, -80, -80)

def transform(t, *args):
	def wrapper(*args):
		def wrapped_f():
			p.pushMatrix()
			t(*args)  # perform transformation t
			args[-1]()  # call function f
			p.popMatrix()
		return wrapped_f
	return wrapper

@transform
def rotate(f):
	p.translate(0, 240)