Subject: Torus Scope

From: Matt <[email-masked]>
Date: Thu, 5 Sep 2002 08:15:41 -0500

Here's your magic, with comments: the torus (with clipping).

[init]
# set constants
n = 1000; pi = acos(-1); pi2 = pi*2; rad = pi/180;

# initial angles and angle deltas
ax = 0; ay = 0; az = 0; adx = 0; ady = 0; adz = 0;

# on-beat sync stuff
width = 1 / 6; width_2 = width / 2;

# clipping vars
cx = 0; cy = 0; cz = -1;

-----

[beat]
# on-beat angle sync stuff
adx = rad * 7 * getosc(width_2, width, 0);
ady = rad * 7 * getosc(width + width_2, width, 0);
adz = rad * 7 * getosc(width * 2 + width_2, width, 0);

-----

[frame]
# old clip var
old_clip = 0;

# adjust the x, y, and z angles
ax = ax + adx; ay = ay + ady; az = az + adz;

# calc. angle sines and cosines here for speed
xcos = cos(ax); xsin = sin(ax); ycos = cos(ay); ysin = sin(ay); zcos = cos(az); zsin = sin(az);

-----

[pixel]
# low-pass filter stuff
v2 = v2 * 0.9 + v * 0.1;

# pseudo-3d polar coords
r1 = 1; r2 = (0.5 + v2 * 0);
a1 = i * pi2; a2 = i * pi2 * 60;

# convert 3d polar -> 3d rect coords
x4 = (r1 + r2 * sin(a2)) * sin(a1);
y4 = r2 * cos(a2);
z4 = (r1 + r2 * sin(a2)) * cos(a1);

# x-axis rotation
x3 = x4;
y3 = y4 * xcos - z4 * xsin;
z3 = y4 * xsin + z4 * xcos;

# y-axis rotation
x2 = x3 * ycos + z3 * ysin;
y2 = y3;
z2 = -x3 * ysin + z3 * ycos;

# z-axis rotation
x1 = x2 * zcos - y2 * zsin - cx;
y1 = x2 * zsin + y2 * zcos - cy;
z1 = z2 - cz;

# clipping
new_clip = bnot(above(z1, 0));
do_clip = bor(new_clip, old_clip);
old_clip = new_clip;

# 3d -> 2d transform, with clip check
x = if(new_clip, 0, x1 / z1);
y = if(new_clip, 0, y1 / z1);

# color
val = if(do_clip, 0, 1 - z1 / 4);
red = val; green = val; blue = val;

-- 
Matt  |  [email-masked]  |  users.openverse.com/~matt/