sourceextensions/scene/demos/voxels-light.xtl

1⍝│ Voxels, 14: light. The endless world, lit: a face open to the sky is 2⍝│ in full sunlight; under an overhang, beneath a tree's crown or down a 3⍝│ tunnel the light fades, a step a block, as it spreads from the open 4⍝│ air. A lamp (the hotbar's eighth block) glows: its light spreads the 5⍝│ same way through the air around it. N turns day to night and back -- 6⍝│ the sunlight and the sky go, the lamps stay -- by one number in scene, 7⍝│ so nothing is worked out again. Each column's light is worked out as 8⍝│ it is made (vx:c_olumnLight: sunlight by a scan down each column, 9⍝│ then rounds of spreading), and again when an edit makes it again: dig 10⍝│ a tunnel's roof open and the sun comes in. 11⍝│ Run: just demo scene voxels-light 12⍝│ click (or X) dig, right-click (or E) place, 1 to 8 choose the block 13⍝│ (8 a lamp), N night or day, W A S D walk, Space jump, Shift run, F 14⍝│ fly, drag or the arrows to look, H back to the start, q quit 15 16"en:" u̲se< "Endless" 17"pl:" u̲se< "Play" 18"sc:" u̲se< "Scene" 19 20w ← "Voxels 14: light -- X_eTaL" ˢᶜo̲pen! 640 400 21g ← w ˢᶜf̲og! 22.0 44.0 22_ ← w ˢᶜs̲ky! 0.55 0.72 0.92 23_ ← w ˢᶜc̲urve! 160.0 24 25ᵖˡhelpLit 26 27⍝━━ The light, checked 28 29⍝│ Stone, 18 by 32 by 18 (a column with its border), with a shaft open to 30⍝│ the sky at x 4, z 9 down to y 10, a tunnel at y 10 from it east to x 31⍝│ 15, and a lamp at the tunnel's end (x 16). Along the tunnel the 32⍝│ sunlight falls 3 a block from the shaft's 15; the lamplight falls 3 a 33⍝│ block back from the lamp. 34"vx:" u̲se< "Voxels" 35cell ← (r̲ange 18 × 32 × 18) − 1 36x ← cell d̲iv 32 × 18 37y ← (cell d̲iv 18) m̲od 32 38z ← cell m̲od 18 39shaft ← (x = 4) × (z = 9) × y ≥ 10 40tunnel ← (y = 10) × (z = 9) × (x ≥ 4) × x ≤ 15 41lamp ← (y = 10) × (z = 9) × x = 16 42b ← 18 32 18 r̲eshape (8 × lamp) + (1 − lamp) × 1 − 0 < shaft + tunnel 43ᵘs̲unOf ← { (sun, _) → sun } 44ᵘl̲ampOf ← { (_, lamp) → lamp } 45L ← ᵛˣc̲olumnLight b 46row ← 1 + tunnel r̲eplicate cell 47"sunlight along the tunnel, x 4 to 15:" 48row s̲elect r̲avel ᵘs̲unOf L 49"lamplight along it, the lamp at x 16:" 50row s̲elect r̲avel ᵘl̲ampOf L 51 52hud ← w ᵖˡh̲udLit 1 53s ← ᵉⁿl̲ighting ᵉⁿn̲ew w 54streamed ← (4 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s 55last ← 100000 'ᵖˡf̲rame p̲ower (streamed, 1) 56_ ← ˢᶜc̲lose! w 57⍝ (an accessor, not a top-level tuple pattern: ask E10) 58ᵘw̲orldOf ← { (s, _) → s } 59world ← ᵘw̲orldOf last 60"by day (1) or night (2) at the end, and the lamps placed:" 61ᵉⁿl̲it world 62'+ r̲/ 8 = 4 s̲elect₂ ᵉⁿe̲dits world 63"bye"