Last active
April 28, 2025 01:08
-
-
Save BlueFalconHD/b84651b4316118eec9fa1a847f668b25 to your computer and use it in GitHub Desktop.
Replicube demo Gameboy solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- cs: 594, c/v: 328.552 | |
local function union(a, b) | |
return function(x, y, z) | |
local v = a(x, y, z) | |
return (v ~= 0) and v or b(x, y, z) | |
end | |
end | |
local function union_col(a, b) | |
return function(x, y, z) | |
local v2 = b(x, y, z) | |
if v2 ~= 0 then | |
return v2 | |
end | |
return a(x, y, z) | |
end | |
end | |
local function intersection(a, b) | |
return function(x, y, z) | |
local v = a(x, y, z) | |
return (v ~= 0 and b(x, y, z) ~= 0) and v or 0 | |
end | |
end | |
local function subtraction(a, b) | |
return function(x, y, z) | |
local v = a(x, y, z) | |
return (v ~= 0 and b(x, y, z) == 0) and v or 0 | |
end | |
end | |
local function exclusion(a, b) | |
return function(x, y, z) | |
local va, vb = a(x, y, z), b(x, y, z) | |
if va ~= 0 and vb == 0 then return va end | |
if vb ~= 0 and va == 0 then return vb end | |
return 0 | |
end | |
end | |
function box(x1,y1,z1, x2,y2,z2, c) | |
local xmin,xmax = min(x1,x2), max(x1,x2) | |
local ymin,ymax = min(y1,y2), max(y1,y2) | |
local zmin,zmax = min(z1,z2), max(z1,z2) | |
return function(x,y,z) | |
if x < xmin or x > xmax | |
or y < ymin or y > ymax | |
or z < zmin or z > zmax then | |
return 0 | |
end | |
return c | |
end | |
end | |
function vox(xo,yo,zo,c) | |
return function(x,y,z) | |
return xo == x and yo == y and zo == z and c | |
end | |
end | |
local case_cut = function(x,y,z) | |
return (x - 4 >= y + 5 and abs(z) <= 1) and 1 or 0 | |
end | |
-- base box shape | |
local case = box(-4, 6, -1, | |
4, -6, 1, 1) | |
-- cut corner off of case | |
case = subtraction(case, case_cut) | |
-- color screen face | |
case = union_col(case, box(-3, 5, 1, 3, 1, 1, 2)) | |
-- indentation on screen | |
case = subtraction(case, box(-2, 5, 1, 2, 1, 1, 1)) | |
-- screen coloration | |
case = union_col(case, box(-2, 5, 0, 2, 1, 0, 11)) | |
-- buttons | |
case = union(case, vox(3, -2, 2, 7)) | |
case = union(case, vox(1, -3, 2, 7)) | |
-- dpad | |
local dpad = function(x, y, z) | |
if z ~= 2 then | |
return 0 | |
end | |
if y == -2 and x >= -3 and x <= -1 then | |
return 3 | |
end | |
if x == -2 and y >= -3 and y <= -1 then | |
return 3 | |
end | |
return 0 | |
end | |
case = union(case, dpad) | |
-- final case | |
return case(x,y,z) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- cs: 183, c/v: 12.814 | |
return(z==2 and((x==3 and y==-2)or(x==1 and y==-3))and 7)or | |
(z==2 and((y==-2 and x>=-3 and x<=-1)or(x==-2 and y>=-3 and y<=-1))and 3)or | |
(z==0 and x>=-2 and x<=2 and y>=1 and y<=5 and 11)or | |
(z==1 and x>=-3 and x<=3 and y>=1 and y<=5 and(x<-2 or x>2)and 2)or | |
(x>=-4 and x<=4 and y>=-6 and y<=6 and z>=-1 and z<=1 | |
and not((x-4)>=y+5 and abs(z)<=1) | |
and not(z==1 and x>=-2 and x<=2 and y>=1 and y<=5)and 1)or 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- cs: 142, c/v: 17.110 | |
return z==2 and(((x==3 and y==-2)or(x==1 and y==-3))and 7 or((y==-2 and x>-4 and x<0)or(x==-2 and y>-4 and y<0))and 3) | |
or z==0 and abs(x)<=2 and y>0 and y<6 and 11 | |
or z==1 and abs(x)==3 and y>0 and y<6 and 2 | |
or abs(x)<=4 and abs(y)<=6 and abs(z)<=1 and x<y+9 and(z<1 or abs(x)>2 or y<1 or y>5)and 1 | |
or 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment