def main(): """ This is the main program. """ # Open the window arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Start the render process. This must be done before any drawing commands. arcadeplus.start_render() # Call our drawing functions. draw_background() draw_pine_tree(50, 250) draw_pine_tree(350, 320) draw_bird(70, 500) draw_bird(470, 550) # Finish the render. # Nothing will be drawn without this. # Must happen after all draw commands arcadeplus.finish_render() # Keep the window up until someone closes it. arcadeplus.run()
def setup(): global toolbar, frames arcadeplus.open_window(WIDTH, HEIGHT, "AnimationCreator") arcadeplus.set_background_color(arcadeplus.color.WHITE) scheduling_update_time = 0.01666666666 # float value is same as 1/60 arcadeplus.schedule(on_update, scheduling_update_time) # Create Vertex Buffer Object (VBO) shape lists frames.append(arcadeplus.ShapeElementList()) toolbar = arcadeplus.ShapeElementList() # Override arcade window methods window = arcadeplus.get_window() window.on_draw = on_draw window.on_key_press = on_key_press window.on_key_release = on_key_release window.on_mouse_press = on_mouse_press window.on_mouse_release = on_mouse_release window.on_mouse_drag = on_mouse_drag # Render toolbar render_toolbar_dividers() render_toolbar_shapes() render_toolbar_colors() render_toolbar_icons() render_toolbar_text() arcadeplus.run()
def main(): # Open up our window arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcadeplus.set_background_color(arcadeplus.color.WHITE) # Tell the computer to call the draw command at the specified interval. arcadeplus.schedule(on_draw, 1 / 80) # Run the program arcadeplus.run()
def setup(): arcade.open_window(WIDTH, HEIGHT, "TOHACKS SARS COV-2 Model") arcade.set_background_color(arcade.color.LIGHT_STEEL_BLUE) arcade.schedule(update, 1 / 60) window = arcade.get_window() window.on_draw = on_draw window.on_mouse_press = on_mouse_press window.on_mouse_release = on_mouse_release window.on_mouse_motion = on_mouse_motion arcade.run()
def setup(): arcade.open_window(WIDTH, HEIGHT, "TOHACKS SARS COV-2 Model") arcade.set_background_color(arcade.color.WHITE) arcade.schedule(update, 1 / 60) # Override arcade window methods window = arcade.get_window() window.on_draw = on_draw window.on_key_press = on_key_press window.on_key_release = on_key_release window.on_mouse_press = on_mouse_press window.on_mouse_release = on_mouse_release window.on_mouse_motion = on_mouse_motion arcade.run()
def main(): arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, TITLE) arcadeplus.set_background_color(BACKGROUND_COLOR) arcadeplus.start_render() arcadeplus.draw_circle_filled(400, 250, 100, arcadeplus.color.BLACK) # load image image = arcadeplus.load_texture(resource_path('character.png')) arcadeplus.draw_texture_rectangle(200, 250, image.width, image.height, image) # load sound sound = arcadeplus.sound.load_sound(resource_path('cat-meow.wav')) arcadeplus.sound.play_sound(sound) arcadeplus.finish_render() arcadeplus.run() return
def test_window(): import arcadeplus width = 800 height = 600 title = "My Title" resizable = True arcadeplus.open_window(width, height, title, resizable) arcadeplus.set_background_color(arcadeplus.color.AMAZON) w = arcadeplus.get_window() assert w is not None # Make sure the arguments get passed to the window assert w.width == width assert w.height == height assert w.caption == title assert w.resizeable is resizable arcadeplus.set_window(w) p = arcadeplus.get_projection() assert p is not None v = arcadeplus.get_viewport() assert v[0] == 0 # The lines below fail. Why? # assert v[1] == width - 1 assert v[2] == 0 # assert v[3] == height - 1 arcadeplus.start_render() arcadeplus.finish_render() def f(): pass arcadeplus.schedule(f, 1 / 60) arcadeplus.pause(0.01) arcadeplus.close_window() arcadeplus.open_window(width, height, title, resizable) arcadeplus.quick_run(0.01)
def main(): """ This is the main program. """ # Open the window arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Start the render process. This must be done before any drawing commands. arcadeplus.start_render() # Call our drawing functions. draw_background() # Loop to draw ten birds in random locations. for bird_count in range(10): # Any random x from 0 to the width of the screen x = random.randrange(0, SCREEN_WIDTH) # Any random y from in the top 2/3 of the screen. # No birds on the ground. y = random.randrange(SCREEN_HEIGHT / 3, SCREEN_HEIGHT - 20) # Draw the bird. draw_bird(x, y) # Draw the top row of trees for x in range(45, SCREEN_WIDTH, 90): draw_pine_tree(x, SCREEN_HEIGHT / 3) # Draw the bottom row of trees for x in range(65, SCREEN_WIDTH, 90): draw_pine_tree(x, (SCREEN_HEIGHT / 3) - 120) # Finish the render. # Nothing will be drawn without this. # Must happen after all draw commands arcadeplus.finish_render() # Keep the window up until someone closes it. arcadeplus.run()
def test_create_isometric_grid_lines(): width = 10 height = 10 tile_width = 64 tile_height = 64 window = arcadeplus.open_window(800, 600, "Test") lines = arcadeplus.create_isometric_grid_lines(width, height, tile_width, tile_height, arcadeplus.color.BLACK, 2) assert lines arcadeplus.close_window()
A video explaining this example can be found here: https://vimeo.com/167158158 If Python and arcadeplus are installed, this example can be run from the command line with: python -m arcadeplus.examples.drawing_primitives """ # Import the arcadeplus library. If this fails, then try following the instructions # for how to install arcadeplus: # http://arcadeplus.academy/installation.html import arcadeplus import os # Open the window. Set the window title and dimensions (width and height) arcadeplus.open_window(600, 600, "Drawing Primitives Example") # Set the background color to white # For a list of named colors see # http://arcadeplus.academy/arcadeplus.color.html # Colors can also be specified in (red, green, blue) format and # (red, green, blue, alpha) format. arcadeplus.set_background_color(arcadeplus.color.WHITE) # Start the render process. This must be done before any drawing commands. arcadeplus.start_render() # Draw a grid # Draw vertical lines every 120 pixels for x in range(0, 601, 120): arcadeplus.draw_line(x, 0, x, 600, arcadeplus.color.BLACK, 2)
Showing how to do nested loops. If Python and arcadeplus are installed, this example can be run from the command line with: python -m arcadeplus.examples.nested_loops_bottom_right_triangle """ # Library imports import arcadeplus COLUMN_SPACING = 20 ROW_SPACING = 20 LEFT_MARGIN = 110 BOTTOM_MARGIN = 110 # Open the window and set the background arcadeplus.open_window(400, 400, "Complex Loops - Bottom Right Triangle") arcadeplus.set_background_color(arcadeplus.color.WHITE) # Start the render process. This must be done before any drawing commands. arcadeplus.start_render() # Loop for each row for row in range(10): # Loop for each column # Change the number of columns depending on the row we are in for column in range(row, 10): # Calculate our location x = column * COLUMN_SPACING + LEFT_MARGIN y = row * ROW_SPACING + BOTTOM_MARGIN
Showing how to do nested loops. If Python and arcadeplus are installed, this example can be run from the command line with: python -m arcadeplus.examples.nested_loops_top_left_triangle """ # Library imports import arcadeplus COLUMN_SPACING = 20 ROW_SPACING = 20 LEFT_MARGIN = 110 BOTTOM_MARGIN = 110 # Open the window and set the background arcadeplus.open_window(400, 400, "Complex Loops - Top Left Triangle") arcadeplus.set_background_color(arcadeplus.color.WHITE) # Start the render process. This must be done before any drawing commands. arcadeplus.start_render() # Loop for each row for row in range(10): # Loop for each column # Change the number of columns depending on the row we are in for column in range(row): # Calculate our location x = column * COLUMN_SPACING + LEFT_MARGIN y = row * ROW_SPACING + BOTTOM_MARGIN
""" Example "arcadeplus" library code. If Python and arcadeplus are installed, this example can be run from the command line with: python -m arcadeplus.examples.decorator_drawing_example """ # Library imports import arcadeplus import random SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "Drawing With Decorators Example" window = arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) bird_list = [] def setup(): create_birds() arcadeplus.schedule(update, 1 / 60) arcadeplus.run() def create_birds(): for bird_count in range(10): x = random.randrange(SCREEN_WIDTH) y = random.randrange(SCREEN_HEIGHT/2, SCREEN_HEIGHT) bird_list.append([x, y])
# Area = pi * r**2 # Draw circle with radius 1, and randomly plot points inside 1 quadrant # Highlight all dots with distance < 1 from (0,0) import arcadeplus as arcade import random import math WIDTH = 800 HEIGHT = 800 circle_points = [] outside_points = [[WIDTH, HEIGHT]] window = arcade.open_window(WIDTH, HEIGHT, "Monte Carlo Pi Approximation") def setup(): arcade.set_background_color(arcade.color.WHITE) arcade.schedule(update, 1 / 60) arcade.run() @window.event def update(delta_time): global pi for i in range(200): points = [random.randrange(0, WIDTH), random.randrange(0, HEIGHT)] if math.sqrt(points[0]**2 + points[1]**2) <= WIDTH: circle_points.append(points) else: outside_points.append(points) pi = 4 * (len(circle_points) / (len(outside_points) + len(circle_points)))
Showing how to do nested loops. If Python and arcadeplus are installed, this example can be run from the command line with: python -m arcadeplus.examples.nested_loops_box """ # Library imports import arcadeplus COLUMN_SPACING = 20 ROW_SPACING = 20 LEFT_MARGIN = 110 BOTTOM_MARGIN = 110 # Open the window and set the background arcadeplus.open_window(400, 400, "Complex Loops - Box") arcadeplus.set_background_color(arcadeplus.color.WHITE) # Start the render process. This must be done before any drawing commands. arcadeplus.start_render() # Loop for each row for row in range(10): # Loop for each column for column in range(10): # Calculate our location x = column * COLUMN_SPACING + LEFT_MARGIN y = row * ROW_SPACING + BOTTOM_MARGIN # Draw the item
""" Sound Demo If Python and arcadeplus are installed, this example can be run from the command line with: python -m arcadeplus.examples.sound """ import arcadeplus import os # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcadeplus.open_window(300, 300, "Sound Demo") laser_sound = arcadeplus.load_sound(":resources:sounds/laser1.wav") arcadeplus.play_sound(laser_sound) arcadeplus.run()