programextensions/scene/demos/voxels-light.xtl

Voxels, 14: light. The endless world, lit: a face open to the sky is in full sunlight; under an overhang, beneath a tree's crown or down a tunnel the light fades, a step a block, as it spreads from the open air. A lamp (the hotbar's eighth block) glows: its light spreads the same way through the air around it. N turns day to night and back -- the sunlight and the sky go, the lamps stay -- by one number in scene, so nothing is worked out again. Each column's light is worked out as it is made (vx:c_olumnLight: sunlight by a scan down each column, then rounds of spreading), and again when an edit makes it again: dig a tunnel's roof open and the sun comes in. Run: just demo scene voxels-light click (or X) dig, right-click (or E) place, 1 to 8 choose the block (8 a lamp), N night or day, W A S D walk, Space jump, Shift run, F fly, drag or the arrows to look, H back to the start, q quit

source · imports en: extensions/scene/demos/Endless.xtl; pl: extensions/scene/demos/Play.xtl; sc: extensions/scene/lib/Scene.xtl; vx: extensions/scene/demos/Voxels.xtl

w : Int

value · line 20
w ← "Voxels 14: light -- X_eTaL" ˢᶜo̲pen! 640 400
Used in: g, k, hud, s, z

g : Int

value · line 21
g ← w ˢᶜf̲og! 22.0 44.0

k : Int

value · line 22
k ← w ˢᶜs̲ky! 0.55 0.72 0.92

k : Int

value · line 23
k ← w ˢᶜc̲urve! 160.0

The light, checked

cell : Int

value · line 35
cell ← (r̲ange 18 × 32 × 18) − 1
Used in: x, y, z, row

x : Int

value · line 36
x ← cell d̲iv 32 × 18
Used in: shaft, tunnel, lamp

y : Int

value · line 37
y ← (cell d̲iv 18) m̲od 32
Used in: shaft, tunnel, lamp

z : Int

value · line 38
z ← cell m̲od 18
Used in: shaft, tunnel, lamp

shaft : Int

value · line 39
shaft ← (x = 4) × (z = 9) × y ≥ 10
Used in: b

tunnel : Int

value · line 40
tunnel ← (y = 10) × (z = 9) × (x ≥ 4) × x ≤ 15
Used in: b, row

lamp : Int

value · line 41
lamp ← (y = 10) × (z = 9) × x = 16
Used in: b, ᵘl̲ampOf

b : Int

value · line 42
b ← 18 32 18 r̲eshape (8 × lamp) + (1 − lamp) × 1 − 0 < shaft + tunnel
Used in: L

ᵘs̲unOf : (Any a, Any b) => (a, b) -> a

function · line 43
ᵘs̲unOf ← { (sun, _) → sun }

ᵘl̲ampOf : (Any a, Any b) => (a, b) -> b

function · line 44
ᵘl̲ampOf ← { (_, lamp) → lamp }

L : (Int, Int)

value · line 45
L ← ᵛˣc̲olumnLight b

row : Int

value · line 46
row ← 1 + tunnel r̲eplicate cell

hud : Int

value · line 52
hud ← w ᵖˡh̲udLit 1

s : ((Float, Float, Float, Float, Float, Float), (Int, Int, Box Int, Box Int, Int, Int, Int, Int), (Int, Int, Int, Int), (Int, Int, Float, Int, Int))

value · line 53
s ← ᵉⁿl̲ighting ᵉⁿn̲ew w

s : ((Float, Float, Float, Float, Float, Float), (Int, Int, Box Int, Box Int, Int, Int, Int, Int), (Int, Int, Int, Int), (Int, Int, Float, Int, Int))

value · line 54
s ← (4 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s

last : (((Float, Float, Float, Float, Float, Float), (Int, Int, Box Int, Box Int, Int, Int, Int, Int), (Int, Int, Int, Int), (Int, Int, Float, Int, Int)), Int)

value · line 55
last ← 100000 'ᵖˡf̲rame p̲ower (s, 1)
Used in: s

z : Int

value · line 56
z ← ˢᶜc̲lose! w

ᵘw̲orldOf : (Any a, Any b) => (a, b) -> a

function · line 58
ᵘw̲orldOf ← { (s, _) → s }
Used in: s

s : ((Float, Float, Float, Float, Float, Float), (Int, Int, Box Int, Box Int, Int, Int, Int, Int), (Int, Int, Int, Int), (Int, Int, Float, Int, Int))

value · line 59
s ← ᵘw̲orldOf last