Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bubble Universe
#1
Paul Dunn posted a cool program for SpecBAS in the BASIC Programming Language facebook group. I just had to rewrite it in n7.

The original source code can be found here: https://github.com/ZXDunny/SpecBAS-Demos...e_universe

Code:
' Bubble universe
' ---------------
' Paul Dunn posted this code but for SpecBAS in a facebook group. It looked so cool that I had to
' rewrite it in n7.

constant TAU = 6.283185307179586

set window "Bubble universe", 512, 512
set redraw off

n = 200; r = TAU/235
x = 0; y = 0;
v = 0; t = 0;
hw = width(primary)/2; hh = height(primary)/2

while not keydown(KEY_ESCAPE)
    set color 0, 0, 0
    cls
    for i = 0 to n  for j = 0 to n
        u = sin(i + v) + sin(r*i + x)
        v = cos(i + v) + cos(r*i + x)
        x = u + t
        set color i, j, 99
        set pixel hw + u*hw*0.4, hh + v*hh*0.4
    next
    t = t + 0.025
   
    set caret hw, 4
    set color 255, 255, 255
    center "Press esc to exit ..."
   
    fwait 60
    redraw
wend
Reply
#2
Cool... Reminds me of a Plasma Ball without the tendrils... Almost hypnotic... Nicely done!

Um... Stupid question to follow... lol

Within the while...wend loop there there are "for i" and "for j" loops but only one "next".

The program runs fine... but how does two "for"'s using one "next" actually work?

Just curious...

J
May your journey be free of incident.
Live long and prosper.
Reply
#3
(11-14-2022, 11:47 PM)johnno1956 Wrote: Cool... Reminds me of a Plasma Ball without the tendrils... Almost hypnotic... Nicely done!

Um... Stupid question to follow... lol

Within the while...wend loop there there are "for i" and "for j" loops but only one "next".

The program runs fine... but how does two "for"'s using one "next" actually work?

Just curious...

J

It works just like 'if'. You can write

Code:
if 5 > 3
  pln "yay!"
endif

, or:

Code:
if 5 > 3  pln "yay!"

With for:

Code:
for i = 1 to 5
  pln "yay!"
next

, or:

Code:
for i = 1 to 5  pln "yay!"

If you use a one-liner, only one statement connected directly to 'if' or 'for' on the same line, 'endif' or 'next' is not expected.

So when if you write:

Code:
for i = 1 to 5  for j = 9 to 7
   ...
next

, the first 'for' is a one-liner, and the second 'for' is its statement. 'next' belongs to the second 'for'.
Reply
#4
Cool... Thank you for the info. Appreciated.

J
May your journey be free of incident.
Live long and prosper.
Reply
#5
dang...
i cannot get same effect in my interpreter ..probably
because is slow or i use pure GDI
BASIC4ALL FORUM:
http://microabasic.epizy.com
Reply
#6
(11-15-2022, 05:59 PM)Aurel Wrote: dang...
i cannot get same effect in my interpreter ..probably
because is slow or i use pure GDI

Are you getting the coordinates right? u and v will be in the range [-1..1], so you have to add 1 and multiply with half the width and height of the window (that's not exactly what I'm doing, but still).
Reply
#7
very nice graphic effect
Reply
#8
marcus
" so you have to add 1 "

add to what or where ?
my output window is 800 x 600
BASIC4ALL FORUM:
http://microabasic.epizy.com
Reply
#9
(11-16-2022, 04:54 PM)Aurel Wrote: marcus
" so you have to add 1 "

add to what or where ?
my output window is 800 x 600

I don't remember what the original code looked like, sorry, but I think the plot coordinates were calculated like this:

Code:
u = sin(i + v) + sin(r*i + x)
v = cos(i + v) + cos(r*i + x)

But those coordinates are both [-1..1], so for an 800x600 screen you can do:

Code:
plot 400 + u*400, 300 + v*300

Unless you can do what Paul is doing and change the coordinate system of the window .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)