def run_episode(show=True): ''' play the game and remember what happened ''' game = VisibleGame(10, 10, run=False) # playing vars state = state_to_tensor(game.return_state()) gameOver = False def draw(): nonlocal show, game, gameOver, q, state, actor, critic if show: game.draw() # play an episode if gameOver: print(game.status()) p5.exit() if mode in [REINFORCE, ACTOR_CRITIC]: _, action_index = actor.choose_action(state) else: action_index = critic.choose_action(state) # observe next state and collect reward _, nextState, gameOver = game.move_player(action_index) # print(reward) nextState = state_to_tensor(nextState) # update state state = nextState p5.run(game.setup, draw, 144)
def __init__(self, *args, run=True, **kwargs): super().__init__(*args, **kwargs) self.window_width = 250 self.window_height = 250 self.rect_width = self.window_width / self.width self.rect_height = self.window_height / self.height if run: p5.frame_rate = 1 p5.run(self.setup, self.draw, 5, frame_rate=1)
def start(fpp='',offset=0.0,stop=False): global fp, ofset, dur,length,final,sek final=length ofset=sek fp=fpp # print(sek) # fp = "test.mp3" # change to the correct path to your file accordingly # The statement in setup() function # ececute once when the program begins if __name__ == '__main__': p.run()
def main(): run() pass
for i in range(path_verts.shape[0] - 1): row = path_verts.iloc[i] row_next = path_verts.iloc[i + 1] x = round(float(x_interp(row.vertex_x)), 2) y = round(float(y_interp(row.vertex_y)), 2) x_next = round(float(x_interp(row_next.vertex_x)), 2) y_next = round(float(y_interp(row_next.vertex_y)), 2) p5.line((x, y), (x_next, y_next)) def draw_midi(t): for i in notes: for j in beats: fill = pg.loc[(j, i), str(t)] if fill == '0': p5.fill(0) p5.stroke(0) else: r, g, b = [int(c) for c in eval(fill)] p5.fill(r, g, b) p5.stroke(r, g, b) p5.rect(((i * w_scale) + res, j * h_scale), w_scale, h_scale) p5.run() db.close()
import p5 as p def setup(): p.size(600, 600) p.rect_mode('CENTER') p.color_mode('HSB') def draw(): p.background(0) p.translate(20, 20) for x in range(30): for y in range(30): d = p.dist((30*x, 30*y), (mouse_x, mouse_y)) p.fill(0.5*d, 255, 255) p.rect((30*x, 30*y), 25, 25) if __name__ == '__main__': p.run()
def main(): run()
if left: print("left",frame_count) if right: print("right",frame_count) def key_pressed(): global up,down,right,left,newKey,lastKey up=False down=False left=False right=False newKey=key if newKey=="UP": up=True if newKey=="DOWN": down=True if newKey=="LEFT": left=True if newKey=="RIGHT": right=True p5.run(frame_rate=60)
def run_p5(self, *args, **kwargs): """Initializes p5 sketch""" run(*args, **kwargs)
boid_list = [ Boid( id=i, position=[20 + random.random() * WIDTH, 20 + random.random() * HEIGHT], velocity=[random.choice([-3, 3]), random.choice([-3, 3])]) for i in range(BOID_COUNT) ] ''' Boids Simulation Display ''' def setup(): size(WIDTH, HEIGHT) def draw(): background(30, 30, 47) for boid in boid_list: nearby_boids = boid.find_nearby_boids() boid.show(nearby_boids) boid.allignment(nearby_boids) boid.cohesion(nearby_boids) boid.seperation(nearby_boids) boid.move() #run simulation run(frame_rate=60)
from p5 import setup, draw, size, background, run import numpy as np from boid import Boid width = 1000 height = 1000 flock = [Boid(*np.random.rand(2) * 1000, width, height) for _ in range(50)] def setup(): #this happens just once size(width, height) #instead of create_canvas def draw(): global flock background(30, 30, 47) for boid in flock: boid.edges() boid.apply_behaviour(flock) boid.update() boid.show() #run(frame_rate=100) run(frame_rate=200) #run()
import p5 global counter counter=0 def setup(): p5.size(600,600) def draw(): global counter counter+=0.01 p5.background(0) p5.fill(0,255,0) p5.stroke(0) #p5.rotate_x(counter) p5.rotate_y(counter) #p5.sphere(300) p5.box(300,300,300) #print(counter) p5.run(mode="P3D",frame_rate=240)
def draw(): global planet, moon p5.fill(255) if not moon.finished: p5.background(0) p5.scale(1, -1) p5.translate(0, -height) moon.collide(planet) moon.update(planet, G) #planet.update(moon,G) p5.no_fill() p5.stroke(255, 60) #p5.circle((planet.pos.x,planet.pos.y),2*abs(moon.relpos(planet))) p5.fill(10, 173, 73) p5.stroke(0) planet.show() p5.fill(0, 0, 255) p5.stroke(0, 0, 255) moon.show() p5.run(frame_rate=120)
import p5 import threading import time first = True def wait(): print("started waiting") time.sleep(5) print("still waiting") time.sleep(5) def setup(): p5.size(600, 600) def draw(): global first if first: first = False t = threading.Thread(target=wait) t.start() print(frame_count) p5.run(frame_rate=10)
Maps[0].gridpos = p5.Vector(2, 2) if key == "#": if not showGrid: showGrid = True else: showGrid = False if key == "]": if not Maps[0].walkThroughWalls: Maps[0].walkThroughWalls = True print("Walk through walls on") else: Maps[0].walkThroughWalls = False print("Walk through walls off") p5.run(frame_rate=50)mport vlc #from audioManager import * screenScale = 5 scl = 16*screenScale showGrid = False player = Player(1, 2, screenScale) def on_release(Key): global lastKey, player if str(Key) == "Key.up" or str(Key) == "Key.down" or str(Key) == "Key.right" or str(Key) == "Key.left": if str(Key) == lastKey:
LeftPlanet=Planet(0,height/2,1,[10,0],25,trail=1) LeftPlanet.pos.x+=LeftPlanet.r RightPlanet=Planet(width,height/2,1,[-10,0],25,trail=1) RightPlanet.pos.x-=RightPlanet.r def draw(): global LeftPlanet,RightPlanet p5.scale(1,-1) p5.translate(0,-height) if not LeftPlanet.finished and not RightPlanet.finished: LeftPlanet.collide(RightPlanet) p5.stroke(255,0,0) LeftPlanet.update(RightPlanet,G) p5.stroke(0,0,255) RightPlanet.update(LeftPlanet,G) p5.background(0) p5.stroke(255,0,0) p5.fill(255,0,0) LeftPlanet.show() p5.stroke(0,0,255) p5.fill(0,0,255) RightPlanet.show() p5.run(frame_rate=240)
def main(): run(frame_rate=10)
filenames = ['arcs', 'custom_shapes', 'triangle_strip', 'custom_shapes2', 'curves', 'primitives'] max_frames = 100 e = SystemExit() for name in filenames: p5 = importlib.import_module('p5') module = importlib.import_module(name) curr_frames = 0 def draw(): global curr_frames curr_frames += 1 if curr_frames > max_frames: p5.exit() module.draw() pr = cProfile.Profile() pr.enable() start_time = time.process_time() try: p5.run(sketch_draw=draw, sketch_setup=module.setup) except BaseException as curr_e: elapsed_time = time.process_time() - start_time print("{0} took {1} seconds to render {2} frames".format(name, elapsed_time, max_frames)) e = curr_e pr.disable() pr.dump_stats(name + ".prof") raise e
from p5 import setup, draw, size, background, run import numpy as np from boid import Boid width = 1000 heigth = 1000 flock = [Boid(*np.random.rand(2) * 1000, width, heigth) for _ in range(20)] def setup(): #once call at RUN #set-up: canvas size size(width, heigth) def draw(): #everytime call event background(30, 30, 47) for boid in flock: boid.show() boid.behavir_commit(flock) boid.update() boid.edges() #p5 calling: setup(),d draw() ... run()
from random import randint global cols, rows, scl, w, h, counter counter = 0 scl = 20 w = 600 h = 600 cols = int(w / scl) rows = int(h / scl) def setup(): p5.size(600, 600) def draw(): p5.background(0) p5.stroke(255) p5.no_fill() p5.translate(width / 2, height / 2) p5.rotate_x(3.41459 / 3) p5.translate(-w / 2, -h / 2) for y in range(rows): p5.begin_shape("TRIANGLE_STRIP") for x in range(cols): p5.vertex(x * scl, y * scl, randint(-100, 100)) p5.vertex(x * scl, (y + 1) * scl, randint(-100, 100)) p5.end_shape() p5.run(mode="P3D")