Skip to content

Commit

Permalink
Unbreak broken tutorials and pytest for tutorials (#1653)
Browse files Browse the repository at this point in the history
* Unbreak card-game tutorial

* Remove print statement filling up terminal

* Fix using wrong glsl file for step 3

* Initial fix to unbreak the pymunk platformer tutorial

* Fix docs failing to build

* Actually fix docs failing to build

Correct wrong line range

* Remove use of non existent method

Wrt step 11 pymunk platformer, it used the processs layer method.

* Add pytest for tutorials

Also fixed using absolute path in tutorials

* Fix `index.rst` for shader toy glow

* Remove use of non existent method

* Fix `index.rst` for gpu particle burst

* Remove inclusion of 0 in the range for sprite circle size

* Change to correct dir when running tutorials

* Cd into ../ before continuing the for loop

* Change dir when running test and not when finding

* Parameterize the test with another parameter

* Fix argvalue

* Update shadertoy_demo_1.py to remove usage of abs path

* Update shadertoy_demo_3.py to remove usage of pathlib

* Update shadertoy_demo_2.py to remove usage of pathlib

* Update shadertoy_demo.py to remove usage of pathlib

* Update index.rst to remove usage of pathlib

* Remove pathlib from gpu_particle_burst tutorial files

* Fix flake8 spacing & indentation errors on gpu_particle_burst tutorial

* Fix flake8 errors in gpu_particle_burst tutorial & ensure lines stay within doc build view

* Remove pathlib from raycasting tutorial

* Address pcraven's drawing order comment on #1653

* Clean up unused imports in raycasting tutorial

* Fix compute shader example by removing pathlib & using auto-closing file handles

* Remove pathlib from crt filter examples

* Fix flake8 / overly long lines in crt filter tutorials

* Rephrase top comment

* Update highlight lines & some phrasing for gpu particle burst tutorial

* Fix line numbers & some phrasing for raycasting tutorial

---------

Co-authored-by: pushfoo <36696816+pushfoo@users.noreply.github.com>
  • Loading branch information
Ibrahim2750mi and pushfoo committed Apr 4, 2023
1 parent 94d2e66 commit aa854d6
Show file tree
Hide file tree
Showing 40 changed files with 342 additions and 229 deletions.
12 changes: 5 additions & 7 deletions doc/tutorials/card_game/drag_drop_cards_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ def setup(self):
self.card_list.append(card)

# Shuffle the cards
for pos1 in range(len(self.card_list)):
pos2 = random.randrange(len(self.card_list))
self.card_list[pos1], self.card_list[pos2] = self.card_list[pos2], self.card_list[pos1]
self.card_list.shuffle()

# Create a list of lists, each holds a pile of cards.
self.piles = [[] for _ in range(PILE_COUNT)]
Expand Down Expand Up @@ -216,11 +214,11 @@ def pull_to_top(self, card):
""" Pull card to top of rendering order (last to render, looks on-top) """
# Find the index of the card
index = self.card_list.index(card)
# Loop and pull all the other cards down towards the zero end

# Repeatedly swap cards until the chosen card draws on top (last)
for i in range(index, len(self.card_list) - 1):
self.card_list[i] = self.card_list[i + 1]
# Put this card at the right-side/top/size of list
self.card_list[len(self.card_list) - 1] = card
# Exchange the drawing order of the cards at i and i + 1
self.card_list.swap(i, i+1)

def on_key_press(self, symbol: int, modifiers: int):
""" User presses key """
Expand Down
18 changes: 9 additions & 9 deletions doc/tutorials/compute_shader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def __init__(self):

# --- Create shaders

# Load in the shader source code
file = open("shaders/compute_shader.glsl")
compute_shader_source = file.read()
file = open("shaders/vertex_shader.glsl")
vertex_shader_source = file.read()
file = open("shaders/fragment_shader.glsl")
fragment_shader_source = file.read()
file = open("shaders/geometry_shader.glsl")
geometry_shader_source = file.read()
# Load in the shader source code safely & auto-close files
with open("shaders/compute_shader.glsl") as file:
compute_shader_source = file.read()
with open("shaders/vertex_shader.glsl") as file:
vertex_shader_source = file.read()
with open("shaders/fragment_shader.glsl") as file:
fragment_shader_source = file.read()
with open("shaders/geometry_shader.glsl") as file:
geometry_shader_source = file.read()

# Create our compute shader.
# Search/replace to set up our compute groups
Expand Down
12 changes: 6 additions & 6 deletions doc/tutorials/crt_filter/bloom_filter_example.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from pathlib import Path
import arcade
from arcade.experimental import BloomFilter
import random
from arcade.color import *
from arcade.color import RED, YELLOW, ORANGE, GREEN, BLUEBERRY, AMETHYST


# Do the math to figure out our screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "ShaderToy Demo"
RESOURCE_DIR = Path(__file__).parent


class MyGame(arcade.Window):
Expand All @@ -27,8 +25,9 @@ def __init__(self, width, height, title):
self.sprite_list = arcade.SpriteList()

for y in range(10, self.height, 50):
color = random.choice([RED, YELLOW, ORANGE, GREEN, BLUEBERRY, AMETHYST])
my_sprite = arcade.SpriteCircle(random.randrange(40), color)
color = random.choice(
[RED, YELLOW, ORANGE, GREEN, BLUEBERRY, AMETHYST])
my_sprite = arcade.SpriteCircle(random.randrange(1, 40), color)
self.sprite_list.append(my_sprite)
my_sprite.change_x = random.random() * 5
my_sprite.center_y = y
Expand All @@ -39,7 +38,8 @@ def on_draw(self):
self.bloom_filter.use()
self.bloom_filter.clear()
self.sprite_list.draw()
# arcade.draw_lrbt_rectangle_outline(0, self.width - 25, 0, self.height - 5, arcade.color.WHITE, 5)
# arcade.draw_lrbt_rectangle_outline(
# 0, self.width - 25, 0, self.height - 5, arcade.color.WHITE, 5)

# Switch back to our window and draw the CRT filter do
# draw its stuff to the screen
Expand Down
28 changes: 15 additions & 13 deletions doc/tutorials/crt_filter/crt_filter_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from pathlib import Path
import arcade
from arcade.experimental.crt_filter import CRTFilter
from pyglet.math import Vec2


# Do the math to figure out our screen dimensions
# Store our screen dimensions & title in a convenient place
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 1100
SCREEN_TITLE = "ShaderToy Demo"
RESOURCE_DIR = Path(__file__).parent


class MyGame(arcade.Window):
Expand All @@ -21,7 +19,7 @@ def __init__(self, width, height, title):
resolution_down_scale=6.0,
hard_scan=-8.0,
hard_pix=-3.0,
display_warp = Vec2(1.0 / 32.0, 1.0 / 24.0),
display_warp=Vec2(1.0 / 32.0, 1.0 / 24.0),
mask_dark=0.5,
mask_light=1.5)

Expand All @@ -30,33 +28,37 @@ def __init__(self, width, height, title):
# Create some stuff to draw on the screen
self.sprite_list = arcade.SpriteList()

full = arcade.Sprite(RESOURCE_DIR / "Pac-man.png")
full = arcade.Sprite("Pac-man.png")
full.center_x = width / 2
full.center_y = height / 2
full.scale = width / full.width
self.sprite_list.append(full)

my_sprite = arcade.Sprite(RESOURCE_DIR / "pac_man_sprite_sheet.png",
scale=5, image_x=4, image_y=65, image_width=13, image_height=15)
my_sprite = arcade.Sprite(
"pac_man_sprite_sheet.png",
scale=5, image_x=4, image_y=65, image_width=13, image_height=15)
my_sprite.change_x = 1
self.sprite_list.append(my_sprite)
my_sprite.center_x = 100
my_sprite.center_y = 300

my_sprite = arcade.Sprite(RESOURCE_DIR / "pac_man_sprite_sheet.png",
scale=5, image_x=4, image_y=81, image_width=13, image_height=15)
my_sprite = arcade.Sprite(
"pac_man_sprite_sheet.png",
scale=5, image_x=4, image_y=81, image_width=13, image_height=15)
my_sprite.change_x = -1
self.sprite_list.append(my_sprite)
my_sprite.center_x = 800
my_sprite.center_y = 200

my_sprite = arcade.AnimatedTimeBasedSprite()
texture = arcade.load_texture(RESOURCE_DIR / "pac_man_sprite_sheet.png", x=4, y=1, width=13, height=15)
texture = arcade.load_texture(
"pac_man_sprite_sheet.png", x=4, y=1, width=13, height=15)
frame = arcade.AnimationKeyframe(tile_id=0,
duration=150,
texture=texture)
my_sprite.frames.append(frame)
texture = arcade.load_texture(RESOURCE_DIR / "pac_man_sprite_sheet.png", x=20, y=1, width=13, height=15)
texture = arcade.load_texture(
"pac_man_sprite_sheet.png", x=20, y=1, width=13, height=15)
frame = arcade.AnimationKeyframe(tile_id=1,
duration=150,
texture=texture)
Expand All @@ -76,8 +78,8 @@ def on_draw(self):
self.crt_filter.clear()
self.sprite_list.draw()

# Next, switch back to the screen and dump the contents of the CRT filter
# to it.
# Next, switch back to the screen and dump the contents of
# the CRT filter to it.
self.use()
self.clear()
self.crt_filter.draw()
Expand Down
1 change: 0 additions & 1 deletion doc/tutorials/framebuffer/step_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def on_draw(self):
self.clear()
self.filter.clear()
self.filter.use()
print(self.width / 2)
arcade.draw_circle_filled(self.width / 2, self.height / 2, 100, arcade.color.RED)
arcade.draw_circle_filled(400, 300, 100, arcade.color.GREEN)

Expand Down
11 changes: 7 additions & 4 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand Down Expand Up @@ -68,10 +69,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f',
['in_pos'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f',
['in_pos'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down
13 changes: 8 additions & 5 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand All @@ -31,7 +32,7 @@ def __init__(self):

# Program to visualize the points
self.program = self.ctx.load_program(
vertex_shader="vertex_shader_v1.glsl",
vertex_shader="vertex_shader_v2.glsl",
fragment_shader="fragment_shader.glsl",
)

Expand Down Expand Up @@ -81,10 +82,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f 2f',
['in_pos', 'in_vel'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f 2f',
['in_pos', 'in_vel'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down
11 changes: 7 additions & 4 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand Down Expand Up @@ -84,10 +85,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f 2f',
['in_pos', 'in_vel'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f 2f',
['in_pos', 'in_vel'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down
11 changes: 7 additions & 4 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand Down Expand Up @@ -84,10 +85,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f 2f',
['in_pos', 'in_vel'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f 2f',
['in_pos', 'in_vel'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down
11 changes: 7 additions & 4 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand Down Expand Up @@ -90,10 +91,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f 2f 3f',
['in_pos', 'in_vel', 'in_color'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f 2f 3f',
['in_pos', 'in_vel', 'in_color'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down
20 changes: 10 additions & 10 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_07.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand Down Expand Up @@ -66,8 +67,7 @@ def on_update(self, dt):
temp_list = self.burst_list.copy()
for burst in temp_list:
if time.time() - burst.start_time > MAX_FADE_TIME:
self.burst_list.remove(burst)

self.burst_list.remove(burst)

def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
""" User clicks mouse """
Expand All @@ -82,7 +82,8 @@ def _gen_initial_data(initial_x, initial_y):
red = random.uniform(0.5, 1.0)
green = random.uniform(0, red)
blue = 0
fade_rate = random.uniform(1 / MAX_FADE_TIME, 1 / MIN_FADE_TIME)
fade_rate = random.uniform(
1 / MAX_FADE_TIME, 1 / MIN_FADE_TIME)

yield initial_x
yield initial_y
Expand All @@ -104,13 +105,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f 2f 3f f',
['in_pos',
'in_vel',
'in_color',
'in_fade_rate'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f 2f 3f f',
['in_pos', 'in_vel', 'in_color', 'in_fade_rate'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down
17 changes: 9 additions & 8 deletions doc/tutorials/gpu_particle_burst/gpu_particle_burst_08.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from array import array
from dataclasses import dataclass

import arcade
import arcade.gl

Expand Down Expand Up @@ -81,7 +82,8 @@ def _gen_initial_data(initial_x, initial_y):
red = random.uniform(0.5, 1.0)
green = random.uniform(0, red)
blue = 0
fade_rate = random.uniform(1 / MAX_FADE_TIME, 1 / MIN_FADE_TIME)
fade_rate = random.uniform(
1 / MAX_FADE_TIME, 1 / MIN_FADE_TIME)

yield initial_x
yield initial_y
Expand All @@ -103,13 +105,12 @@ def _gen_initial_data(initial_x, initial_y):
# Create a buffer with that data
buffer = self.ctx.buffer(data=array('f', initial_data))

# Create a buffer description that says how the buffer data is formatted.
buffer_description = arcade.gl.BufferDescription(buffer,
'2f 2f 3f f',
['in_pos',
'in_vel',
'in_color',
'in_fade_rate'])
# Create a buffer description specifying the buffer's data format
buffer_description = arcade.gl.BufferDescription(
buffer,
'2f 2f 3f f',
['in_pos', 'in_vel', 'in_color', 'in_fade_rate'])

# Create our Vertex Attribute Object
vao = self.ctx.geometry([buffer_description])

Expand Down

0 comments on commit aa854d6

Please sign in to comment.