Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QBJS Rotating 4D cube
#1
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)


dim x(16), y(16), z(16), w(16)
x(0)=0-1: y(0) =0-1: z(0) =0-1: w(0) = 0-1
x(1)=  1: y(1) =0-1: z(1) =0-1: w(1) = 0-1
x(2)=  1: y(2) =  1: z(2) =0-1: w(2) = 0-1
x(3)=0-1: y(3) =  1: z(3) =0-1: w(3) = 0-1

x(4)=0-1: y(4) =0-1: z(4) =1: w(4) = 0-1
x(5)=  1: y(5) =0-1: z(5) =1: w(5) = 0-1
x(6)=  1: y(6) =  1: z(6) =1: w(6) = 0-1
x(7)=0-1: y(7) =  1: z(7) =1: w(7) = 0-1

x( 8)=0-1: y( 8) =0-1: z( 8) =0-1: w( 8) = 1
x( 9)=  1: y( 9) =0-1: z( 9) =0-1: w( 9) = 1
x(10)=  1: y(10) =  1: z(10) =0-1: w(10) = 1
x(11)=0-1: y(11) =  1: z(11) =0-1: w(11) = 1

x(12)=0-1: y(12) =0-1: z(12) =1: w(12) = 1
x(13)=  1: y(13) =0-1: z(13) =1: w(13) = 1
x(14)=  1: y(14) =  1: z(14) =1: w(14) = 1
x(15)=0-1: y(15) =  1: z(15) =1: w(15) = 1


screen _newimage(sw, sh, 32)

do
for t = 0 to 8*pi step 0.01
    cls

    f=0
    i = 0
    proj x(i), y(i), z(i), w(i)
    pset (p, q)
    for i=1 to 3
        proj x(i), y(i), z(i), w(i)
        line -(p, q)
    next
    i = 0
    proj x(i), y(i), z(i), w(i)
    line -(p, q)

    i = 4
    proj x(i), y(i), z(i), w(i)
    pset (p, q)
    for i=4 to 7
        proj x(i), y(i), z(i), w(i)
        line -(p, q)
    next
    i = 4
    proj x(i), y(i), z(i), w(i)
    line -(p, q)

    for i=0 to 3
        proj x(i), y(i), z(i), w(i)
        pset (p, q)
        proj x(i+4), y(i+4), z(i+4), w(i+4)
        line -(p, q)
    next

    f = 1
    k = 8
    i = 0+k
    proj x(i), y(i), z(i), w(i)
    pset (p, q), _rgb(255,0,0)
    for i=1+k to 3+k
        proj x(i), y(i), z(i), w(i)
        line -(p, q), _rgb(255,0,0)
    next
    i = 0+k
    proj x(i), y(i), z(i), w(i)
    line -(p, q), _rgb(255,0,0)

    i = 4+k
    proj x(i), y(i), z(i), w(i)
    pset (p, q), _rgb(255,0,0)
    for i=4+k to 7+k
        proj x(i), y(i), z(i), w(i)
        line -(p, q), _rgb(255,0,0)
    next
    i = 4+k
    proj x(i), y(i), z(i), w(i)
    line -(p, q), _rgb(255,0,0)

    for i=0+k to 3+k
        proj x(i), y(i), z(i), w(i)
        pset (p, q), _rgb(255,0,0)
        proj x(i+4), y(i+4), z(i+4), w(i+4)
        line -(p, q), _rgb(255,0,0)
    next

    for i=0 to 7
        f = 0
        proj x(i), y(i), z(i), w(i)
        pset (p, q)
        f = 1
        proj x(i+k), y(i+k), z(i+k), w(i+k)
        line -(p, q)
    next

    _display
    _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/3
    b = pi/12
    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 = 100*xx
    yy = 100*yy
    zz = 100*zz

    p = sw/2 + 2*xx*d/(yy + z0)
    q = sh/2 - 2*zz*d/(yy + z0)
end sub
Reply
#2
I was curious about 4D, so I copy/pasted the code, but I get an error in line 41: illegal function call. Do I need another file?
edit: I just noticed its a JS file, so I guess I'm not able to run it.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#3
Hi, Phil. Yes, the programs I intend to post here have only been tested in QBJS and use new high tech QBJS features.

Since this program is mostly compatible with QB64PE I have modified the above post to be so, so feel free to try the above again
Reply
#4
Before this line was missing the 32

Screen _NewImage(sw, sh, 32)

Now it's there.
b = b + ...
Reply
#5

[i]EDIT:  OOPS, I had set my screen mode to 12, and that should have been 18.  Correction made.  The red color vince has in there adds a really nice touch.[/i]
Reply
#6
very nice, Charlie, thanks for the link.

Suppose I wanted to write a wiki article on 4D geometry with various example codes, with BAM I could start tiddling my willy away with the tiddlywiki
Reply
#7
(11-08-2022, 03:33 AM)vince Wrote: very nice, Charlie, thanks for the link.

Suppose I wanted to write a wiki article on 4D geometry with various example codes, with BAM I could start tiddling my willy away with the tiddlywiki

You know, one can be as happy as the day is long, tiddling one's wiki, wiki-ing one's tiddly, and throwing in a willy for the trifecta ménage-à-trois, just remember to get proper rest and nutrition.

Then again, to be here for a long time vs being here for a good time ...

Giggles aside, seeing as your code essentially works as is, I figured a link to BAM export to run the program when it is so easy to do: what the hey.

It is a really sharp program.  Totally mesmerising.  If I smoked the wacky tabacky, I'd have a doobie goin' while watching that animation, man.

EDIT:  OOPS, I had set my screen mode to 12, and that should have been 18.  Correction made.  The red color vince has in there adds a really nice touch.
Reply
#8
(11-08-2022, 03:13 AM)vince Wrote: Hi, Phil.  Yes, the programs I intend to post here have only been tested in QBJS and use new high tech QBJS features.

Since this program is mostly compatible with QB64PE I have modified the above post to be so, so feel free to try the above again

Oh wow!
Looks beautiful Vince! Looks so simple, too!
I'm not game to even look at QBJS, although I did start on Javascript a while back... I guess that's what the JS refers to?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#9
Thumbs Up 
vince on a roll at a few forums!

Nice translation Charlie! (I suspect it wasn't hard, vince code is pretty Basic!)
b = b + ...
Reply
#10
(11-08-2022, 06:12 PM)bplus Wrote: vince on a roll at a few forums!

Nice translation Charlie! (I suspect it wasn't hard, vince code is pretty Basic!)

All vince's original, and quite awesome, code.

The only required change for BAM: add a subroutine declaration at the top. 
  • EDIT: Oh yeah, and BAM does need the "CALL" statement to call a subroutine

Me just being fussy: changed the third parameter on _NEWIMAGE.

EDIT:  OOPS, I had set my screen mode to 12, and that should have been 18.  Correction made.  The red color vince has in there adds a really nice touch.
Reply




Users browsing this thread: 1 Guest(s)