info = { type = "image", title = "Stone cutter", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "A diamond drill bores a stone slab apart", api = 33, } local STEP_HZ = 30 local FR = 0 local tr = ({ sk = { ["Slab"] = "Dlaždica", ["Mixed"] = "Zmiešané", ["Marble"] = "Mramor", ["Granite"] = "Žula", ["Jade"] = "Nefrit", ["Rose quartz"] = "Ruženín", ["Speed"] = "Rýchlosť" }, cs = { ["Slab"] = "Dlaždice", ["Mixed"] = "Smíšené", ["Marble"] = "Mramor", ["Granite"] = "Žula", ["Jade"] = "Nefrit", ["Rose quartz"] = "Růženín", ["Speed"] = "Rychlost" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "slab", label = T("Slab"), type = "int", default = "mix", opts = { keys = { "mix", "marble", "granite", "jade", "rose" }, T("Mixed"), T("Marble"), T("Granite"), T("Jade"), T("Rose quartz") } }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, cos, sin, min, max = math.floor, math.cos, math.sin, math.min, math.max local hash32 = math.hash32 local W, H = gfx.W, gfx.H local PI = 3.14159265 local SLABS = { marble = { top = { 255, 255, 250 }, body = { 228, 228, 222 }, low = { 184, 184, 180 }, vein = { 140, 144, 158 }, hole = { 92, 92, 98 } }, granite = { top = { 200, 200, 206 }, body = { 146, 146, 152 }, low = { 104, 104, 112 }, vein = { 60, 60, 68 }, hole = { 56, 56, 62 } }, jade = { top = { 150, 236, 184 }, body = { 64, 176, 116 }, low = { 38, 124, 80 }, vein = { 180, 246, 208 }, hole = { 24, 84, 54 } }, rose = { top = { 255, 214, 226 }, body = { 238, 154, 176 }, low = { 190, 106, 132 }, vein = { 255, 234, 240 }, hole = { 128, 62, 84 } }, } local ORDER = { "marble", "granite", "jade", "rose" } local SX0, SW, SY = 8, 48, 36 local CYC = 270 local SPD, MODE = 1, "mix" local VEIN = {} do for s = 1, 4 do local h = hash32(s * 0x9E3779B1 + 21) local c, r = 3 + (h & 15) + (s - 1) * 11, 1 + (h >> 4 & 3) for k = 1, 6 do if c >= 0 and c < SW and (c < 21 or c > 26) and r >= 1 and r <= 6 then VEIN[#VEIN + 1] = c; VEIN[#VEIN + 1] = r end local hk = hash32(h + k) c = c + 1 + (hk & 1) r = r + ((hk >> 1 & 3) == 0 and -1 or ((hk >> 1 & 3) == 1 and 1 or 0)) end end end local CRACK = { 31, 41, 32, 42, 31, 43, 29, 38, 28, 39, 27, 39, 34, 38, 35, 39, 36, 40, 26, 40, 37, 41 } local T_IN, T_DOWN0, T_CUT0, T_CUT1, T_UP1 = 50, 64, 86, 196, 212 local T_CR, T_FALL = 208, 216 local function tip_y(t) if t < T_DOWN0 then return 22 end if t < T_CUT0 then return 22 + 14 * (0.5 - 0.5 * cos(PI * (t - T_DOWN0) / (T_CUT0 - T_DOWN0))) end if t < T_CUT1 then return 36 + 5 * (t - T_CUT0) / (T_CUT1 - T_CUT0) end if t < T_UP1 then local p = (t - T_CUT1) / (T_UP1 - T_CUT1); return 41 - 19 * p * p end return 22 end local BG = nil local function build_bg() rect(0, 0, W, H, 60, 72, 92) rect(3, 3, 58, 30, 80, 92, 112) for y = 5, 31, 4 do for x = 5, 59, 4 do px(x, y, 52, 62, 80) end end rect(8, 8, 1, 14, 176, 182, 196); rect(7, 6, 3, 2, 176, 182, 196) px(8, 6, 80, 92, 112); rect(7, 22, 3, 2, 176, 182, 196); px(8, 23, 80, 92, 112) rect(15, 7, 2, 13, 150, 98, 58); rect(13, 20, 6, 4, 196, 90, 50) rect(53, 11, 2, 15, 156, 104, 62); rect(50, 7, 8, 4, 128, 136, 152) rect(50, 7, 8, 1, 176, 184, 198) rect(0, 58, W, 6, 76, 74, 84) rect(0, 58, W, 1, 104, 100, 112) for _, x in ipairs({ 22, 36 }) do rect(x, 45, 6, 19, 110, 118, 132) rect(x, 45, 1, 19, 150, 160, 176) rect(x + 5, 45, 1, 19, 76, 82, 96) rect(x - 1, 44, 8, 1, 58, 56, 64) end rect(28, 52, 8, 2, 88, 96, 110) BG = gfx.snapshot(0, 0, W, H) end local function c3(c) return c[1], c[2], c[3] end local function slab(x0, S, depth) local ix = floor(x0) local f = x0 - ix rect(ix + 1, SY, SW - 1, 1, c3(S.top)) rect(ix + 1, SY + 1, SW - 1, 6, c3(S.body)) rect(ix + 1, SY + 7, SW - 1, 1, c3(S.low)) if f < 0.95 then local a = 1 - f blend(ix, SY, S.top[1], S.top[2], S.top[3], a) blend_rect(ix, SY + 1, 1, 6, S.body[1], S.body[2], S.body[3], a) blend(ix, SY + 7, S.low[1], S.low[2], S.low[3], a) end if f > 0.05 then blend(ix + SW, SY, S.top[1], S.top[2], S.top[3], f) blend_rect(ix + SW, SY + 1, 1, 6, S.body[1], S.body[2], S.body[3], f) blend(ix + SW, SY + 7, S.low[1], S.low[2], S.low[3], f) end local xr = floor(x0 + 0.5) for k = 1, #VEIN, 2 do px(xr + VEIN[k], SY + VEIN[k + 1], c3(S.vein)) end if depth >= 1 then rect(xr + 22, SY, 4, depth, c3(S.hole)) end end local function half(side, S, th, dxo, dyo) local pv = side < 0 and 22 or 42 local c0 = side < 0 and 0 or 24 local cs, sn = cos(th), sin(th) for c = c0, c0 + 23 do local top, h = 0, 8 if c >= 22 and c <= 25 then top, h = 5, 3 end local d = SX0 + c + 0.5 - pv local X = floor(pv + d * cs + side * dxo) local Y = SY + top + floor(side * d * sn + dyo + 0.5) rect(X, Y, 1, h, c3(S.body)) if top == 0 then px(X, Y, c3(S.top)) end px(X, Y + h - 1, c3(S.low)) end for k = 1, #VEIN, 2 do local c = VEIN[k] if (side < 0) == (c < 24) then local d = SX0 + c + 0.5 - pv px(floor(pv + d * cs + side * dxo), SY + VEIN[k + 1] + floor(side * d * sn + dyo + 0.5), c3(S.vein)) end end end local OR_, OR_L, OR_D = { 232, 140, 36 }, { 255, 192, 92 }, { 172, 92, 20 } local function drill(tipy, ph) local ty = floor(tipy) local f = tipy - ty local ht = ty - 33 if ht > 0 then rect(29, 0, 6, ht, 120, 128, 142) rect(29, 0, 1, ht, 170, 178, 192) end rect(22, ht, 20, 14, c3(OR_)) rect(22, ht, 20, 1, c3(OR_L)) rect(22, ht, 1, 14, c3(OR_L)) rect(40, ht, 2, 14, c3(OR_D)) rect(25, ht + 3, 13, 3, 44, 40, 48) for x = 26, 37, 2 do rect(x, ht + 4, 1, 1, 96, 90, 100) end rect(25, ht + 9, 13, 1, c3(OR_D)) if f > 0.05 then blend_rect(22, ty - 19, 20, 1, OR_D[1], OR_D[2], OR_D[3], f) end local an = (tipy - 22) * 0.16 - 0.5 local hx, hy = 43, ht + 6 rect(hx - 1, hy - 1, 2, 2, 70, 74, 84) for k = 1, 6 do px(floor(hx + cos(an) * k + 0.5), floor(hy + sin(an) * k + 0.5), 176, 182, 196) end rect(floor(hx + cos(an) * 7), floor(hy + sin(an) * 7), 2, 2, 210, 40, 40) rect(28, ty - 19, 8, 5, 150, 156, 170) rect(28, ty - 19, 1, 5, 200, 206, 218) rect(35, ty - 19, 1, 5, 96, 100, 114) rect(29, ty - 17, 6, 1, 110, 116, 128) if f > 0.05 then blend_rect(28, ty - 14, 8, 1, 96, 100, 114, f) end rect(30, ty - 14, 1, 12, 214, 220, 230) rect(31, ty - 14, 1, 12, 182, 188, 200) rect(32, ty - 14, 1, 12, 150, 156, 170) rect(33, ty - 14, 1, 12, 112, 118, 132) for r = 0, 11 do px(30 + (r - ph) % 4, ty - 14 + r, 84, 88, 100) end rect(29, ty - 2, 6, 2, 232, 120, 210) px(29 + ph % 6, ty - 2, 255, 255, 255) px(29 + (ph + 3) % 6, ty - 1, 255, 220, 246) if f > 0.05 then blend_rect(29, ty, 6, 1, 232, 120, 210, f) end end local function sparks(t, n) if t < T_CUT0 or t > T_CUT1 + 18 then return end local m1 = floor(min(t, T_CUT1)) for m = max(T_CUT0, m1 - 17), m1 do local h = hash32(m * 0x9E3779B1 + n * 0x85EBCA6B) local life = 8 + (h & 7) local a = t - m if a >= 0 and a < life then local side = (h >> 3 & 1) == 0 and -1 or 1 local vx = side * (0.5 + (h >> 4 & 15) / 10) local vy = -(0.8 + (h >> 8 & 15) / 9) local x = floor(31.5 + side * 2.5 + vx * a + 0.5) local y = floor(35 + vy * a + 0.11 * a * a + 0.5) local k = a / life if k < 0.3 then px(x, y, 255, 250, 210) elseif k < 0.6 then px(x, y, 255, 204, 64) elseif k < 0.85 then px(x, y, 255, 128, 32) else px(x, y, 196, 56, 24) end end end end local function dot(x, y, r, g, b, a) local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy blend(ix, iy, r, g, b, a * (1 - fx) * (1 - fy)); blend(ix + 1, iy, r, g, b, a * fx * (1 - fy)) blend(ix, iy + 1, r, g, b, a * (1 - fx) * fy); blend(ix + 1, iy + 1, r, g, b, a * fx * fy) end local function dust(t, n, S) local r, g, b = c3(S.top) for m = T_CUT0, T_CUT1, 6 do local a = t - m if a >= 0 and a < 64 then local h = hash32(m * 0x2545F491 + n) local side = (h & 1) == 0 and -1 or 1 local vx = side * (0.12 + (h >> 2 & 15) / 60) local vy = -0.12 - (h >> 6 & 7) / 60 dot(31.5 + side * 3 + vx * a, 34 + vy * a + 0.004 * a * a, r, g, b, 0.55 * (1 - a / 64)) end end end local function chips(t, n, S) local a = t - T_CR if a < 0 or a > 26 then return end for i = 1, 6 do local h = hash32(i * 0x632BE5AB + n) local side = i % 2 == 0 and -1 or 1 local vx = side * (0.3 + (h & 15) / 16) local vy = -(0.7 + (h >> 4 & 15) / 16) local c = i % 3 == 0 and S.low or S.top px(floor(31.5 + vx * a + 0.5), floor(40 + vy * a + 0.13 * a * a + 0.5), c[1], c[2], c[3]) end end function on_settings() SPD = 0.25 + 0.25 * (cfg.speed or 3) MODE = cfg.slab or "mix" end function render() FR = frame * STEP_HZ // gfx.FPS if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local tt = FR * SPD local n = floor(tt / CYC) local t = tt - n * CYC local S = SLABS[MODE] or SLABS[ORDER[1 + n % 4]] local ty = tip_y(t) local depth = t >= T_CUT1 and 5 or floor(min(5, max(0, ty - 36))) if t < T_IN then local p = 1 - t / T_IN slab(SX0 + (64 - SX0) * p * p * p, S, 0) elseif t < T_FALL then local sh = 0 if t >= T_CR and t < T_CR + 6 then sh = (floor(t) % 2 == 0) and 1 or -1 end slab(SX0 + sh, S, depth) if t >= T_CR then local nn = min(#CRACK // 2, floor((t - T_CR) * 1.6) + 1) for k = 1, nn do px(CRACK[2 * k - 1] + sh, CRACK[2 * k], c3(S.hole)) end end else local tau = t - T_FALL local th, dyo, dxo = 0.002 * tau * tau, 0, 0 local td = 15 if tau > td then local e = tau - td th = 0.45 + 0.06 * e dyo, dxo = 0.15 * e * e, 0.5 * e end if dyo < 40 then th = min(th, 1.3) half(-1, S, th, dxo, dyo) half(1, S, th, dxo, dyo) end end local ph = floor(min(max(t, 58), 214) - 58) drill(ty, ph) sparks(t, n) dust(t, n, S) chips(t, n, S) end