Skip to content

Instantly share code, notes, and snippets.

@cl1ents
Last active November 2, 2022 12:42
Show Gist options
  • Save cl1ents/3901ecd0f7d4446305a5c6c03fa9e93f to your computer and use it in GitHub Desktop.
Save cl1ents/3901ecd0f7d4446305a5c6c03fa9e93f to your computer and use it in GitHub Desktop.
Donut math: recreation of donut.c in Roblox Luau
sin,cos,w=math
.sin,math.cos,math.--$
floor;A,R,S=0,.0704,1760;C
=(".,-~:;=!*#$@"):split("")b,z
={},{}while(1)do task.wait(.01)for
i=0,S do z[i]=0 end for i=0,S do b[i
]=i%80==0 and"\n" or" " end V=6.28 B=A
/2 for j=0,V,0.07 do for i = 0, V, .02
do c,d,e,f,g=sin (i),cos(j),sin(A
),sin(j),cos(A) h=d+2;D=1/(c*h*
e+f*g+5);l,m,n= cos(i),cos(B)--
,sin(B)t=c*h*g- f*e;x=w(40+30*D
*(l*h*m-t*n))y=w(12+15*D*(l*h*n+t*m))o
= w(x + 80 * y);N=w(8*((f*e-c*d*g)*m-c
*d*e-f*g-l*d*n))+1 if 22>y and y>0--
and x>0 and 80>x and D> z[o]then z
[o]=D b[o]=C[(N>1 and N or 1)]
end;end;end;A+=R;script.--
Parent.Text=table.--~-.
concat(b,"")end
sin, cos, w =
math.sin,
math.cos,
math.floor
A, R, S = 0, .0704, 1760
C = (".,-~:;=!*#$@"):split("")
b, z = {}, {}
while (1) do
task.wait(.01)
for i = 0, S do
z[i] = 0
end
for i = 0, S do
b[i] = i % 80 == 0 and "\n" or " "
end
V = 6.28
B = A / 2
for j = 0, V, 0.07 do
for i = 0, V, .02 do
c, d, e, f, g = sin(i), cos(j), sin(A), sin(j), cos(A)
h = d + 2
D = 1 / (c * h * e + f * g + 5)
l, m, n =
cos(i),
cos(B),
sin(B)
t = c * h * g - f * e
x = w(40 + 30 * D * (l * h * m - t * n))
y = w(12 + 15 * D * (l * h * n + t * m))
o = w(x + 80 * y)
N = w(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n)) + 1
if 22 > y and y > 0 and x > 0 and 80 > x and D > z[o] then
z[o] = D
b[o] = C[(N > 1 and N or 1)]
end
end
end
A += R
script.Parent.Text = table.concat(b, "")
end

I honestly have no idea why I took the time to make this

there's ONE extra character at the end, so its not a perfect donut, but its close enough

put it in a gui like so, with the font as "Code" in the TextLabel & it should just work

Example

All credits goes to Andy Sloane & his original code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment