spore-engine 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- demo.py +500 -0
- demos/__init__.py +272 -0
- demos/scene_3d.py +223 -0
- demos/scene_abyssal_bloom.py +515 -0
- demos/scene_anim.py +90 -0
- demos/scene_anim_path.py +94 -0
- demos/scene_astral_cathedral.py +103 -0
- demos/scene_aurora.py +57 -0
- demos/scene_aurora_lagoon.py +444 -0
- demos/scene_aurora_palace.py +106 -0
- demos/scene_aurora_storm.py +115 -0
- demos/scene_autumn_forest.py +730 -0
- demos/scene_bioluminescence.py +78 -0
- demos/scene_biome_demo.py +25 -0
- demos/scene_black_hole.py +134 -0
- demos/scene_braille_current.py +149 -0
- demos/scene_celestial_temple.py +123 -0
- demos/scene_cellular.py +66 -0
- demos/scene_code_shader.py +121 -0
- demos/scene_constellation.py +131 -0
- demos/scene_cosmic_tunnel.py +126 -0
- demos/scene_crystal_cluster.py +133 -0
- demos/scene_crystal_nebula.py +133 -0
- demos/scene_dna.py +56 -0
- demos/scene_double_pendulum.py +115 -0
- demos/scene_dungeon.py +44 -0
- demos/scene_eclipse.py +97 -0
- demos/scene_ecs_lifecycle.py +281 -0
- demos/scene_ecs_swarm.py +286 -0
- demos/scene_erosion.py +51 -0
- demos/scene_ethereal_ruins.py +225 -0
- demos/scene_field_demo.py +59 -0
- demos/scene_fireflies.py +118 -0
- demos/scene_flocking.py +135 -0
- demos/scene_flowfield.py +97 -0
- demos/scene_forest_fire.py +89 -0
- demos/scene_fractals.py +74 -0
- demos/scene_fx.py +126 -0
- demos/scene_galaxy.py +84 -0
- demos/scene_geometric_flower.py +97 -0
- demos/scene_glyph_art.py +157 -0
- demos/scene_god_rays.py +269 -0
- demos/scene_golden_city.py +108 -0
- demos/scene_gravity.py +128 -0
- demos/scene_horizon.py +395 -0
- demos/scene_hypercube.py +119 -0
- demos/scene_infinite_temple.py +152 -0
- demos/scene_isometric.py +46 -0
- demos/scene_kaleidoscope.py +41 -0
- demos/scene_landscape.py +102 -0
- demos/scene_lava.py +80 -0
- demos/scene_lightning.py +77 -0
- demos/scene_lorenz.py +89 -0
- demos/scene_media_player.py +119 -0
- demos/scene_meteor.py +80 -0
- demos/scene_misc.py +106 -0
- demos/scene_neon_cathedral.py +122 -0
- demos/scene_neon_city.py +150 -0
- demos/scene_neon_grid.py +54 -0
- demos/scene_new_features.py +97 -0
- demos/scene_new_features2.py +377 -0
- demos/scene_particles.py +84 -0
- demos/scene_phantom_galaxy.py +78 -0
- demos/scene_phoenix.py +148 -0
- demos/scene_phosphor.py +171 -0
- demos/scene_photo_ascii.py +46 -0
- demos/scene_physics_enhanced.py +131 -0
- demos/scene_physics_rigid.py +103 -0
- demos/scene_platformer.py +174 -0
- demos/scene_powder.py +74 -0
- demos/scene_prism_raytracer.py +72 -0
- demos/scene_ragdoll.py +300 -0
- demos/scene_raytracer_alien.py +37 -0
- demos/scene_raytracer_crystal.py +40 -0
- demos/scene_raytracer_infinity.py +37 -0
- demos/scene_raytracer_jewel.py +46 -0
- demos/scene_raytracer_moonlit.py +43 -0
- demos/scene_raytracer_nebula.py +42 -0
- demos/scene_raytracer_photo.py +36 -0
- demos/scene_raytracer_reflections.py +48 -0
- demos/scene_raytracer_system.py +36 -0
- demos/scene_raytracer_toybox.py +36 -0
- demos/scene_ripples.py +39 -0
- demos/scene_scenery.py +84 -0
- demos/scene_screenfx.py +84 -0
- demos/scene_sdf_csg.py +41 -0
- demos/scene_sdf_dreamscape.py +75 -0
- demos/scene_sdf_glow.py +45 -0
- demos/scene_shader_symphony.py +126 -0
- demos/scene_shaders.py +96 -0
- demos/scene_shadows.py +81 -0
- demos/scene_sierpinski.py +122 -0
- demos/scene_sim.py +65 -0
- demos/scene_solar_flare.py +57 -0
- demos/scene_spline_demo.py +55 -0
- demos/scene_stained_glass.py +68 -0
- demos/scene_starry_night.py +57 -0
- demos/scene_synthwave.py +126 -0
- demos/scene_terminal_app.py +284 -0
- demos/scene_terrain_flyover.py +71 -0
- demos/scene_tilemap.py +108 -0
- demos/scene_timeline.py +86 -0
- demos/scene_tui.py +199 -0
- demos/scene_tunnel.py +35 -0
- demos/scene_ui.py +82 -0
- demos/scene_underwater.py +105 -0
- demos/scene_video_player.py +76 -0
- demos/scene_voxel_world.py +59 -0
- demos/scene_walkers.py +317 -0
- demos/scene_worley.py +34 -0
- easy_demo.py +81 -0
- shader_sandbox.py +26 -0
- spore_engine/__init__.py +170 -0
- spore_engine/__version__.py +4 -0
- spore_engine/anim/__init__.py +3 -0
- spore_engine/anim/anim.py +401 -0
- spore_engine/anim/ik.py +198 -0
- spore_engine/anim/timeline.py +191 -0
- spore_engine/cli.py +267 -0
- spore_engine/core/__init__.py +150 -0
- spore_engine/core/_accel.py +49 -0
- spore_engine/core/_optional.py +40 -0
- spore_engine/core/assets.py +324 -0
- spore_engine/core/camera.py +94 -0
- spore_engine/core/canvas.py +692 -0
- spore_engine/core/color.py +282 -0
- spore_engine/core/draw.py +542 -0
- spore_engine/core/ecs.py +197 -0
- spore_engine/core/geom.py +247 -0
- spore_engine/core/glyphs.py +62 -0
- spore_engine/core/input.py +702 -0
- spore_engine/core/reload.py +282 -0
- spore_engine/core/scene.py +145 -0
- spore_engine/core/scene_file.py +375 -0
- spore_engine/core/sprite.py +55 -0
- spore_engine/core/state.py +184 -0
- spore_engine/core/term.py +541 -0
- spore_engine/core/util.py +170 -0
- spore_engine/easy/__init__.py +17 -0
- spore_engine/easy/anim.py +164 -0
- spore_engine/easy/app.py +747 -0
- spore_engine/easy/sprite.py +297 -0
- spore_engine/easy/systems.py +908 -0
- spore_engine/easy/util.py +15 -0
- spore_engine/easy/widgets.py +101 -0
- spore_engine/fx/__init__.py +15 -0
- spore_engine/fx/effects.py +376 -0
- spore_engine/fx/field.py +117 -0
- spore_engine/fx/lightfield.py +621 -0
- spore_engine/fx/lighting.py +163 -0
- spore_engine/fx/postfx.py +268 -0
- spore_engine/fx/screenfx.py +157 -0
- spore_engine/fx/shader_lab.py +430 -0
- spore_engine/fx/shaderlab.py +345 -0
- spore_engine/fx/shaders.py +528 -0
- spore_engine/fx/textfx.py +143 -0
- spore_engine/fx/transitions.py +159 -0
- spore_engine/fx/volumetric.py +195 -0
- spore_engine/gen/__init__.py +13 -0
- spore_engine/gen/biome_terrain.py +105 -0
- spore_engine/gen/delaunay.py +173 -0
- spore_engine/gen/dungeon.py +515 -0
- spore_engine/gen/erosion.py +202 -0
- spore_engine/gen/fractals.py +171 -0
- spore_engine/gen/lsystem.py +87 -0
- spore_engine/gen/marching_cubes.py +394 -0
- spore_engine/gen/maze.py +144 -0
- spore_engine/gen/pathfinding.py +140 -0
- spore_engine/gen/scenery.py +292 -0
- spore_engine/gen/splines.py +98 -0
- spore_engine/gen/terrain.py +152 -0
- spore_engine/gen/wfc.py +202 -0
- spore_engine/media/__init__.py +5 -0
- spore_engine/media/_pillow_compat.py +24 -0
- spore_engine/media/ansi_io.py +175 -0
- spore_engine/media/converter.py +264 -0
- spore_engine/media/export.py +378 -0
- spore_engine/media/ffmpeg.py +225 -0
- spore_engine/media/glyphart.py +326 -0
- spore_engine/media/imaging.py +110 -0
- spore_engine/media/img3d.py +201 -0
- spore_engine/media/video.py +287 -0
- spore_engine/render3d/__init__.py +7 -0
- spore_engine/render3d/engine3d.py +250 -0
- spore_engine/render3d/isometric.py +91 -0
- spore_engine/render3d/model_loader.py +127 -0
- spore_engine/render3d/raytracer.py +386 -0
- spore_engine/render3d/sdf.py +231 -0
- spore_engine/render3d/voxel.py +100 -0
- spore_engine/sim/__init__.py +9 -0
- spore_engine/sim/cellular.py +277 -0
- spore_engine/sim/fluid.py +261 -0
- spore_engine/sim/noise.py +248 -0
- spore_engine/sim/physics.py +988 -0
- spore_engine/sim/physics3d.py +194 -0
- spore_engine/sim/powder.py +447 -0
- spore_engine/sim/softbody.py +238 -0
- spore_engine/sim/steering.py +228 -0
- spore_engine/ui/__init__.py +4 -0
- spore_engine/ui/font.py +113 -0
- spore_engine/ui/tilemap.py +194 -0
- spore_engine/ui/toolkit.py +476 -0
- spore_engine/ui/widgets.py +819 -0
- spore_engine-0.1.0.dist-info/METADATA +342 -0
- spore_engine-0.1.0.dist-info/RECORD +209 -0
- spore_engine-0.1.0.dist-info/WHEEL +5 -0
- spore_engine-0.1.0.dist-info/entry_points.txt +3 -0
- spore_engine-0.1.0.dist-info/licenses/LICENSE +121 -0
- spore_engine-0.1.0.dist-info/top_level.txt +5 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Code shaders: a fragment program written in Python, running over the canvas.
|
|
2
|
+
|
|
3
|
+
Every other shader demo ships a prebuilt shader *class*. This one compiles a
|
|
4
|
+
program at runtime from a source file, which is the whole authoring loop:
|
|
5
|
+
|
|
6
|
+
python3 shader_sandbox.py # live preview, edit and save
|
|
7
|
+
spore shader # same thing
|
|
8
|
+
spore-demo --scene "Code Shader" # and it runs in the demo reel
|
|
9
|
+
|
|
10
|
+
Save the file while any of those is running and the frame updates in place --
|
|
11
|
+
no restart, no lost state.
|
|
12
|
+
"""
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
from spore_engine.core.canvas import Canvas
|
|
16
|
+
from spore_engine.core.color import Color, DIM
|
|
17
|
+
from spore_engine.fx.shaderlab import ShaderError, ShaderProgram
|
|
18
|
+
|
|
19
|
+
_SOURCE = '''\
|
|
20
|
+
# A whole-canvas shader: draw(canvas, t, dt) is called once per frame.
|
|
21
|
+
# Cell shaders use shade(x, y, w, h, t, src) instead and may return
|
|
22
|
+
# (char, fg) or (char, fg, bg).
|
|
23
|
+
|
|
24
|
+
u = {'hue': 0.55, 'speed': 1.0}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def draw(canvas, t, dt):
|
|
28
|
+
from math import sin, cos, hypot
|
|
29
|
+
w, h = canvas.w, canvas.h
|
|
30
|
+
cx, cy = w / 2, h / 2
|
|
31
|
+
for y in range(h):
|
|
32
|
+
for x in range(w):
|
|
33
|
+
dx, dy = x - cx, y - cy
|
|
34
|
+
d = hypot(dx, dy) + 1e-6
|
|
35
|
+
a = __import__('math').atan2(dy, dx)
|
|
36
|
+
ripple = sin(d * 0.55 - t * 3.0 * u['speed']) * 0.5 + 0.5
|
|
37
|
+
bands = (a / 6.2832 + t * 0.06 * u['speed']) % 1.0
|
|
38
|
+
v = ripple * 0.6 + bands * 0.4
|
|
39
|
+
ramp = ' .:-=+*#%@'
|
|
40
|
+
ci = min(len(ramp) - 1, int(v * len(ramp)))
|
|
41
|
+
canvas.set_pixel(x, y, ramp[ci], Color.from_hsv(
|
|
42
|
+
(u['hue'] + v * 0.25) % 1.0, 0.7, 0.25 + 0.75 * v))
|
|
43
|
+
'''
|
|
44
|
+
|
|
45
|
+
_PROG = None
|
|
46
|
+
_SRC_PATH = None
|
|
47
|
+
_ERROR = None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _ensure(path=None):
|
|
51
|
+
"""Compile the shader once, writing the starter file on first run.
|
|
52
|
+
|
|
53
|
+
Returns the live program, or ``None`` while it is broken. Recompiling
|
|
54
|
+
every frame would work but is the wrong shape: a fresh program each
|
|
55
|
+
frame means frame counters and cost measurements are meaningless, and the
|
|
56
|
+
error state flickers instead of persisting until the file is fixed.
|
|
57
|
+
"""
|
|
58
|
+
global _PROG, _SRC_PATH, _ERROR
|
|
59
|
+
if _SRC_PATH is None or path:
|
|
60
|
+
_SRC_PATH = path or os.path.join(
|
|
61
|
+
os.path.dirname(os.path.abspath(__file__)), 'shader_code.spore')
|
|
62
|
+
if not os.path.exists(_SRC_PATH):
|
|
63
|
+
with open(_SRC_PATH, 'w', encoding='utf-8') as fh:
|
|
64
|
+
fh.write(_SOURCE)
|
|
65
|
+
if _PROG is None:
|
|
66
|
+
# Compile whenever there is no live program, not only when the path
|
|
67
|
+
# changes: a failed first compile leaves _PROG as None, and keying off
|
|
68
|
+
# the path alone would never retry after the file was fixed.
|
|
69
|
+
try:
|
|
70
|
+
_PROG = ShaderProgram(path=_SRC_PATH)
|
|
71
|
+
_ERROR = None
|
|
72
|
+
except ShaderError as exc:
|
|
73
|
+
_ERROR = str(exc)
|
|
74
|
+
return _PROG
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def scene_code_shader(c: Canvas, hr, t: float, pt: float, dt: float):
|
|
78
|
+
global _ERROR
|
|
79
|
+
prog = _ensure()
|
|
80
|
+
c.clear()
|
|
81
|
+
|
|
82
|
+
if _PROG is not None:
|
|
83
|
+
try:
|
|
84
|
+
# Only clear a stale error when a reload actually happened. If no
|
|
85
|
+
# reload ran, `_ERROR` may still describe a failure from earlier
|
|
86
|
+
# in this frame loop and clearing it would hide the problem.
|
|
87
|
+
if prog.reload_if_changed():
|
|
88
|
+
_ERROR = None
|
|
89
|
+
except ShaderError as exc:
|
|
90
|
+
_ERROR = str(exc)
|
|
91
|
+
if _ERROR is not None or _PROG is None:
|
|
92
|
+
# A failed reload leaves the previous program intact, so `apply` would
|
|
93
|
+
# happily draw another good frame and the error would never be seen.
|
|
94
|
+
# Report it and keep the last picture underneath.
|
|
95
|
+
if _PROG is not None:
|
|
96
|
+
prog.apply(c, t, dt)
|
|
97
|
+
return _report(c)
|
|
98
|
+
|
|
99
|
+
prog.apply(c, t, dt)
|
|
100
|
+
if prog.error is not None:
|
|
101
|
+
exc, _tb = prog.error
|
|
102
|
+
_ERROR = f'{type(exc).__name__}: {exc}'
|
|
103
|
+
return _report(c)
|
|
104
|
+
|
|
105
|
+
# last_us is microseconds.
|
|
106
|
+
c.draw_text(2, 1,
|
|
107
|
+
f' {prog.name} {prog.last_us / 1000.0:5.2f} ms '
|
|
108
|
+
f'{prog.frames} frames', DIM, z=99)
|
|
109
|
+
c.draw_text(2, c.h - 2,
|
|
110
|
+
f' live code shader — edit {os.path.basename(_SRC_PATH)} '
|
|
111
|
+
'and save', DIM, z=99)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _report(c: Canvas):
|
|
115
|
+
"""Explain the failure over the last good frame, which is still visible
|
|
116
|
+
because a broken shader is not allowed to clear the canvas."""
|
|
117
|
+
c.draw_text(2, 1, ' shader failed:', Color(255, 90, 90), z=99)
|
|
118
|
+
for i, line in enumerate((_ERROR or '').splitlines()[:c.h - 3]):
|
|
119
|
+
c.draw_text(4, 3 + i, line, DIM, z=99)
|
|
120
|
+
c.draw_text(2, c.h - 2, f' fix {os.path.basename(_SRC_PATH)} and save',
|
|
121
|
+
DIM, z=99)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import random
|
|
3
|
+
from spore_engine import *
|
|
4
|
+
from spore_engine.core.color import *
|
|
5
|
+
|
|
6
|
+
_CON = None
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _init():
|
|
10
|
+
global _CON
|
|
11
|
+
if _CON is not None:
|
|
12
|
+
return
|
|
13
|
+
rnd = random.Random(99)
|
|
14
|
+
n = 90
|
|
15
|
+
pts = []
|
|
16
|
+
# fibonacci sphere for even distribution
|
|
17
|
+
ga = math.pi * (3 - math.sqrt(5))
|
|
18
|
+
for i in range(n):
|
|
19
|
+
y = 1 - (i / (n - 1)) * 2
|
|
20
|
+
r = math.sqrt(1 - y * y)
|
|
21
|
+
theta = ga * i
|
|
22
|
+
pts.append((math.cos(theta) * r, y, math.sin(theta) * r))
|
|
23
|
+
edges = []
|
|
24
|
+
for i in range(n):
|
|
25
|
+
dists = []
|
|
26
|
+
for j in range(n):
|
|
27
|
+
if i == j:
|
|
28
|
+
continue
|
|
29
|
+
dx = pts[i][0] - pts[j][0]
|
|
30
|
+
dy = pts[i][1] - pts[j][1]
|
|
31
|
+
dz = pts[i][2] - pts[j][2]
|
|
32
|
+
dists.append((dx * dx + dy * dy + dz * dz, j))
|
|
33
|
+
dists.sort()
|
|
34
|
+
for d, j in dists[:4]:
|
|
35
|
+
if (j, i) not in edges and (i, j) not in edges:
|
|
36
|
+
edges.append((i, j))
|
|
37
|
+
_CON = {
|
|
38
|
+
'pts': pts,
|
|
39
|
+
'edges': edges,
|
|
40
|
+
'bright': sorted(range(n),
|
|
41
|
+
key=lambda i: rnd.random())[:14],
|
|
42
|
+
'palette': [(0.6, 0.9, 1.0), (0.95, 0.95, 1.0),
|
|
43
|
+
(1.0, 0.8, 0.5), (0.7, 0.8, 1.0)],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _rot(p, ay, ax):
|
|
48
|
+
x, y, z = p
|
|
49
|
+
cx, sx = math.cos(ay), math.sin(ay)
|
|
50
|
+
x2 = x * cx + z * sx
|
|
51
|
+
z2 = -x * sx + z * cx
|
|
52
|
+
x, z = x2, z2
|
|
53
|
+
cy, sy = math.cos(ax), math.sin(ax)
|
|
54
|
+
y2 = y * cy - z * sy
|
|
55
|
+
z3 = y * sy + z * cy
|
|
56
|
+
return (x, y2, z3)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _line(hr, x1, y1, x2, y2, fg, z=0):
|
|
60
|
+
n = max(abs(x2 - x1), abs(y2 - y1))
|
|
61
|
+
if n == 0:
|
|
62
|
+
hr.set_pixel(x1, y1, '·', fg=fg, z=z)
|
|
63
|
+
return
|
|
64
|
+
for i in range(n + 1):
|
|
65
|
+
tt = i / n
|
|
66
|
+
hr.set_pixel(int(x1 + (x2 - x1) * tt), int(y1 + (y2 - y1) * tt),
|
|
67
|
+
'·', fg=fg, z=z)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def scene_constellation(c, hr, t, pt, dt):
|
|
71
|
+
"""Constellation - a rotating sphere of stars joined by constellation lines"""
|
|
72
|
+
w, h = hr.w, hr.h
|
|
73
|
+
_init()
|
|
74
|
+
s = _CON
|
|
75
|
+
|
|
76
|
+
cx, cy = c.w / 2, c.h / 2
|
|
77
|
+
for y in range(c.h):
|
|
78
|
+
for x in range(c.w):
|
|
79
|
+
nx = (x - cx) / (c.w * 0.5)
|
|
80
|
+
ny = (y - cy) / (c.h * 0.5)
|
|
81
|
+
d = math.hypot(nx, ny)
|
|
82
|
+
col = Color(4, 3, 12).lerp(Color(20, 8, 40), max(0, 1 - d * 0.9))
|
|
83
|
+
c.set_pixel(x, y, ' ', bg=col, z=-100)
|
|
84
|
+
|
|
85
|
+
cx, cy = w / 2, h / 2
|
|
86
|
+
scale = min(w, h) * 0.34
|
|
87
|
+
ay = t * 0.25
|
|
88
|
+
ax = 0.4 + 0.25 * math.sin(t * 0.1)
|
|
89
|
+
|
|
90
|
+
proj = []
|
|
91
|
+
for p in s['pts']:
|
|
92
|
+
x, y, z = _rot(p, ay, ax)
|
|
93
|
+
persp = 1.0 / (1.0 + 0.5 * z)
|
|
94
|
+
px = cx + x * scale * persp
|
|
95
|
+
py = cy - y * scale * persp
|
|
96
|
+
depth = (z + 1) * 0.5
|
|
97
|
+
proj.append((px, py, depth))
|
|
98
|
+
|
|
99
|
+
for i, j in s['edges']:
|
|
100
|
+
x1, y1, d1 = proj[i]
|
|
101
|
+
x2, y2, d2 = proj[j]
|
|
102
|
+
dim = 0.05 + 0.18 * (1 - (d1 + d2) / 2)
|
|
103
|
+
b = int(255 * dim)
|
|
104
|
+
_line(hr, int(x1), int(y1), int(x2), int(y2),
|
|
105
|
+
Color(b, int(b * 0.9), int(b * 1.25)), z=20)
|
|
106
|
+
|
|
107
|
+
for i, p in enumerate(proj):
|
|
108
|
+
px, py, depth = p
|
|
109
|
+
tw = 0.5 + 0.5 * math.sin(t * 1.5 + i * 1.37)
|
|
110
|
+
fade = 1.0 - depth * 0.55
|
|
111
|
+
if i in s['bright']:
|
|
112
|
+
col_i = i % len(s['palette'])
|
|
113
|
+
r, g, b = s['palette'][col_i]
|
|
114
|
+
bri = (0.55 + 0.45 * tw) * fade
|
|
115
|
+
col = Color(int(r * 255 * bri), int(g * 255 * bri),
|
|
116
|
+
int(b * 255 * bri))
|
|
117
|
+
ch = '✦' if tw > 0.7 else '·'
|
|
118
|
+
hr.set_pixel(int(px), int(py), ch, fg=col, z=60)
|
|
119
|
+
if tw > 0.85:
|
|
120
|
+
hr.set_pixel(int(px), int(py - 1), '·',
|
|
121
|
+
fg=col.mul(0.4), z=55)
|
|
122
|
+
else:
|
|
123
|
+
bri = (0.2 + 0.5 * tw) * fade
|
|
124
|
+
if bri < 0.1:
|
|
125
|
+
continue
|
|
126
|
+
col = Color(int(150 * bri), int(160 * bri), int(255 * bri))
|
|
127
|
+
hr.set_pixel(int(px), int(py), '·', fg=col, z=50)
|
|
128
|
+
|
|
129
|
+
hr.to_canvas(c)
|
|
130
|
+
c.draw_text(2, 0, '✦ Constellation ✦', Color(200, 210, 255), z=100)
|
|
131
|
+
c.draw_text(2, c.h - 1, 'star sphere | constellation lines', DIM, z=100)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from spore_engine import *
|
|
3
|
+
from spore_engine.core.color import *
|
|
4
|
+
from spore_engine.render3d.sdf import *
|
|
5
|
+
from spore_engine.core.geom import Vec3
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Precomputed state - avoids recomputing ring/star trig inside SDF callbacks (huge perf win)
|
|
9
|
+
_cosmic_state = {
|
|
10
|
+
'rings': [], # list of (x, y, z, major_r) per ring
|
|
11
|
+
'stars': [], # list of (x, y, z) per star
|
|
12
|
+
'cz': 0,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def scene_cosmic_tunnel(c: Canvas, hr: HiResCanvas, t: float, pt, dt: float):
|
|
17
|
+
"""Cosmic Tunnel - Psychedelic ray marched tunnel through space with warp drive effect"""
|
|
18
|
+
global _cosmic_state
|
|
19
|
+
cz = t * 0.6 # tunnel progress
|
|
20
|
+
|
|
21
|
+
# Precompute ring/star positions ONCE per frame (not inside SDF callbacks!)
|
|
22
|
+
rings = []
|
|
23
|
+
for i in range(8):
|
|
24
|
+
z_pos = cz + 1 + i * 1.5 + math.sin(t * 0.3 + i * 1.1) * 0.2
|
|
25
|
+
rings.append((
|
|
26
|
+
0.8 * math.cos(i * 1.2 + t * 0.5),
|
|
27
|
+
0.8 * math.sin(i * 1.2 + t * 0.5),
|
|
28
|
+
z_pos,
|
|
29
|
+
0.75,
|
|
30
|
+
))
|
|
31
|
+
|
|
32
|
+
stars = []
|
|
33
|
+
for i in range(12):
|
|
34
|
+
z_pos = cz + 0.5 + i * 1.2 + math.sin(t * 0.4 + i * 1.7) * 0.3
|
|
35
|
+
stars.append((
|
|
36
|
+
1.8 * math.cos(i * 3.7 + t * 1.2),
|
|
37
|
+
1.8 * math.sin(i * 3.7 + t * 1.2),
|
|
38
|
+
z_pos,
|
|
39
|
+
))
|
|
40
|
+
|
|
41
|
+
_cosmic_state['rings'] = rings
|
|
42
|
+
_cosmic_state['stars'] = stars
|
|
43
|
+
_cosmic_state['cz'] = cz
|
|
44
|
+
s = _cosmic_state
|
|
45
|
+
|
|
46
|
+
_g_scene = SDFScene()
|
|
47
|
+
_g_scene.ambient = Color(5, 3, 20)
|
|
48
|
+
_g_scene.max_steps = 48
|
|
49
|
+
_g_scene.max_dist = 35
|
|
50
|
+
_g_scene.bg_color = Color(2, 1, 10)
|
|
51
|
+
|
|
52
|
+
# SDF functions reference precomputed arrays - no trig inside callbacks
|
|
53
|
+
def tunnel(p):
|
|
54
|
+
radius = math.hypot(p.x, p.z)
|
|
55
|
+
d = radius - 2.5
|
|
56
|
+
rib = abs(math.sin(p.z * 4.0 - s['cz'] * 2.0)) * 0.12
|
|
57
|
+
d = op_union(d, radius - (2.5 - rib))
|
|
58
|
+
d += math.sin(p.z * 6.0 + p.x * 2.0 + s['cz'] * 3.0) * 0.08
|
|
59
|
+
return d
|
|
60
|
+
|
|
61
|
+
def end_glow(p):
|
|
62
|
+
return sd_sphere(p, Vec3(0, 0, s['cz'] + 18), 1.8)
|
|
63
|
+
|
|
64
|
+
def moving_rings(p):
|
|
65
|
+
d = 1e9
|
|
66
|
+
for rx, ry, rz, mr in s['rings']:
|
|
67
|
+
d = op_union(d, sd_torus(p, Vec3(rx, ry, rz), mr, 0.04))
|
|
68
|
+
return d
|
|
69
|
+
|
|
70
|
+
def moving_stars(p):
|
|
71
|
+
d = 1e9
|
|
72
|
+
for sx, sy, sz in s['stars']:
|
|
73
|
+
d = op_union(d, sd_sphere(p, Vec3(sx, sy, sz), 0.04))
|
|
74
|
+
return d
|
|
75
|
+
|
|
76
|
+
_g_scene.add(tunnel, Color(60, 40, 110), reflectivity=0.2)
|
|
77
|
+
_g_scene.add(end_glow, Color(255, 220, 150), emissive=0.9)
|
|
78
|
+
_g_scene.add(moving_rings, Color(100, 200, 255), reflectivity=0.3, emissive=0.15)
|
|
79
|
+
_g_scene.add(moving_stars, Color(255, 255, 220), emissive=0.7)
|
|
80
|
+
|
|
81
|
+
_g_scene.add_light(Vec3(2, 2, s['cz'] + 3), Color(255, 200, 180), 1.5)
|
|
82
|
+
_g_scene.add_light(Vec3(-2, -2, s['cz'] + 8), Color(180, 200, 255), 1.2)
|
|
83
|
+
_g_scene.add_light(Vec3(0, 0, s['cz'] + 20), Color(255, 220, 200), 2.0)
|
|
84
|
+
|
|
85
|
+
camera = Vec3(0.3 * math.sin(t * 0.5), 0.3 * math.cos(t * 0.7), s['cz'])
|
|
86
|
+
target = Vec3(0, 0, s['cz'] + 3)
|
|
87
|
+
_g_scene.render(c, camera, target, 70)
|
|
88
|
+
|
|
89
|
+
_apply_glow(c)
|
|
90
|
+
|
|
91
|
+
hue = (t * 0.03) % 1.0
|
|
92
|
+
c.draw_text(2, 0, '✦ Cosmic Tunnel ✦', Color.from_hsv(hue, 0.7, 1.0), z=100)
|
|
93
|
+
c.draw_text(2, c.h - 1, 'warp drive | tunnel vision | star stream | neon rings', DIM, z=100)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _apply_glow(canvas: Canvas, intensity: float = 0.10):
|
|
97
|
+
"""Simple glow/bloom effect"""
|
|
98
|
+
w, h = canvas.w, canvas.h
|
|
99
|
+
buf = [[None] * w for _ in range(h)]
|
|
100
|
+
for y in range(h):
|
|
101
|
+
for x in range(w):
|
|
102
|
+
cell = canvas.buffer[y][x]
|
|
103
|
+
if cell.fg:
|
|
104
|
+
buf[y][x] = (cell.fg.r, cell.fg.g, cell.fg.b)
|
|
105
|
+
blurred = [[None] * w for _ in range(h)]
|
|
106
|
+
for y in range(1, h - 1):
|
|
107
|
+
for x in range(1, w - 1):
|
|
108
|
+
r, g, b, n = 0, 0, 0, 0
|
|
109
|
+
for dy in (-1, 0, 1):
|
|
110
|
+
for dx in (-1, 0, 1):
|
|
111
|
+
px = buf[y + dy][x + dx]
|
|
112
|
+
if px:
|
|
113
|
+
r += px[0]; g += px[1]; b += px[2]; n += 1
|
|
114
|
+
if n > 0:
|
|
115
|
+
blurred[y][x] = (r // n, g // n, b // n)
|
|
116
|
+
for y in range(h):
|
|
117
|
+
for x in range(w):
|
|
118
|
+
cell = canvas.buffer[y][x]
|
|
119
|
+
bl = blurred[y][x]
|
|
120
|
+
if bl and cell.fg:
|
|
121
|
+
cell.fg = Color(
|
|
122
|
+
min(255, int(cell.fg.r + bl[0] * intensity)),
|
|
123
|
+
min(255, int(cell.fg.g + bl[1] * intensity)),
|
|
124
|
+
min(255, int(cell.fg.b + bl[2] * intensity)),
|
|
125
|
+
)
|
|
126
|
+
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import random
|
|
3
|
+
from spore_engine import *
|
|
4
|
+
from spore_engine.core.color import *
|
|
5
|
+
from spore_engine.render3d.engine3d import Mesh3D, render_mesh_solid
|
|
6
|
+
|
|
7
|
+
_CC = None
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _octahedron(size=1.0):
|
|
11
|
+
m = Mesh3D('octahedron')
|
|
12
|
+
m.verts = [Vec3(1, 0, 0), Vec3(-1, 0, 0), Vec3(0, 1, 0), Vec3(0, -1, 0),
|
|
13
|
+
Vec3(0, 0, 1), Vec3(0, 0, -1)]
|
|
14
|
+
m.faces = [
|
|
15
|
+
[0, 2, 4], [4, 2, 1], [1, 2, 5], [5, 2, 0],
|
|
16
|
+
[4, 3, 0], [1, 3, 4], [5, 3, 1], [0, 3, 5],
|
|
17
|
+
]
|
|
18
|
+
m.face_colors = [Color(220, 220, 255)] * len(m.faces)
|
|
19
|
+
return m
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _init(w, h):
|
|
23
|
+
global _CC
|
|
24
|
+
if _CC is not None:
|
|
25
|
+
return
|
|
26
|
+
rnd = random.Random(42)
|
|
27
|
+
_CC = {
|
|
28
|
+
'stars': [(rnd.uniform(0, w), rnd.uniform(0, h * 0.8),
|
|
29
|
+
rnd.uniform(0, 2 * math.pi), rnd.uniform(0.3, 1.0))
|
|
30
|
+
for _ in range(110)],
|
|
31
|
+
'sparkles': [(rnd.uniform(0, 2 * math.pi), rnd.uniform(1.6, 3.0),
|
|
32
|
+
rnd.uniform(0, 2 * math.pi))
|
|
33
|
+
for _ in range(24)],
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _build_cluster(t):
|
|
38
|
+
meshes = []
|
|
39
|
+
|
|
40
|
+
core = Mesh3D.icosphere(0.9, 1)
|
|
41
|
+
core = core.transform(Mat4.rotate_y(t * 0.35) @ Mat4.rotate_x(t * 0.22))
|
|
42
|
+
meshes.append(core)
|
|
43
|
+
|
|
44
|
+
cube_setup = [
|
|
45
|
+
(Vec3(1.15, 0.2, 0.1), 1.1, Vec3(t * 0.5, t * 0.3, 0)),
|
|
46
|
+
(Vec3(-1.0, -0.35, 0.45), 1.1, Vec3(-t * 0.4, t * 0.55, t * 0.2)),
|
|
47
|
+
(Vec3(0.25, -1.05, -0.5), 1.1, Vec3(t * 0.6, -t * 0.35, t * 0.4)),
|
|
48
|
+
(Vec3(-0.3, 0.95, -0.4), 1.1, Vec3(-t * 0.3, -t * 0.45, t * 0.5)),
|
|
49
|
+
]
|
|
50
|
+
for pos, size, rot in cube_setup:
|
|
51
|
+
cube = Mesh3D.cube(size)
|
|
52
|
+
cube = cube.transform(
|
|
53
|
+
Mat4.translate(pos.x, pos.y, pos.z)
|
|
54
|
+
@ Mat4.rotate_x(rot.x) @ Mat4.rotate_y(rot.y) @ Mat4.rotate_z(rot.z)
|
|
55
|
+
)
|
|
56
|
+
meshes.append(cube)
|
|
57
|
+
|
|
58
|
+
octa = _octahedron(1.35)
|
|
59
|
+
octa = octa.transform(
|
|
60
|
+
Mat4.translate(0.35, 0.55, -0.2)
|
|
61
|
+
@ Mat4.rotate_x(t * 0.45 + 1.0) @ Mat4.rotate_z(t * 0.3)
|
|
62
|
+
)
|
|
63
|
+
meshes.append(octa)
|
|
64
|
+
|
|
65
|
+
ring = Mesh3D.torus(1.7, 0.08, 36, 8)
|
|
66
|
+
ring = ring.transform(
|
|
67
|
+
Mat4.translate(-0.05, 0.0, 0.1)
|
|
68
|
+
@ Mat4.rotate_x(math.pi * 0.5 + t * 0.2) @ Mat4.rotate_y(t * 0.15)
|
|
69
|
+
@ Mat4.scale(1, 0.6, 1)
|
|
70
|
+
)
|
|
71
|
+
meshes.append(ring)
|
|
72
|
+
|
|
73
|
+
hues = [0.6, 0.05, 0.5, 0.9, 0.75, 0.25, 0.45]
|
|
74
|
+
for i, m in enumerate(meshes):
|
|
75
|
+
m.face_colors = [Color.from_hsv(hues[i], 0.9, 1.0)] * len(m.faces)
|
|
76
|
+
return meshes
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def scene_crystal_cluster(c, hr, t, pt, dt):
|
|
80
|
+
"""Crystal Cluster - interpenetrating polyhedra resolved by the z-buffer"""
|
|
81
|
+
w, h = hr.w, hr.h
|
|
82
|
+
_init(w, h)
|
|
83
|
+
s = _CC
|
|
84
|
+
|
|
85
|
+
cx, cy = c.w / 2, c.h / 2
|
|
86
|
+
for y in range(c.h):
|
|
87
|
+
for x in range(c.w):
|
|
88
|
+
nx = (x - cx) / (c.w * 0.5)
|
|
89
|
+
ny = (y - cy) / (c.h * 0.5)
|
|
90
|
+
d = math.hypot(nx, ny)
|
|
91
|
+
ang = math.atan2(ny, nx)
|
|
92
|
+
hue = (0.62 + ang / (2 * math.pi) + t * 0.008) % 1.0
|
|
93
|
+
neb = Color.from_hsv(hue, 0.6, 0.10)
|
|
94
|
+
deep = Color(2, 1, 8)
|
|
95
|
+
glow = max(0.0, 1 - d * 1.1)
|
|
96
|
+
col = deep.lerp(neb, min(1, 0.25 + glow * 0.75))
|
|
97
|
+
c.set_pixel(x, y, ' ', bg=col, z=-100)
|
|
98
|
+
|
|
99
|
+
cx, cy = w / 2, h / 2
|
|
100
|
+
for sx, sy, ph, bri in s['stars']:
|
|
101
|
+
tw = 0.5 + 0.5 * math.sin(t * 1.6 + ph * 5 + sx * 2.3)
|
|
102
|
+
v = tw * bri
|
|
103
|
+
if v < 0.15:
|
|
104
|
+
continue
|
|
105
|
+
b = int(min(255, v * 255))
|
|
106
|
+
hr.set_pixel(int(sx), int(sy), '·' if v < 0.5 else '✦',
|
|
107
|
+
fg=Color(b, b, min(255, int(b * 1.2))), z=50)
|
|
108
|
+
|
|
109
|
+
meshes = _build_cluster(t)
|
|
110
|
+
eye = Vec3(4.1 * math.sin(t * 0.09), 1.1 + 0.5 * math.sin(t * 0.13),
|
|
111
|
+
4.1 * math.cos(t * 0.09))
|
|
112
|
+
view = Mat4.look_at(eye, Vec3(0, 0, 0))
|
|
113
|
+
proj = Mat4.perspective(1.0, w / h, 0.1, 30)
|
|
114
|
+
|
|
115
|
+
for i, m in enumerate(meshes):
|
|
116
|
+
ldir = Vec3(math.sin(t * 0.3 + i * 1.7), -0.4,
|
|
117
|
+
math.cos(t * 0.3 + i * 1.7)).norm()
|
|
118
|
+
render_mesh_solid(hr, m, view, proj, ldir, None)
|
|
119
|
+
|
|
120
|
+
for ph, rad, spd in s['sparkles']:
|
|
121
|
+
a = ph + t * spd
|
|
122
|
+
px = cx + math.cos(a) * rad * (w / h)
|
|
123
|
+
py = cy + math.sin(a) * rad * 0.5
|
|
124
|
+
if 0 <= px < w and 0 <= py < h:
|
|
125
|
+
tw = 0.5 + 0.5 * math.sin(t * 3 + ph * 7)
|
|
126
|
+
col = Color.from_hsv((0.6 + ph / 6.28) % 1, 0.9, 0.4 + 0.6 * tw)
|
|
127
|
+
hr.set_pixel(int(px), int(py), '✧', fg=col, z=70)
|
|
128
|
+
|
|
129
|
+
hr.to_canvas(c)
|
|
130
|
+
c.draw_text(2, 0, '◆ Crystal Cluster ◆',
|
|
131
|
+
Color.from_hsv((t * 0.02) % 1, 0.8, 1.0), z=100)
|
|
132
|
+
c.draw_text(2, c.h - 1,
|
|
133
|
+
'intersecting polyhedra | per-pixel z-buffer', DIM, z=100)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import math, random
|
|
2
|
+
from spore_engine import *
|
|
3
|
+
from spore_engine.core.color import *
|
|
4
|
+
|
|
5
|
+
_CN = None
|
|
6
|
+
|
|
7
|
+
def scene_crystal_nebula(c, hr, t, pt, dt):
|
|
8
|
+
global _CN
|
|
9
|
+
w, h = c.w, c.h
|
|
10
|
+
cx, cy = w / 2, h / 2
|
|
11
|
+
|
|
12
|
+
if _CN is None:
|
|
13
|
+
crystals = []
|
|
14
|
+
for _ in range(12):
|
|
15
|
+
size = random.uniform(1.5, 5.0)
|
|
16
|
+
crystals.append({
|
|
17
|
+
'x': random.uniform(w * 0.1, w * 0.9),
|
|
18
|
+
'y': random.uniform(h * 0.1, h * 0.9),
|
|
19
|
+
'z': random.uniform(0.3, 1.0),
|
|
20
|
+
'size': size,
|
|
21
|
+
'rot': random.uniform(0, 2*math.pi),
|
|
22
|
+
'rot_speed': random.uniform(-0.3, 0.3),
|
|
23
|
+
'hue': random.uniform(0.55, 0.95),
|
|
24
|
+
'hue_width': random.uniform(0.05, 0.2),
|
|
25
|
+
'phase': random.uniform(0, 2*math.pi),
|
|
26
|
+
'sharpness': random.uniform(0.5, 1.0),
|
|
27
|
+
})
|
|
28
|
+
floaters = []
|
|
29
|
+
for _ in range(80):
|
|
30
|
+
floaters.append({
|
|
31
|
+
'x': random.uniform(0, w), 'y': random.uniform(0, h),
|
|
32
|
+
'vx': random.uniform(-0.2, 0.2), 'vy': random.uniform(-0.2, 0.2),
|
|
33
|
+
'hue': random.uniform(0.5, 1.0),
|
|
34
|
+
'phase': random.uniform(0, 2*math.pi),
|
|
35
|
+
'size': random.uniform(0.3, 1.0),
|
|
36
|
+
})
|
|
37
|
+
_CN = {'crystals': crystals, 'floaters': floaters}
|
|
38
|
+
|
|
39
|
+
s = _CN
|
|
40
|
+
|
|
41
|
+
for y in range(h):
|
|
42
|
+
ty = y / h
|
|
43
|
+
for x in range(w):
|
|
44
|
+
dx = (x - cx) / (w * 0.4)
|
|
45
|
+
dy = (y - cy) / (h * 0.4)
|
|
46
|
+
d = math.hypot(dx, dy)
|
|
47
|
+
bg_val = 0.01 + 0.03 * (0.5 + 0.5 * math.sin(d * 2 - t * 0.1 + x * 0.01 + y * 0.01))
|
|
48
|
+
hue_bg = (0.7 + d * 0.05 + t * 0.002) % 1.0
|
|
49
|
+
c.set_pixel(x, y, ' ', bg=Color.from_hsv(hue_bg, 0.4, bg_val), z=-100)
|
|
50
|
+
|
|
51
|
+
nebula_bands = 4
|
|
52
|
+
for band in range(nebula_bands):
|
|
53
|
+
for y in range(h):
|
|
54
|
+
ty = y / h
|
|
55
|
+
for x in range(w):
|
|
56
|
+
dx = (x - cx) / (w * 0.35)
|
|
57
|
+
dy = (y - cy) / (h * 0.35)
|
|
58
|
+
d = math.hypot(dx, dy)
|
|
59
|
+
angle = math.atan2(dy, dx) + band * 1.5 + t * 0.05
|
|
60
|
+
n = math.sin(d * 1.5 + angle * 2 + t * 0.15 + band) * 0.5 + 0.5
|
|
61
|
+
n *= math.exp(-d * 1.2)
|
|
62
|
+
if n > 0.04:
|
|
63
|
+
hue = (0.65 + band * 0.07 + d * 0.06 + t * 0.003) % 1.0
|
|
64
|
+
bright = n * 0.5
|
|
65
|
+
c.set_pixel(x, y, '░', Color.from_hsv(hue, 0.7, bright), z=1)
|
|
66
|
+
|
|
67
|
+
c.set_pixel(0, 0, ' ', bg=Color(0, 0, 0), z=-100)
|
|
68
|
+
|
|
69
|
+
sorted_crystals = sorted(s['crystals'], key=lambda cr: cr['z'])
|
|
70
|
+
for cr in sorted_crystals:
|
|
71
|
+
cr['rot'] += cr['rot_speed'] * dt
|
|
72
|
+
sz = cr['size']
|
|
73
|
+
rot = cr['rot']
|
|
74
|
+
cx_cr, cy_cr = cr['x'], cr['y']
|
|
75
|
+
pulse = 0.8 + 0.2 * math.sin(t * 0.5 + cr['phase'])
|
|
76
|
+
sz_pulse = sz * pulse
|
|
77
|
+
|
|
78
|
+
def crystal_face(cx, cy, rot, sz, hue_base, offset, z_val):
|
|
79
|
+
points = []
|
|
80
|
+
for i in range(6):
|
|
81
|
+
a = rot + i * math.pi / 3 + offset
|
|
82
|
+
r = sz * (0.7 + 0.3 * math.sin(i * 2.5 + rot))
|
|
83
|
+
px = cx + r * math.cos(a)
|
|
84
|
+
py = cy + r * math.sin(a) * 0.5
|
|
85
|
+
points.append((px, py))
|
|
86
|
+
for i in range(len(points) - 1):
|
|
87
|
+
x1, y1 = points[i]
|
|
88
|
+
x2, y2 = points[i + 1]
|
|
89
|
+
segments = max(1, int(math.hypot(x2 - x1, y2 - y1)))
|
|
90
|
+
for s_i in range(segments + 1):
|
|
91
|
+
frac = s_i / segments
|
|
92
|
+
px = int(x1 + (x2 - x1) * frac)
|
|
93
|
+
py = int(y1 + (y2 - y1) * frac)
|
|
94
|
+
if 0 <= px < w and 0 <= py < h:
|
|
95
|
+
dist_from_center = math.hypot(px - cx, (py - cy) * 2) / max(1, sz)
|
|
96
|
+
glow = 1 - min(1, dist_from_center * 0.4)
|
|
97
|
+
hue = (hue_base + dist_from_center * 0.1 + t * 0.01 + offset) % 1.0
|
|
98
|
+
bright = min(1.0, pulse * (0.5 + 0.5 * glow) * (1 - dist_from_center * 0.1))
|
|
99
|
+
col = Color.from_hsv(hue, 0.6 + 0.4 * glow, bright)
|
|
100
|
+
ch = '░' if glow < 0.3 else ('▒' if glow < 0.6 else '▓')
|
|
101
|
+
c.set_pixel(px, py, ch, col, z=int(z_val))
|
|
102
|
+
|
|
103
|
+
crystal_face(cx_cr, cy_cr, rot, sz_pulse, cr['hue'], 0, 20)
|
|
104
|
+
crystal_face(cx_cr, cy_cr, rot + 0.3, sz_pulse * 0.85, cr['hue'] + 0.15, 0.5, 18)
|
|
105
|
+
crystal_face(cx_cr, cy_cr, rot - 0.3, sz_pulse * 0.7, cr['hue'] - 0.1, -0.5, 16)
|
|
106
|
+
|
|
107
|
+
glow_r = int(sz_pulse * 1.5)
|
|
108
|
+
for gx in range(-glow_r, glow_r + 1):
|
|
109
|
+
for gy2 in range(-glow_r, glow_r + 1):
|
|
110
|
+
gd = math.hypot(gx, gy2)
|
|
111
|
+
if gd <= glow_r:
|
|
112
|
+
px, py2 = int(cx_cr + gx), int(cy_cr + gy2)
|
|
113
|
+
if 0 <= px < w and 0 <= py2 < h:
|
|
114
|
+
a = 1 - gd / glow_r
|
|
115
|
+
hue = (cr['hue'] + a * 0.1 + t * 0.01) % 1.0
|
|
116
|
+
bright = pulse * a * 0.15
|
|
117
|
+
if bright > 0.02:
|
|
118
|
+
c.set_pixel(px, py2, ' ', bg=Color.from_hsv(hue, 0.4, bright), z=14)
|
|
119
|
+
|
|
120
|
+
for fl in s['floaters']:
|
|
121
|
+
fl['x'] += fl['vx'] * dt * 15 + math.sin(t * 0.3 + fl['phase']) * 0.1
|
|
122
|
+
fl['y'] += fl['vy'] * dt * 15 + math.cos(t * 0.2 + fl['phase'] * 1.3) * 0.1
|
|
123
|
+
fl['x'] = fl['x'] % w
|
|
124
|
+
fl['y'] = fl['y'] % h
|
|
125
|
+
px, py2 = int(fl['x']), int(fl['y'])
|
|
126
|
+
if 0 <= px < w and 0 <= py2 < h:
|
|
127
|
+
tw = 0.3 + 0.7 * (0.5 + 0.5 * math.sin(t * 0.8 + fl['phase']))
|
|
128
|
+
b = tw * fl['size'] * 0.5
|
|
129
|
+
if b > 0.05:
|
|
130
|
+
hue = (fl['hue'] + t * 0.005) % 1.0
|
|
131
|
+
col = Color.from_hsv(hue, 0.6, b)
|
|
132
|
+
ch = '·'
|
|
133
|
+
c.set_pixel(px, py2, ch, col, z=5)
|