Posts: 301
Threads: 16
Joined: Apr 2022
Reputation:
51
04-14-2023, 02:01 AM
(This post was last modified: 04-14-2023, 02:30 AM by vince.)
inside out torus
run it in QBJS
Code: (Select All) r = 50
rr = 100
pi = 3.141593
SCREEN _NEWIMAGE(640, 480, 32), , 1, 0
dim t
'SCREEN , , 0, 0
DO
cls
'PCOPY 1, 0
t = t + .1
FOR u = 0 TO 7 STEP .05
FOR v = 0 TO 7 STEP .1
h = 100 * SIN(t)
x = (100 + 50 * COS(u)) * COS(v) + h
rr = 100 * COS(t)
cc = (pi / 2) * SIN(t)
ss = SIN(v) * COS(t) + SIN(t)
y = (rr + r * COS(u + cc)) * ss
rr = 100 * SIN(t)
cc = (pi / 2) * COS(t)
ss = SIN(v) * SIN(t) + COS(t)
z = (rr + r * COS(u + cc)) * ss
PSET (x + 0.707 * z + 320, y + 0.707 * z + 240), _RGB(255, 0, z * 10)
NEXT
NEXT
'SLEEP
_LIMIT 10
_DISPLAY
LOOP
Posts: 301
Threads: 16
Joined: Apr 2022
Reputation:
51
04-14-2023, 02:07 AM
(This post was last modified: 04-14-2023, 03:40 AM by vince.)
as well as the 4D clifford torus
run in QBJS
Code: (Select All) dim shared pi, p, q, d, z0, t, f, sw, sh
sw = 800
sh = 600
d = 700
z0 = 1500
pi = 4*atn(1)
screen _newimage(sw, sh, 32)
sv = 2*pi/30
su = 2*pi/10
'do
for t = 0 to 2*pi step 0.01
cls
u = 0
for v=0 to 2*pi+sv step sv
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
line (p, q)-(p, q)
for u=0 to 2*pi+su step su
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
line -(p, q)
next
next
for u=0 to 2*pi+su step su
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
line (p, q)-(p, q), _rgb(255,0,0)
for v=0 to 2*pi+sv step sv
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
line -(p, q), _rgb(255,0,0)
next
next
_limit 50
next
'loop
sub proj(x, y, z, w)
xx = x
yy = y*cos(t) - w*sin(t)
zz = z
ww = y*sin(t) + w*cos(t)
d2 = 3
w0 = 3
xx = xx*d2/(w0 + ww)
yy = yy*d2/(w0 + ww)
zz = zz*d2/(w0 + ww)
xxx = xx*cos(t) - zz*sin(t)
zzz = xx*sin(t) + zz*cos(t)
xx = xxx
zz = zzz
a = pi/12
b = pi/3
xxx = xx*cos(a) - yy*sin(a)
yyy = xx*sin(a) + yy*cos(a)
xx = xxx
yy = yyy
yyy = yy*cos(b) - zz*sin(b)
zzz = yy*sin(b) + zz*cos(b)
yy = yyy
zz = zzz
xx = 200*xx
yy = 200*yy
zz = 200*zz
p = sw/2 + 2*xx*d/(yy + z0)
q = sh/2 - 2*zz*d/(yy + z0)
end sub
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
ROFLMAO I got that "Clifford" to dance, first by pressing "< Run >" at the bottom and then pressing the triangular "play" button at the top. This was with Firefox on Linux.
Posts: 301
Threads: 16
Joined: Apr 2022
Reputation:
51
04-14-2023, 03:13 AM
(This post was last modified: 04-14-2023, 03:45 AM by vince.
Edit Reason: none
)
yo @dbox
Program #1 runs faster on the latest build at qbjs.org and slower on version 0.5 beta
meanwhile, program #2 runs way faster on 0.5 beta and very slow on the latest build
something is up, perhaps the PSET buffering? the first program just uses PSETs to sketch out the torus while the second uses LINEs to make a wireframe
EDIT: dbox identified the issue and it will likely get fixed but in the meantime I updated the post with a workaround fix for now
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
04-14-2023, 03:29 AM
(This post was last modified: 04-14-2023, 04:12 AM by CharlieJV.)
(04-14-2023, 02:01 AM)vince Wrote: inside out torus
That's a thing of beauty, so I had to try and get it working in BAM.
I had a devil of a time getting the right colouring, and spent much of the last hour trying to figure out the right formula for the blue component.
https://basicanywheremachine.neocities.o...ming_torus
And, because it is also very cool: https://basicanywheremachine.neocities.o...ford_torus
|