Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
Created April 26, 2026 05:29
Show Gist options
  • Select an option

  • Save ongaeshi/9754ac9df1ad5520b993dbba321d0ccb to your computer and use it in GitHub Desktop.

Select an option

Save ongaeshi/9754ac9df1ad5520b993dbba321d0ccb to your computer and use it in GitHub Desktop.
spinel でドーナツらしきもの
a = 0.0
b_rot = 0.0
# Pre-define some constants and arrays
chars = ".,-~:;=!*#$@"
out_buf = ""
# Hide cursor and clear screen
print "\x1b[?25l"
print "\x1b[2J"
while true
z = Array.new(1760, 0.0)
b = Array.new(1760, " ")
j = 0.0
while j < 6.28
i = 0.0
while i < 6.28
c = Math.sin(i)
d = Math.cos(j)
e = Math.sin(a)
f = Math.sin(j)
g = Math.cos(a)
h = d + 2.0
depth_inv = 1.0 / (c * h * e + f * g + 5.0)
l = Math.cos(i)
m = Math.cos(b_rot)
n = Math.sin(b_rot)
t = c * h * g - f * e
x = (40.0 + 30.0 * depth_inv * (l * h * m - t * n)).to_i
y = (12.0 + 15.0 * depth_inv * (l * h * n + t * m)).to_i
o = x + 80 * y
n_idx = (8.0 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n)).to_i
if 22 > y && y > 0 && x > 0 && 80 > x && depth_inv > z[o]
z[o] = depth_inv
idx = n_idx > 0 ? n_idx : 0
idx = 11 if idx > 11
b[o] = chars[idx]
end
i += 0.02
end
j += 0.07
end
out_buf = "\x1b[H" # Reset cursor to top-left
k = 0
while k < 1760
if k % 80 == 79
out_buf << 10.chr # newline
else
out_buf << b[k]
end
k += 1
end
print out_buf
a += 0.004
b_rot += 0.002
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment