forked from pythonarcade/arcade
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import math | ||
import random | ||
import traceback | ||
import arcade | ||
from arcade.experimental.lights import Light, LightLayer | ||
|
||
# Do the math to figure out our screen dimensions | ||
SCREEN_WIDTH = 800 | ||
SCREEN_HEIGHT = 600 | ||
SCREEN_TITLE = "Lighting Demo (Experimental)" | ||
|
||
|
||
class MyGame(arcade.Window): | ||
|
||
def __init__(self, width, height, title): | ||
""" | ||
Set up the application. | ||
""" | ||
super().__init__(width, height, title, resizable=True) | ||
self.time = 0 | ||
self.frame = 0 | ||
self.background = arcade.load_texture(":resources:images/backgrounds/abstract_1.jpg") | ||
|
||
self.light_layer = LightLayer((SCREEN_WIDTH, SCREEN_HEIGHT)) | ||
# Add some random lights | ||
for _ in range(500): | ||
self.light_layer.add( | ||
Light(( | ||
random.randrange(0, SCREEN_WIDTH), | ||
random.randrange(0, SCREEN_HEIGHT)), | ||
radius=50, | ||
mode='soft', | ||
color=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) | ||
), | ||
) | ||
|
||
def on_draw(self): | ||
try: | ||
arcade.start_render() | ||
|
||
# Everything that should be affected by lights in here | ||
with self.light_layer: | ||
arcade.set_background_color(arcade.color.WHITE) | ||
arcade.start_render() | ||
# arcade.draw_lrwh_rectangle_textured( | ||
# 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, self.background) | ||
|
||
# Draw the contents with lighting | ||
self.light_layer.draw() | ||
|
||
image = arcade.get_image() | ||
image.save(f'screenshots/frame{str(self.frame).zfill(3)}.png', 'png') | ||
|
||
except Exception as e: | ||
print(e) | ||
|
||
def on_update(self, dt): | ||
dt = 0.1 | ||
self.frame += 1 | ||
try: | ||
self.time += dt | ||
for i, light in enumerate(self.light_layer): | ||
light.radius = 20 + math.sin(self.time + i) * 40 | ||
except Exception as e: | ||
print(e) | ||
|
||
def on_resize(self, width, height): | ||
arcade.set_viewport(0, width, 0, height) | ||
self.light_layer.resize(width, height) | ||
|
||
|
||
if __name__ == "__main__": | ||
MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) | ||
arcade.run() |