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,444 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from spore_engine import (Canvas, Color, Gradient, HiResCanvas, LinearCanvas,
|
|
7
|
+
PerlinNoise, add_light, clamp, color_vec, gradient_lut,
|
|
8
|
+
monotonic, scene_state)
|
|
9
|
+
|
|
10
|
+
TAU = math.tau
|
|
11
|
+
|
|
12
|
+
# ---------------------------------------------------------------------------
|
|
13
|
+
# Palettes. The aurora ramp follows the real emission lines: N2+ violet along
|
|
14
|
+
# the lower fringe, 557.7nm atomic-oxygen green through the body of the
|
|
15
|
+
# curtain, thinning yellow-green, then 630nm oxygen red at the crown.
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
_SKY = Gradient(
|
|
19
|
+
Color(2, 3, 11),
|
|
20
|
+
Color(4, 6, 21),
|
|
21
|
+
Color(7, 12, 35),
|
|
22
|
+
Color(11, 19, 47),
|
|
23
|
+
Color(19, 32, 58),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
_AURORA = Gradient(
|
|
27
|
+
Color(134, 116, 255),
|
|
28
|
+
Color(80, 235, 240),
|
|
29
|
+
Color(80, 255, 150),
|
|
30
|
+
Color(140, 250, 120),
|
|
31
|
+
Color(255, 150, 130),
|
|
32
|
+
Color(255, 172, 112),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
_WATER = Color(5, 14, 25)
|
|
36
|
+
_CREST = Color(104, 152, 196)
|
|
37
|
+
_MOON = Color(255, 246, 228)
|
|
38
|
+
_MOON_PATH = Color(255, 232, 186)
|
|
39
|
+
_MIST = Color(120, 178, 202)
|
|
40
|
+
_AIRGLOW = Color(34, 104, 102)
|
|
41
|
+
_RIM_COOL = Color(88, 178, 162)
|
|
42
|
+
_RIM_MOON = Color(178, 206, 230)
|
|
43
|
+
_HULL = Color(11, 16, 30)
|
|
44
|
+
_GUNWALE = Color(122, 176, 182)
|
|
45
|
+
_LANTERN = Color(255, 186, 100)
|
|
46
|
+
_MOTES = (Color(255, 202, 124), Color(146, 222, 255))
|
|
47
|
+
|
|
48
|
+
#: lower edge, span, gain, drift, ray frequency, hue shift, envelope freq/phase
|
|
49
|
+
_LAYERS = (
|
|
50
|
+
(0.34, 0.46, 2.30, 0.050, 0.90, 0.00, 0.045, 0.0),
|
|
51
|
+
(0.16, 0.28, 1.35, 0.082, 1.45, -0.11, 0.075, 19.0),
|
|
52
|
+
(0.52, 0.62, 0.85, 0.028, 0.55, 0.07, 0.030, 37.0),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
#: A low layered shore, not a mountain range, and translucent as well as
|
|
56
|
+
#: feathered: at one sub-cell of vertical resolution a tall opaque silhouette
|
|
57
|
+
#: resolves into a staircase of blocks, while a thin receding shoreline reads
|
|
58
|
+
#: as distance and leaves the frame to the aurora.
|
|
59
|
+
#: colour, height fraction, fBm frequency, fBm phase, rim strength, opacity
|
|
60
|
+
_RIDGES = (
|
|
61
|
+
(Color(26, 34, 58), 0.070, 0.090, 11.3, 1.00, 0.72),
|
|
62
|
+
(Color(14, 20, 36), 0.028, 0.140, 27.1, 0.70, 0.54),
|
|
63
|
+
(Color(6, 9, 20), 0.012, 0.200, 41.5, 0.00, 0.36),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
_AURORA_LUT = gradient_lut(_AURORA)
|
|
68
|
+
_MOON_V = color_vec(_MOON)
|
|
69
|
+
_WATER_V = color_vec(_WATER)
|
|
70
|
+
_CREST_V = color_vec(_CREST)
|
|
71
|
+
_MOON_PATH_V = color_vec(_MOON_PATH)
|
|
72
|
+
_MIST_V = color_vec(_MIST)
|
|
73
|
+
_AIRGLOW_V = color_vec(_AIRGLOW)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _fbm_line(pn, w, freq, drift, off, octaves=3, gain=1.0):
|
|
77
|
+
"""A 1-D fBm trace across the frame, sampled through the engine's grid.
|
|
78
|
+
|
|
79
|
+
Every silhouette here wants a per-column fBm, and the frame needs seventeen
|
|
80
|
+
of them. Looping ``PerlinNoise.fbm1`` per column costs about 0.5ms each at
|
|
81
|
+
200 columns; the same trace through :meth:`PerlinNoise.fbm2d_grid` uses the
|
|
82
|
+
JIT-compiled kernel and costs about 0.03ms - a 14x saving on a quarter of
|
|
83
|
+
the frame budget - and falls back to plain Python when numba is absent.
|
|
84
|
+
"""
|
|
85
|
+
if freq == 0.0 or w < 1:
|
|
86
|
+
return np.full(max(1, w), 0.5 * gain, dtype=np.float32)
|
|
87
|
+
grid = pn.fbm2d_grid(w, 1, scale=freq, ox=(drift + off) / freq, oy=off * 0.37,
|
|
88
|
+
octaves=octaves)
|
|
89
|
+
return (grid[0] * 0.5 + 0.5).astype(np.float32) * gain
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _starfield(st):
|
|
93
|
+
"""A size-independent star field.
|
|
94
|
+
|
|
95
|
+
Every coordinate is a 0-1 fraction, so a later terminal resize rescales it
|
|
96
|
+
instead of indexing off the end of a list sized for the first frame.
|
|
97
|
+
"""
|
|
98
|
+
def build():
|
|
99
|
+
rnd = random.Random(0x5EED)
|
|
100
|
+
return [(rnd.random(), rnd.random() ** 1.4, rnd.random() * TAU,
|
|
101
|
+
rnd.random() ** 2.6, rnd.random() < 0.12) for _ in range(300)]
|
|
102
|
+
return st.get('stars', None, build)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _sky_field(w, hz, t, pn, st):
|
|
106
|
+
"""Composite the whole sky as linear RGB; return it with the moon."""
|
|
107
|
+
f32 = np.float32
|
|
108
|
+
yy = np.arange(hz, dtype=f32)[:, None]
|
|
109
|
+
xx = np.arange(w, dtype=f32)[None, :]
|
|
110
|
+
hgt = (hz - 1) - yy # height above the horizon
|
|
111
|
+
|
|
112
|
+
ramp = [_SKY.at(i / max(1, hz - 1)) for i in range(hz)]
|
|
113
|
+
sky = np.empty((hz, w, 3), dtype=f32)
|
|
114
|
+
for ch, key in enumerate(('r', 'g', 'b')):
|
|
115
|
+
sky[:, :, ch] = np.fromiter((getattr(c, key) for c in ramp),
|
|
116
|
+
dtype=f32, count=hz)[:, None]
|
|
117
|
+
|
|
118
|
+
mr = max(1.2, hz * 0.150)
|
|
119
|
+
mx = w * 0.68 + 1.4 * math.sin(t * 0.043)
|
|
120
|
+
my = hz * 0.40 + 0.9 * math.sin(t * 0.031 + 1.2)
|
|
121
|
+
|
|
122
|
+
# -- galactic band ------------------------------------------------------
|
|
123
|
+
band_c = hz * 0.30 + hz * 0.22 * np.sin(xx * 0.05 + 1.1)
|
|
124
|
+
band = np.exp(-(((yy - band_c) / (hz * 0.11)) ** 2))
|
|
125
|
+
grain = 0.5 + 0.5 * np.sin(xx * 2.4 + 1.7 * np.sin(xx * 0.9)) * np.sin(
|
|
126
|
+
yy * 3.2 + xx * 0.5 + 2.0)
|
|
127
|
+
sky += (band * grain * 15.0)[..., None] * np.array([0.55, 0.62, 1.0], dtype=f32)
|
|
128
|
+
|
|
129
|
+
# -- stars --------------------------------------------------------------
|
|
130
|
+
ys, xs = [], []
|
|
131
|
+
chan = ([], [], [])
|
|
132
|
+
for u, v, ph, bri, warm in _starfield(st):
|
|
133
|
+
tw = 0.5 + 0.5 * math.sin(t * 1.5 + ph * 5.0 + u * 37.0)
|
|
134
|
+
mag = tw * bri
|
|
135
|
+
if mag < 0.42:
|
|
136
|
+
continue
|
|
137
|
+
xi = int(u * w)
|
|
138
|
+
yi = int(min(v, 0.999) * hz)
|
|
139
|
+
if 0 <= xi < w and 0 <= yi < hz:
|
|
140
|
+
ys.append(yi)
|
|
141
|
+
xs.append(xi)
|
|
142
|
+
chan[0].append(mag * (150.0 if warm else 130.0))
|
|
143
|
+
chan[1].append(mag * 142.0)
|
|
144
|
+
chan[2].append(mag * (134.0 if warm else 170.0))
|
|
145
|
+
if ys:
|
|
146
|
+
ya = np.array(ys)
|
|
147
|
+
xa = np.array(xs)
|
|
148
|
+
for ch in range(3):
|
|
149
|
+
np.add.at(sky[:, :, ch], (ya, xa), np.array(chan[ch], dtype=f32))
|
|
150
|
+
|
|
151
|
+
# -- aurora curtains ----------------------------------------------------
|
|
152
|
+
phase = _fbm_line(pn, w, 0.11, 0.0, 40.0, 2, 5.0)
|
|
153
|
+
for base_f, span_f, gain, speed, freq, hue_ofs, env_f, env_o in _LAYERS:
|
|
154
|
+
jag = _fbm_line(pn, w, 0.019, t * speed, env_o, 3) - 0.5
|
|
155
|
+
base = hz * (base_f + 0.15 * jag)
|
|
156
|
+
# a contrasty per-column envelope is what turns a wash into curtains
|
|
157
|
+
env = np.clip(_fbm_line(pn, w, env_f, t * 0.025, env_o + 5.0, 3, 1.35), 0, 1.35) ** 1.70
|
|
158
|
+
p = (hgt - base[None, :]) / max(2.0, hz * span_f)
|
|
159
|
+
pc = np.clip(p, 0.0, 1.0)
|
|
160
|
+
win = np.clip(p / 0.12, 0.0, 1.0) * np.clip((1.0 - p) / 0.15, 0.0, 1.0)
|
|
161
|
+
prof = (1.0 - pc) ** 1.7
|
|
162
|
+
fringe = 0.60 * np.exp(-(((hgt - base[None, :]) / 2.4) ** 2))
|
|
163
|
+
stri = (0.5 + 0.5 * np.sin(xx * freq + phase[None, :] + t * 0.45 + pc * 3.0)) ** 2.0
|
|
164
|
+
stri = 0.20 + 0.80 * stri
|
|
165
|
+
stri *= 0.60 + 0.40 * np.sin(phase[None, :] * 1.7 + pc * 6.5 - t * 0.28)
|
|
166
|
+
# a second harmonic groups the rays irregularly instead of leaving one
|
|
167
|
+
# evenly spaced comb
|
|
168
|
+
stri *= 0.52 + 0.48 * (0.5 + 0.5 * np.sin(
|
|
169
|
+
xx * freq * 2.7 + phase[None, :] * 3.1 + t * 0.31 + pc * 1.7))
|
|
170
|
+
idx = np.clip((pc + hue_ofs) * 255.0, 0, 255).astype(np.int32)
|
|
171
|
+
sky += (((prof + fringe) * win * gain * stri * env)[..., None] * _AURORA_LUT[idx])
|
|
172
|
+
|
|
173
|
+
# -- moon, limb-darkened, with a two-lobe corona -----------------------
|
|
174
|
+
d = np.hypot(xx - mx, yy - my)
|
|
175
|
+
limb = 1.0 - 0.24 * np.clip(d / mr, 0, 1) ** 3
|
|
176
|
+
disc = np.clip((mr - d) / 1.8, 0, 1) * limb
|
|
177
|
+
halo = 0.30 * np.exp(-d / (mr * 2.2)) + 0.085 * np.exp(-d / (mr * 6.5))
|
|
178
|
+
sky += (disc * 1.00 + halo)[..., None] * _MOON_V
|
|
179
|
+
|
|
180
|
+
# -- airglow pooling along the horizon ---------------------------------
|
|
181
|
+
sky += (np.exp(-(((yy - (hz - 1) + hz * 0.13) / (hz * 0.13)) ** 2))[..., None]
|
|
182
|
+
* _AIRGLOW_V * 0.24)
|
|
183
|
+
|
|
184
|
+
# -- ridge silhouettes, far to near -------------------------------------
|
|
185
|
+
# The rim on each crest is driven by the aurora luminance immediately
|
|
186
|
+
# above it, so the edge glows exactly where a curtain passes behind the
|
|
187
|
+
# ridge and stays dark where the sky is empty.
|
|
188
|
+
luma = 0.299 * sky[:, :, 0] + 0.587 * sky[:, :, 1] + 0.114 * sky[:, :, 2]
|
|
189
|
+
xidx = np.arange(w, dtype=np.int32)
|
|
190
|
+
for col, hf, freq, off, rim_gain, opacity in _RIDGES:
|
|
191
|
+
# two octaves: a broad range plus fine crests. A single low-frequency
|
|
192
|
+
# trace is nearly flat across a terminal and reads as one black bar.
|
|
193
|
+
swell = _fbm_line(pn, w, freq, t * 0.06, off, 4, 1.0)
|
|
194
|
+
crest = _fbm_line(pn, w, freq * 3.7, t * 0.09, off + 13.0, 2, 1.0)
|
|
195
|
+
relief = np.clip(swell * 1.30 + crest * 0.38 - 0.30, 0.0, 1.45)
|
|
196
|
+
top = hz - 1.0 - hz * hf * relief
|
|
197
|
+
tint = np.clip(1.0 - (hz - 1.0 - top[None, :]) / (hz * 0.22), 0, 1)
|
|
198
|
+
# Feather the crest over ~2.5 sub-cells. A hard one-cell staircase is
|
|
199
|
+
# what makes a low-res silhouette read as pixel-art blocks.
|
|
200
|
+
soft = np.clip((yy - top[None, :]) / 2.4 + 0.5, 0, 1)
|
|
201
|
+
lit = soft * opacity * (0.88 + 0.12 * tint)
|
|
202
|
+
base_col = (col.r, col.g, col.b)
|
|
203
|
+
for ch in range(3):
|
|
204
|
+
sky[:, :, ch] = sky[:, :, ch] * (1.0 - lit) + base_col[ch] * lit
|
|
205
|
+
if rim_gain <= 0.0:
|
|
206
|
+
continue
|
|
207
|
+
behind = luma[np.clip(top, 0, hz - 1).astype(np.int32), xidx]
|
|
208
|
+
rmoon = np.exp(-(((xx - mx) / (w * 0.34 + 1.0)) ** 2))
|
|
209
|
+
peak = 0.45 + 0.55 * np.clip(
|
|
210
|
+
_fbm_line(pn, w, freq * 2.4, t * 0.09, off + 60.0, 2, 1.0), 0, 1)[None, :]
|
|
211
|
+
rimw = np.clip((behind[None, :] - 34.0) / 130.0, 0, 1)
|
|
212
|
+
rimw = rimw * (0.30 + 0.70 * rmoon) * peak * rim_gain
|
|
213
|
+
rim = (soft > 0.02) & (yy < top[None, :] + 1.2) & (rimw[None, :] > 0.05)
|
|
214
|
+
cool = (_RIM_COOL.r, _RIM_COOL.g, _RIM_COOL.b)
|
|
215
|
+
warm = (_RIM_MOON.r, _RIM_MOON.g, _RIM_MOON.b)
|
|
216
|
+
for ch in range(3):
|
|
217
|
+
# purely additive: blending toward `v` darkened the sky to a black
|
|
218
|
+
# block wherever the rim weight was small
|
|
219
|
+
sky[:, :, ch] = np.where(
|
|
220
|
+
rim, sky[:, :, ch] + (cool[ch] * 0.85 + warm[ch] * 0.45 * rmoon) * rimw,
|
|
221
|
+
sky[:, :, ch])
|
|
222
|
+
|
|
223
|
+
# -- ground mist drifting across the far shore -------------------------
|
|
224
|
+
mfog = np.clip(_fbm_line(pn, w, 0.035, t * 0.09, 61.0, 3, 1.0), 0, 1) ** 1.4
|
|
225
|
+
wob = 0.55 + 0.45 * np.sin(xx * 0.11 + t * 0.5 + yy * 0.35)
|
|
226
|
+
band = np.clip(1.0 - hgt / max(1.0, hz * 0.15), 0, 1) ** 1.5
|
|
227
|
+
sky += (band * mfog[None, :] * wob * 0.55)[..., None] * _MIST_V
|
|
228
|
+
|
|
229
|
+
return sky, (mx, my, mr)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _water_field(w, hz, max_d, sky, moon, t, pn, st):
|
|
233
|
+
"""Mirror the sky about the horizon and turn it into water."""
|
|
234
|
+
f32 = np.float32
|
|
235
|
+
mx, my, mr = moon
|
|
236
|
+
d = np.arange(1, max_d + 1, dtype=f32)[:, None]
|
|
237
|
+
xx = np.arange(w, dtype=f32)[None, :]
|
|
238
|
+
dn = d / max_d
|
|
239
|
+
|
|
240
|
+
ph1 = xx * 0.33 + d * 0.29 + t * 1.85
|
|
241
|
+
wave = (1.05 * np.sin(ph1)
|
|
242
|
+
+ 0.58 * np.sin(xx * 0.112 - d * 0.10 + t * 1.03)
|
|
243
|
+
+ 0.33 * np.sin(xx * 0.71 + d * 0.55 - t * 2.55)
|
|
244
|
+
+ 0.19 * np.sin(xx * 1.31 + d * 0.97 + t * 3.65))
|
|
245
|
+
amp = 0.22 + 0.78 * dn
|
|
246
|
+
src = hz - (d * 0.78 + 0.011 * d * d) + wave * amp
|
|
247
|
+
syi = np.clip(src, 0, hz - 1).astype(np.int32)
|
|
248
|
+
ref = sky[syi, np.arange(w, dtype=np.int32)[None, :]]
|
|
249
|
+
|
|
250
|
+
absorb = 0.22 + 0.72 * dn
|
|
251
|
+
body = ref * (1.0 - 0.48 * absorb)[..., None] + _WATER_V * (0.48 * absorb)[..., None]
|
|
252
|
+
|
|
253
|
+
# Only the very top of the dominant wave lights a crest; thresholding the
|
|
254
|
+
# raw sum saturated most of the surface and turned the lake into a bar code.
|
|
255
|
+
crest = np.clip((np.sin(ph1) * amp - 0.72) / 0.28, 0, 1) ** 1.3
|
|
256
|
+
body += crest[..., None] * _CREST_V * (0.22 - 0.12 * dn)[..., None]
|
|
257
|
+
|
|
258
|
+
# the moon lays a glitter path that widens as it comes toward the viewer
|
|
259
|
+
d0 = my * 0.78 + 0.011 * my * my
|
|
260
|
+
along = np.exp(-(((d - d0) / (max_d * 0.30 + 1.0)) ** 2))
|
|
261
|
+
across = np.exp(-(((xx - mx) / (mr * 0.9 + d * 0.50)) ** 2))
|
|
262
|
+
spk = (0.5 + 0.5 * np.sin(xx * 1.9 + d * 1.25
|
|
263
|
+
+ 2.4 * np.sin(d * 0.35 - t * 0.9) - t * 3.3)) ** 5
|
|
264
|
+
mod = 0.45 + 0.55 * (0.5 + 0.5 * np.sin(d * 0.8 + xx * 0.06 + t * 1.1))
|
|
265
|
+
body += (along * across * spk * mod * 1.5)[..., None] * _MOON_PATH_V
|
|
266
|
+
|
|
267
|
+
mfog = np.clip(_fbm_line(pn, w, 0.035, t * 0.09, 61.0, 3, 1.0), 0, 1) ** 1.4
|
|
268
|
+
body += (np.clip(1.0 - d / 4.5, 0, 1) ** 1.4 * mfog[None, :] * 0.45)[..., None] * _MIST_V
|
|
269
|
+
|
|
270
|
+
_moored_boat(body, w, hz, max_d, t)
|
|
271
|
+
return body
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _moored_boat(body, w, hz, max_d, t):
|
|
275
|
+
"""A small moored boat, lantern lit, trailing a broken reflection.
|
|
276
|
+
|
|
277
|
+
Deliberately horizontal, and only one of them: a narrow vertical silhouette
|
|
278
|
+
is a dark smudge at sub-cell resolution, and two hulls read as clutter
|
|
279
|
+
rather than depth. The lantern is the only warm light in a cold frame, so it
|
|
280
|
+
carries the focal point and its streak anchors the composition.
|
|
281
|
+
"""
|
|
282
|
+
f32 = np.float32
|
|
283
|
+
rows = body.shape[0]
|
|
284
|
+
xf = np.arange(w, dtype=f32)
|
|
285
|
+
hull_v = color_vec(_HULL)
|
|
286
|
+
gunw_v = color_vec(_GUNWALE)
|
|
287
|
+
flame_v = color_vec(_LANTERN)
|
|
288
|
+
|
|
289
|
+
persp = 0.70
|
|
290
|
+
u = 0.32 + 0.010 * math.sin(t * 0.05)
|
|
291
|
+
by = int(2.0 + persp * (max_d - 6.0))
|
|
292
|
+
if not 0.08 <= u < 0.92 or by >= rows - 3 or by < 5:
|
|
293
|
+
return
|
|
294
|
+
cx = int(u * (w - 1))
|
|
295
|
+
bw = 2.4 + persp * 3.4
|
|
296
|
+
rock = 0.35 * math.sin(t * 0.5)
|
|
297
|
+
|
|
298
|
+
# A three-row trapezoid alone reads as a bar; the mast is what makes the
|
|
299
|
+
# silhouette resolve as a boat.
|
|
300
|
+
for k in range(3):
|
|
301
|
+
row = by - k
|
|
302
|
+
hw = bw * (0.50 + 0.34 * k)
|
|
303
|
+
a0 = max(0, int(cx - hw + rock * k))
|
|
304
|
+
a1 = min(w, int(cx + hw + rock * k) + 1)
|
|
305
|
+
if a0 >= a1:
|
|
306
|
+
continue
|
|
307
|
+
body[row, a0:a1] = hull_v * (0.85 + 0.25 * k)
|
|
308
|
+
if k == 2: # gunwale catches light
|
|
309
|
+
g0, g1 = a0 + 1, a1 - 1
|
|
310
|
+
if g0 < g1:
|
|
311
|
+
body[row, g0:g1] = gunw_v * 0.72
|
|
312
|
+
|
|
313
|
+
for k in (1, 2):
|
|
314
|
+
row = by - 2 - k
|
|
315
|
+
if 0 <= row < rows:
|
|
316
|
+
body[row, cx] = hull_v * (1.0 + 0.2 * k)
|
|
317
|
+
|
|
318
|
+
ly = by - 5
|
|
319
|
+
body[ly, cx] = flame_v
|
|
320
|
+
body[ly, max(0, cx - 1):cx + 2] += flame_v * 0.42
|
|
321
|
+
body[ly, max(0, cx - 2):cx + 3] += flame_v * 0.15
|
|
322
|
+
if ly - 1 >= 0:
|
|
323
|
+
body[ly - 1, cx] = flame_v * 0.45
|
|
324
|
+
for gy in range(1, 4): # warm pool on the water
|
|
325
|
+
gyy = by - gy
|
|
326
|
+
if 0 <= gyy < rows:
|
|
327
|
+
g0, g1 = max(0, cx - gy - 1), min(w, cx + gy + 2)
|
|
328
|
+
if g0 < g1:
|
|
329
|
+
body[gyy, g0:g1] += flame_v * (0.20 / (gy + 1))
|
|
330
|
+
|
|
331
|
+
length = int(6.0 + persp * 14.0)
|
|
332
|
+
for dy in range(1, length + 1):
|
|
333
|
+
y = by + dy
|
|
334
|
+
if y >= rows:
|
|
335
|
+
break
|
|
336
|
+
fade = 1.0 - dy / (length + 1.0)
|
|
337
|
+
wob = math.sin(dy * 0.8 + t * 1.9) * (0.6 + 1.3 * dy / (length + 1.0))
|
|
338
|
+
a = fade * fade * (0.22 + 0.78 * (0.5 + 0.5 * np.sin(
|
|
339
|
+
xf * 1.6 + dy * 2.3 - t * 2.7)))
|
|
340
|
+
ox = int(wob + (0.5 if wob >= 0 else -0.5))
|
|
341
|
+
half = max(1, int(bw * (0.5 + 0.5 * dy / length)))
|
|
342
|
+
s0, s1 = max(0, cx - half + ox), min(w, cx + half + ox + 1)
|
|
343
|
+
if s0 < s1:
|
|
344
|
+
body[y, s0:s1] += flame_v * (a[s0:s1] * 0.75)[..., None]
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _grade(lc):
|
|
348
|
+
"""Highlight rolloff, a tight bloom and a vignette, in place.
|
|
349
|
+
|
|
350
|
+
The stages are the engine's; the numbers are this scene's. The bloom
|
|
351
|
+
threshold sits high (205 of 255) because this is a daylight-ish frame where
|
|
352
|
+
only the moon, the crest highlights and the lantern should carry a halo -
|
|
353
|
+
a low threshold would fog the whole sky, which is the correct setting for
|
|
354
|
+
the dark bioluminescent scene next to it and the wrong one here.
|
|
355
|
+
"""
|
|
356
|
+
lc.tonemap(knee=172.0)
|
|
357
|
+
lc.bloom(threshold=205.0, span=50.0, radii=(1, 3), weights=(0.62, 0.30),
|
|
358
|
+
tint=(1.0, 0.96, 0.90), gain=52.0)
|
|
359
|
+
lc.vignette(gain=0.52, exponent=2.2, radius=0.72)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def _motes(hr, w, hz, t, st):
|
|
363
|
+
"""Drifting lights over the lagoon, each with a wobbling reflection."""
|
|
364
|
+
now = monotonic()
|
|
365
|
+
last = st.get('mote_clock')
|
|
366
|
+
st.mote_clock = now
|
|
367
|
+
fps = st.get('fps')
|
|
368
|
+
if last is not None and 0.0 < now - last < 0.5:
|
|
369
|
+
inst = 1.0 / (now - last)
|
|
370
|
+
st.fps = inst if fps is None else fps * 0.88 + inst * 0.12
|
|
371
|
+
|
|
372
|
+
def build():
|
|
373
|
+
rnd = random.Random(0xF1A3)
|
|
374
|
+
return [(rnd.random(), rnd.random() ** 1.6, rnd.random() * TAU,
|
|
375
|
+
rnd.uniform(0.004, 0.015), rnd.random() < 0.34) for _ in range(64)]
|
|
376
|
+
|
|
377
|
+
for u, v, ph, spd, warm in st.get('motes', None, build):
|
|
378
|
+
tw = 0.5 + 0.5 * math.sin(t * 1.7 + ph * 3.0)
|
|
379
|
+
if tw < 0.22:
|
|
380
|
+
continue
|
|
381
|
+
col = _MOTES[1 if warm else 0]
|
|
382
|
+
gain = 0.30 + 0.80 * tw
|
|
383
|
+
x = int(((u + t * spd) % 1.0) * (w - 1))
|
|
384
|
+
y = int(hz - 1.0 - (v + 0.020 * math.sin(t * 0.7 + ph)) * (hz - 1))
|
|
385
|
+
if not 0 <= y < hr.h:
|
|
386
|
+
continue
|
|
387
|
+
add_light(hr, x, y, col.r * gain, col.g * gain, col.b * gain, 40)
|
|
388
|
+
halo = gain * 0.16
|
|
389
|
+
for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
|
|
390
|
+
add_light(hr, x + dx, y + dy, col.r * halo, col.g * halo, col.b * halo, 40)
|
|
391
|
+
ry = int(hz + (hz - 1.0 - y) * 0.52)
|
|
392
|
+
if 0 <= ry < hr.h:
|
|
393
|
+
rx = x + int(1.2 * math.sin(t * 1.3 + ph * 5.0 + ry * 0.4))
|
|
394
|
+
rg = gain * 0.20
|
|
395
|
+
add_light(hr, rx, ry, col.r * rg, col.g * rg, col.b * rg, 38)
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def _hud(c, t, st):
|
|
399
|
+
"""Title, thesis, and a live readout of the incremental renderer."""
|
|
400
|
+
c.draw_text(2, 0, '✦ Aurora Lagoon ✦',
|
|
401
|
+
Color.from_hsv(0.50 + 0.05 * math.sin(t * 0.06), 0.42, 1.0), z=100)
|
|
402
|
+
c.draw_text(2, c.h - 1,
|
|
403
|
+
'fbm aurora | mirror water | lantern-lit boat | per-pixel bloom',
|
|
404
|
+
Color(70, 90, 118), z=100)
|
|
405
|
+
|
|
406
|
+
stats = c.render_stats
|
|
407
|
+
if stats is None:
|
|
408
|
+
return
|
|
409
|
+
fps = st.get('fps')
|
|
410
|
+
rate = f'{fps:5.0f} fps' if fps else ' -- fps'
|
|
411
|
+
note = 'full redraw' if stats['full'] else f'{stats["cells"]} cells'
|
|
412
|
+
c.draw_text_at(3, 0, f'{rate} · {note} · {stats["bytes"] / 1024:.1f} KiB/f',
|
|
413
|
+
Color(70, 92, 124), z=100, anchor='ne')
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def scene_aurora_lagoon(c: Canvas, hr: HiResCanvas, t: float, pt, dt: float):
|
|
417
|
+
"""Aurora Lagoon - obsidian water mirroring an fBm aurora and a low moon."""
|
|
418
|
+
w, h = hr.w, hr.h
|
|
419
|
+
st = scene_state('aurora_lagoon')
|
|
420
|
+
pn = st.get('noise', None, lambda: PerlinNoise(0xA07A))
|
|
421
|
+
|
|
422
|
+
hz = clamp(int(h * 0.52), 3, h - 3)
|
|
423
|
+
max_d = h - hz
|
|
424
|
+
if max_d < 2:
|
|
425
|
+
for y in range(h):
|
|
426
|
+
g = _SKY.at(y / max(1, h - 1))
|
|
427
|
+
for x in range(w):
|
|
428
|
+
hr.buffer[y][x].fg = g
|
|
429
|
+
return
|
|
430
|
+
|
|
431
|
+
sky, moon = _sky_field(w, hz, t, pn, st)
|
|
432
|
+
lc = LinearCanvas(w, h)
|
|
433
|
+
frame = lc.data
|
|
434
|
+
frame[:hz] = sky
|
|
435
|
+
frame[hz:] = _water_field(w, hz, max_d, sky, moon, t, pn, st)
|
|
436
|
+
_grade(lc)
|
|
437
|
+
# Keep the returned cache: dropping it rebuilds it every frame, and the
|
|
438
|
+
# Color reuse is worth more than the rest of the frame combined.
|
|
439
|
+
st['keys'], st['objs'] = lc.to_hires(hr, prev=st.get('keys', None),
|
|
440
|
+
objs=st.get('objs', None))
|
|
441
|
+
_motes(hr, w, hz, t, st)
|
|
442
|
+
|
|
443
|
+
hr.to_canvas(c)
|
|
444
|
+
_hud(c, t, st)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import math, random
|
|
2
|
+
from spore_engine import *
|
|
3
|
+
from spore_engine.core.color import *
|
|
4
|
+
|
|
5
|
+
_AI = None
|
|
6
|
+
|
|
7
|
+
def scene_aurora_palace(c, hr, t, pt, dt):
|
|
8
|
+
global _AI
|
|
9
|
+
w, h = c.w, c.h
|
|
10
|
+
|
|
11
|
+
if _AI is None:
|
|
12
|
+
snowflakes = []
|
|
13
|
+
for _ in range(40):
|
|
14
|
+
snowflakes.append({
|
|
15
|
+
'x': random.uniform(0, w), 'y': random.uniform(0, h),
|
|
16
|
+
'vx': random.uniform(-0.2, 0.2), 'vy': random.uniform(0.3, 0.8),
|
|
17
|
+
'size': random.randint(0, 1),
|
|
18
|
+
'phase': random.uniform(0, 2*math.pi),
|
|
19
|
+
})
|
|
20
|
+
_AI = {'snowflakes': snowflakes}
|
|
21
|
+
|
|
22
|
+
s = _AI
|
|
23
|
+
|
|
24
|
+
for y in range(h):
|
|
25
|
+
ty = y / h
|
|
26
|
+
hue = 0.7 - ty * 0.05
|
|
27
|
+
sat = 0.2 + ty * 0.2
|
|
28
|
+
bright = 0.02 + ty * 0.08
|
|
29
|
+
col = Color.from_hsv(hue % 1.0, sat, bright)
|
|
30
|
+
for x in range(w):
|
|
31
|
+
c.set_pixel(x, y, ' ', bg=col, z=-100)
|
|
32
|
+
|
|
33
|
+
for y in range(int(h*0.05), int(h*0.35)):
|
|
34
|
+
for x in range(w):
|
|
35
|
+
offset = y * 0.05 + x * 0.02
|
|
36
|
+
aurora = math.sin(offset + t * 0.3) * 0.5 + 0.5
|
|
37
|
+
aurora2 = math.sin(offset * 1.5 + t * 0.5) * 0.5 + 0.5
|
|
38
|
+
aurora3 = math.sin(offset * 0.7 + t * 0.2 + 1.5) * 0.5 + 0.5
|
|
39
|
+
val = aurora * 0.5 + aurora2 * 0.3 + aurora3 * 0.2
|
|
40
|
+
if val > 0.4:
|
|
41
|
+
hue = 0.65 + val * 0.15
|
|
42
|
+
ch = ' ' if val < 0.5 else ('░' if val < 0.6 else ('▒' if val < 0.75 else '▓'))
|
|
43
|
+
c.set_pixel(x, y, ch, Color.from_hsv(hue % 1.0, 0.6, 0.1+val*0.5), z=3)
|
|
44
|
+
|
|
45
|
+
stars_set = set()
|
|
46
|
+
for _ in range(30):
|
|
47
|
+
sx = random.randint(0, w-1)
|
|
48
|
+
sy = random.randint(0, int(h*0.3)-1)
|
|
49
|
+
if random.random() < 0.7:
|
|
50
|
+
pulse = 0.5 + 0.5 * math.sin(t*1.5 + sx*3 + sy*7)
|
|
51
|
+
c.set_pixel(sx, sy, '·', Color(200, 210, 255).mul(pulse*0.5), z=2)
|
|
52
|
+
|
|
53
|
+
palace_cx = w // 2
|
|
54
|
+
palace_base = h - 1
|
|
55
|
+
center_tower_h = int(h * 0.4)
|
|
56
|
+
side_towers = [(int(w*0.3), int(h*0.25)), (int(w*0.7), int(h*0.25))]
|
|
57
|
+
center_w = 8
|
|
58
|
+
|
|
59
|
+
for tower_x, tower_h in [(palace_cx, center_tower_h), side_towers[0], side_towers[1]]:
|
|
60
|
+
tw = 5 if tower_x == palace_cx else 4
|
|
61
|
+
for y in range(palace_base - tower_h, palace_base + 1):
|
|
62
|
+
ty = (y - (palace_base - tower_h)) / max(1, tower_h)
|
|
63
|
+
for x in range(tower_x - tw, tower_x + tw + 1):
|
|
64
|
+
if 0 <= x < w and 0 <= y < h:
|
|
65
|
+
if y == palace_base - tower_h:
|
|
66
|
+
if tower_x == palace_cx:
|
|
67
|
+
c.set_pixel(x, y, '▲', Color(120, 140, 180).mul(1-ty*0.3), z=8)
|
|
68
|
+
else:
|
|
69
|
+
c.set_pixel(x, y, '▲', Color(100, 120, 160).mul(1-ty*0.3), z=8)
|
|
70
|
+
elif x == tower_x - tw or x == tower_x + tw or abs(x - tower_x) <= 1:
|
|
71
|
+
col = Color(int(80+ty*40), int(100+ty*50), int(140+ty*60)).mul(1-ty*0.2)
|
|
72
|
+
c.set_pixel(x, y, '║', col, z=8)
|
|
73
|
+
else:
|
|
74
|
+
col = Color(int(50+ty*30), int(70+ty*40), int(100+ty*50)).mul(1-ty*0.3)
|
|
75
|
+
c.set_pixel(x, y, '█', col, z=8)
|
|
76
|
+
|
|
77
|
+
for tower_x, tower_h in [(palace_cx, center_tower_h), side_towers[0], side_towers[1]]:
|
|
78
|
+
tw = 5 if tower_x == palace_cx else 4
|
|
79
|
+
for wy in range(palace_base - tower_h + 3, palace_base - 1, random.randint(4, 7)):
|
|
80
|
+
for wx in range(tower_x - tw + 2, tower_x + tw - 1, 3):
|
|
81
|
+
if 0 <= wx < w and wy < h:
|
|
82
|
+
glow = 0.5 + 0.5 * math.sin(t*0.7 + wx*1.5 + wy*2.3)
|
|
83
|
+
col = Color.from_hsv(0.12, 0.8, 0.3+0.7*glow)
|
|
84
|
+
c.set_pixel(wx, wy, '█', col, z=10)
|
|
85
|
+
if glow > 0.6:
|
|
86
|
+
for ddx, ddy in [(-1,0),(1,0),(0,-1),(0,1)]:
|
|
87
|
+
if 0 <= wx+ddx < w and 0 <= wy+ddy < h:
|
|
88
|
+
c.set_pixel(wx+ddx, wy+ddy, '·', col.mul(0.3), z=9)
|
|
89
|
+
|
|
90
|
+
for x in range(w):
|
|
91
|
+
for y in range(palace_base-2, palace_base+1):
|
|
92
|
+
if 0 <= y < h:
|
|
93
|
+
c.set_pixel(x, y, '█', Color(30, 40, 60), z=6)
|
|
94
|
+
|
|
95
|
+
for flake in s['snowflakes']:
|
|
96
|
+
flake['x'] += flake['vx'] * dt * 8 + math.sin(t*0.5+flake['phase'])*0.3
|
|
97
|
+
flake['y'] += flake['vy'] * dt * 10
|
|
98
|
+
if flake['y'] > h+2:
|
|
99
|
+
flake['y'] = -2
|
|
100
|
+
flake['x'] = random.uniform(0, w)
|
|
101
|
+
px, py = int(flake['x']), int(flake['y'])
|
|
102
|
+
if 0 <= px < w and 0 <= py < h:
|
|
103
|
+
c.set_pixel(px, py, '·' if flake['size'] == 0 else '°', Color(200, 220, 255).mul(0.5+0.5*random.random()), z=15)
|
|
104
|
+
|
|
105
|
+
if 0 <= palace_cx < w and 0 <= palace_base - center_tower_h - 5 < h:
|
|
106
|
+
c.set_pixel(palace_cx, palace_base - center_tower_h - 5, '●', Color(255, 220, 180).mul(0.6+0.4*math.sin(t)), z=12)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import math, random
|
|
2
|
+
from spore_engine import *
|
|
3
|
+
from spore_engine.core.color import *
|
|
4
|
+
|
|
5
|
+
_AS = None
|
|
6
|
+
|
|
7
|
+
def scene_aurora_storm(c, hr, t, pt, dt):
|
|
8
|
+
global _AS
|
|
9
|
+
w, h = c.w, c.h
|
|
10
|
+
|
|
11
|
+
if _AS is None:
|
|
12
|
+
freqs = []
|
|
13
|
+
for _ in range(12):
|
|
14
|
+
freqs.append({
|
|
15
|
+
'freq_x': random.uniform(0.005, 0.025),
|
|
16
|
+
'freq_y': random.uniform(0.01, 0.04),
|
|
17
|
+
'freq_t': random.uniform(0.02, 0.08),
|
|
18
|
+
'phase': random.uniform(0, 2*math.pi),
|
|
19
|
+
'amp': random.uniform(0.3, 1.0),
|
|
20
|
+
'hue': random.uniform(0.6, 0.9),
|
|
21
|
+
'speed': random.uniform(0.3, 1.5),
|
|
22
|
+
})
|
|
23
|
+
columns = []
|
|
24
|
+
for _ in range(20):
|
|
25
|
+
columns.append({
|
|
26
|
+
'x': random.uniform(0, w),
|
|
27
|
+
'width': random.uniform(2, 8),
|
|
28
|
+
'hue': random.uniform(0.65, 0.85),
|
|
29
|
+
'phase': random.uniform(0, 2*math.pi),
|
|
30
|
+
'pulse_speed': random.uniform(0.3, 1.0),
|
|
31
|
+
})
|
|
32
|
+
spikes = []
|
|
33
|
+
for _ in range(40):
|
|
34
|
+
spikes.append({
|
|
35
|
+
'x': random.uniform(0, w),
|
|
36
|
+
'hue': random.uniform(0.0, 0.15),
|
|
37
|
+
'phase': random.uniform(0, 2*math.pi),
|
|
38
|
+
'height': random.uniform(0.1, 0.4),
|
|
39
|
+
})
|
|
40
|
+
_AS = {'freqs': freqs, 'columns': columns, 'spikes': spikes}
|
|
41
|
+
|
|
42
|
+
s = _AS
|
|
43
|
+
|
|
44
|
+
for y in range(h):
|
|
45
|
+
ty = y / h
|
|
46
|
+
col = Color(int(2 + ty * 8), int(ty * 6), int(5 + ty * 20))
|
|
47
|
+
for x in range(w):
|
|
48
|
+
c.set_pixel(x, y, ' ', bg=col, z=-100)
|
|
49
|
+
|
|
50
|
+
aurora_h = int(h * 0.55)
|
|
51
|
+
for y in range(aurora_h):
|
|
52
|
+
gy = int(h * 0.02 + y * 0.6)
|
|
53
|
+
if gy >= h: continue
|
|
54
|
+
ty = y / aurora_h
|
|
55
|
+
falloff = math.sin(ty * math.pi)
|
|
56
|
+
for x in range(w):
|
|
57
|
+
val = 0
|
|
58
|
+
for f in s['freqs']:
|
|
59
|
+
n = math.sin(x * f['freq_x'] + gy * f['freq_y'] + t * f['freq_t'] + f['phase'])
|
|
60
|
+
n += math.sin(x * f['freq_x'] * 2.3 + gy * f['freq_y'] * 1.7 - t * f['freq_t'] * 0.7 + f['phase'] * 1.3)
|
|
61
|
+
val += n * f['amp'] * 0.3
|
|
62
|
+
val = val / len(s['freqs']) * 0.5 + 0.5
|
|
63
|
+
val = min(1.0, val * 1.8)
|
|
64
|
+
val *= falloff
|
|
65
|
+
|
|
66
|
+
if val > 0.08:
|
|
67
|
+
for f in s['freqs']:
|
|
68
|
+
if f['amp'] > 0.7:
|
|
69
|
+
hue = f['hue'] + ty * 0.1 + val * 0.08 + t * 0.005
|
|
70
|
+
break
|
|
71
|
+
else:
|
|
72
|
+
hue = 0.7 + ty * 0.15 + val * 0.05 + t * 0.003
|
|
73
|
+
hue = hue % 1.0
|
|
74
|
+
bright = 0.15 + val * 0.7
|
|
75
|
+
ch = '░' if val < 0.25 else ('▒' if val < 0.45 else ('▓' if val < 0.7 else '█'))
|
|
76
|
+
c.set_pixel(x, gy, ch, Color.from_hsv(hue, 0.75, bright), z=10)
|
|
77
|
+
|
|
78
|
+
for col in s['columns']:
|
|
79
|
+
col_pulse = 0.5 + 0.5 * math.sin(t * col['pulse_speed'] + col['phase'])
|
|
80
|
+
if col_pulse < 0.3: continue
|
|
81
|
+
col_width = int(col['width'] * (0.5 + 0.5 * col_pulse))
|
|
82
|
+
for xx in range(int(col['x']) - col_width, int(col['x']) + col_width + 1):
|
|
83
|
+
if 0 <= xx < w:
|
|
84
|
+
dist = abs(xx - col['x']) / max(1, col_width)
|
|
85
|
+
for yy in range(int(h * 0.1), int(h * 0.55)):
|
|
86
|
+
gy = int(h * 0.02 + (yy / (h * 0.45)) * 0.6 * h * 0.55)
|
|
87
|
+
gy = min(gy, h - 1)
|
|
88
|
+
ty = (yy - int(h * 0.1)) / max(1, int(h * 0.45))
|
|
89
|
+
falloff = math.sin(ty * math.pi) * (1 - dist * 0.6)
|
|
90
|
+
if falloff < 0.1: continue
|
|
91
|
+
flicker = 0.7 + 0.3 * math.sin(t * 3 + xx * 2 + gy * 1.5 + col['phase'])
|
|
92
|
+
bright = min(1.0, col_pulse * falloff * flicker * 0.8)
|
|
93
|
+
if bright > 0.1:
|
|
94
|
+
hue = (col['hue'] + ty * 0.05 + t * 0.01) % 1.0
|
|
95
|
+
ch = '░' if bright < 0.3 else ('▒' if bright < 0.5 else '▓')
|
|
96
|
+
c.set_pixel(xx, gy, ch, Color.from_hsv(hue, 0.8, bright), z=12)
|
|
97
|
+
|
|
98
|
+
for sp in s['spikes']:
|
|
99
|
+
sp_pulse = 0.3 + 0.7 * (0.5 + 0.5 * math.sin(t * 1.2 + sp['phase']))
|
|
100
|
+
height = int(h * sp['height'] * sp_pulse)
|
|
101
|
+
base_x = int(sp['x'])
|
|
102
|
+
for yy in range(height):
|
|
103
|
+
gy = int(h * 0.05 + yy * 0.6)
|
|
104
|
+
if gy >= h: break
|
|
105
|
+
ty = yy / height
|
|
106
|
+
width = max(1, int(3 * (1 - ty * 0.7)))
|
|
107
|
+
for xx in range(base_x - width, base_x + width + 1):
|
|
108
|
+
if 0 <= xx < w:
|
|
109
|
+
d = abs(xx - base_x) / max(1, width)
|
|
110
|
+
flicker = 0.6 + 0.4 * math.sin(t * 5 + xx * 3 + yy + sp['phase'])
|
|
111
|
+
bright = sp_pulse * (1 - ty * 0.5) * (1 - d * 0.5) * flicker
|
|
112
|
+
if bright > 0.15:
|
|
113
|
+
hue = (sp['hue'] + ty * 0.06 + t * 0.02) % 1.0
|
|
114
|
+
ch = '│' if width < 2 else ('░' if ty > 0.6 else '▒')
|
|
115
|
+
c.set_pixel(xx, gy, ch, Color.from_hsv(hue, 0.9, bright), z=15)
|