Exemplo n.º 1
0
def external_run(q, n):
    """
    Call this instead of calling run() directly when running this module in its own process
    """
    global queue
    queue = q
    global network
    network = n
    pp.run()
Exemplo n.º 2
0
def keyPressed():
	if p5.key.char == ' ':
		buildLDA(vectors, labels)

def audioInput(in_data, frame_count, time_info, status):
	global recent
	recent = np.fromstring(in_data, 'Int32').astype(float)
	recent /= np.iinfo(np.int32).max
	if p5.key.pressed and p5.key.char >= '1' and p5.key.char <= '9':
		global vectors
		global labels
		vectors.append(recent)
		labels.append(int(p5.key.char) - int('1'))
	return (None, pyaudio.paContinue)

audio = pyaudio.PyAudio()
format = pyaudio.paInt32
stream = audio.open(format=format, # bytes per sample
					channels=1,
					rate=48000,
					input=True,
					output=False,
					frames_per_buffer=N,
					stream_callback=audioInput)
stream.start_stream()
p5.run()
stream.stop_stream()
stream.close()
audio.terminate()
Exemplo n.º 3
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)

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()

p.run()
Exemplo n.º 4
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()
Exemplo n.º 5
0
    #     '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)))


pyp.run()
Exemplo n.º 6
0

def setup():
    global width, height
    pyp.size(width, height)


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()
    #imshow(np.reshape(z,learn.xx.shape))
    #show()
pyp.run()
Exemplo n.º 7
0
    getattr(obj, method)(*args, **kwargs)


def setup():
    size(1000, 1000)
    show_grid()
    global actors
    actors = []

    urist = Dwarf()
    p_liner = Liner(pretty_lines)

    actors.append(urist)
    actors.append(p_liner)


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)


run()
    def empty(self):
        pyp.fill(self.emptycolor)
        pyp.rect(self.xposition, self.yposition,self.size,self.size);



res = []
z = Controller()
variance_history = np.zeros((100,5)) #has to be the same width as the
z.state = np.array([np.pi+.2,0])
velocity = None
angle = 0

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()

pyp.run()  #THIS DOES ALL THE ACTION