ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
3.3 KiB
Text
80 lines
3.3 KiB
Text
# grade.ludic - a photograph out of a hundred, for its best subject: SIZE in the frame (40), FRAMING
|
|
# (20), LIGHT (20) and THE MOMENT (20). A tag is a tag at any grade; the grade is what a frame is
|
|
# worth, never whether it happened.
|
|
# the share of the picture's height the subject stands in, 0..1
|
|
function pht_size_frac(h: float, d: float) -> float {
|
|
let span = 2.0 * d * Math.tan(PhotoLens.fov() * 0.5)
|
|
if span < 0.01 { return 1.0 }
|
|
return Math.clamp(h / span, 0.0, 1.0)
|
|
}
|
|
|
|
# 0..40: a record shot under 4%, the band that pays a quarter to two thirds, cropped past 85%
|
|
export function photo_score_size(frac: float) -> int {
|
|
if frac < 0.04 { return int(frac / 0.04 * 6.0) }
|
|
if frac < 0.25 { return int(6.0 + (frac - 0.04) / 0.21 * 28.0) }
|
|
if frac < 0.70 { return 40 }
|
|
if frac < 0.85 { return int(40.0 - (frac - 0.70) / 0.15 * 6.0) }
|
|
return int(Math.max(34.0 - (frac - 0.85) / 0.15 * 22.0, 8.0))
|
|
}
|
|
|
|
# 0..20 from how near a thirds point it sits; cut by an edge, a third of that
|
|
export function photo_score_frame(sx: float, sy: float, frac: float) -> int {
|
|
let m = frac * 0.5
|
|
if sx < 0.0 or sx > 1.0 or sy < 0.0 or sy > 1.0 { return 0 }
|
|
var best = 9.0
|
|
for i in 0 .. 2 {
|
|
for j in 0 .. 2 {
|
|
let dx = sx - float(i + 1) / 3.0
|
|
let dy = sy - float(j + 1) / 3.0
|
|
best = Math.min(best, Math.sqrt(dx * dx + dy * dy))
|
|
}
|
|
}
|
|
var v = int(Math.max(1.0 - best / 0.28, 0.0) * 20.0)
|
|
if sx < m or sx > 1.0 - m or sy < m or sy > 1.0 - m { v = v / 3 }
|
|
return v
|
|
}
|
|
|
|
# The whole score for a subject `h` metres tall standing at (x, y, z), doing something worth
|
|
# `moment` (0..20). Composition, light and behaviour are qualities OF a subject, so they are
|
|
# weighted by how much of one there is: a deer three pixels wide in perfect light is not a photograph.
|
|
export function photo_score(photo_st: mut PhotoState, x: float, y: float, z: float, h: float, moment: int) -> int {
|
|
let dx = x - PhotoLens.x()
|
|
let dy = y + 0.6 - PhotoLens.y()
|
|
let dz = z - PhotoLens.z()
|
|
let d = Math.max(Math.sqrt(dx * dx + dy * dy + dz * dz), 0.01)
|
|
let frac = pht_size_frac(h, d)
|
|
if photo_st.pht_comp == null { pht_blank(photo_st) }
|
|
var sx = 0.5
|
|
var sy = 0.5
|
|
if PhotoLens.project(x, y + h * 0.5, z) {
|
|
sx = PhotoLens.sx()
|
|
sy = PhotoLens.sy()
|
|
}
|
|
photo_st.pht_comp[0] = float(photo_score_size(frac))
|
|
photo_st.pht_comp[1] = float(photo_score_frame(sx, sy, frac))
|
|
if PhotoLens.steady() { photo_st.pht_comp[1] = Math.min(photo_st.pht_comp[1] + 5.0, 20.0) }
|
|
photo_st.pht_comp[2] = float(photo_score_light(x, z))
|
|
photo_st.pht_comp[3] = float(Math.clamp(moment, 0, 20))
|
|
photo_st.pht_comp_have = true
|
|
let presence = Math.clamp(photo_st.pht_comp[0] / 40.0 * 1.4, 0.0, 1.0)
|
|
if PhotoRules.behaviour() {
|
|
photo_st.pht_comp[0] = photo_st.pht_comp[0] * 0.5
|
|
photo_st.pht_comp[3] = photo_st.pht_comp[3] * 2.0
|
|
}
|
|
return int(photo_st.pht_comp[0] + (photo_st.pht_comp[1] + photo_st.pht_comp[2] + photo_st.pht_comp[3]) * presence)
|
|
}
|
|
|
|
# the one thing to do differently next time: the worst component, or nothing to fault
|
|
export function photo_why_of_comp(photo_st: PhotoState) -> int {
|
|
var worst = PHOTO_WHY_SIZE
|
|
var least = photo_st.pht_comp[0] / 40.0
|
|
for k in 1 .. 4 {
|
|
let f = photo_st.pht_comp[k] / 20.0
|
|
if f < least {
|
|
least = f
|
|
worst = k
|
|
}
|
|
}
|
|
if least > 0.8 { return PHOTO_WHY_FINE }
|
|
return worst
|
|
}
|