Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Bubble universe
Author | Message | ||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
Needs the speed of MMB for Windows I believe the original code was written by Paul Dunn - developer of SpecBas. It has done the rounds of many languages including QB64 and PureBasic 'bubble universe MMB4W OPTION EXPLICIT OPTION DEFAULT FLOAT DIM r,t,u,v,x,n, TAU DIM INTEGER i, j, hw, hh, col MODE 1 n = RND()*100+300 TAU = 6.283185307179586 r = TAU / (RND()*100+235) hw = MM.HRES / 2 hh = MM.VRES / 2 'Cls(RGB(0, 0, 0)) PAGE WRITE 1 DO CLS(RGB(0, 0, 0)) 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 Col = RGB(i AND &hFF, j AND &hFF, 99) PIXEL hw + u * hw * 0.4, hh + v * hh * 0.4, Col NEXT NEXT t = t + 0.01 PAGE COPY 1 TO 0 LOOP UNTIL INKEY$ <>"" Jim Edited 2023-01-06 14:53 by TassyJim VK7JH MMedit  MMBasic Help |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Very beautifull. There was a thread about this before, it also runs on the picomite. Although not near as beautifull as on mmb4w PicomiteVGA PETSCII ROBOTS |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
I must have missed it the first time. It runs very nicely with a compiled Basic. Amazing what can be done with a few lines of code. Jim VK7JH MMedit  MMBasic Help |
||||
Goksteroo Senior Member Joined: 15/03/2021 Location: AustraliaPosts: 114 |
Original Post re Bubble Universe for MMBasic. |
||||
ebbandflow Newbie Joined: 31/08/2023 Location: United StatesPosts: 19 |
How did I not see this post!?! lol go figure. Love the images this code produces! |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
1 fps on pico even vga but pretty. ' Bubble Universe credit to who posted it mode 2 option autorun on Dim Float u,a,p,q,t,v=0, x=0 Dim Integer g,b,i,j,c(41),d(41),e(41),n(41) Dim Integer f(41,41),l(41,41),m(41,41) Const w=MM.HRes/2, h=MM.VRes/2 Const r=(2*Pi)/235, o=h/2 FRAMEBUFFER CREATE F FRAMEBUFFER WRITE f CLS RGB(black)':Backlight 95 t=Rnd*10:math set 2,e()'Math set 3,e() For g=0 to 41 for b=0 to 41 Â m(g,b)=rgb(g*6,b*6,128*(g+b>30)*(g+b<60)) Next:Next Do Inc t,0.025:g=0:Timer =0 For i=50 To 255 Step 5 b=0 a=r*i Math Slice f(),g,,c() Math Slice l(),g,,d() Box c(),d(),e(),e(),0,,0 For j=50 To 255 Step 5 p=i+v:q=a+x u=Sin(p)+Sin(q):v=Cos(p)+Cos(q) x=u+t:c(b)=w+u*o:d(b)=h+v*o Inc b Next Math Slice m(),g,,n() Box c(),d(),e(),e(),0,,n() Math Insert f(),g,,c() Math Insert l(),g,,d() Inc g Next i FRAMEBUFFER COPY f,N 'Print Timer Loop ps what's mmb4w? Edited 2024-01-15 01:51 by stanleyella |
||||
javavi Senior Member Joined: 01/10/2023 Location: UkrainePosts: 213 |
' Bubble Universe MODE 2 FRAMEBUFFER LAYER FRAMEBUFFER WRITE L RX=MM.HRes:RY=MM.VRes:CX=RX\2:CY=RY\2 r=(2*Pi)/25:x=0:v=0:t=0:SC=RY/4 Dim integer C(15) For i=0 To 15: Read C(i): Next i Data &H000000,&H0000FF,&H004000,&H0040FF Data &H008000,&H0080FF,&H00FF00,&H00FFFF Data &HFF0000,&HFF00FF,&HFF4000,&HFF40FF Data &HFF8000,&HFF80FF,&HFFFF00,&HFFFFFF Do :CLS co=1 For i=50 To 80 Step 2 For j=50 To 70 Step 1 u=Sin(i+v)+Sin(r*i+x) v=Cos(i+v)+Cos(r*i+x) x=u+t Pixel CX+u*SC,CY+v*SC,C(co) Next j Inc co: If co>15 Then co=1 Next i Inc t,.025 FRAMEBUFFER COPY L,N,B Loop |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
javavi got error- framebuffer layer error: cpuspeed=252000 for layers > option cpuspeed 378000 Error : CpuSpeed 126000, 252000 only > option list PicoMiteVGA MMBasic Version 5.08.00b5 OPTION SYSTEM I2C GP4,GP5 OPTION AUTORUN ON OPTION KEYBOARD US OPTION DISPLAY 20, 40 OPTION AUDIO GP0,GP1', ON PWM CHANNEL 0 > is this a duff rpi? |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
javavi- Changed cpuspeed and works brill.. very fast. Others should try it. nice one, stan |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6790 |
Top CPUSPEED on a VGA is 252, not 378. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
doh. probably says that somewhere.new to vga and never set cpuspeed on this. does this mean non vga can be faster than vga? |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
It depends on the program. If it's processor intensive then yes. If it is display intensive the VGA display is faster than a serial LCD. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6790 |
Yes, 378 is faster - and it's noticeably faster usually - but the increase is usually less than might be expected from the numbers. If there is any IO whatsoever (including memory access) many CPU(s) will have to slow down to the maximum speed of the IO channel(s). Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 509 |
This is my current fastest Bubble Universe, using VGA, but it also works fine on a LCD if you remove the "Mode 2"; it will update just over 2000 points at a rate of 267mS (at 378Mhz using an older version of VGA Picomite) otherwise it'll be about 400ms per update @ 252Mhz. Alternatively if you want more speed, increase the step size in the two main 'For' loops ("For i=" and or "For j=") For example changing the i loop to 'step 7' looks quite nice and updates at 5hz or 3.5Hz. Regards, Kevin. ' Bubble Universe MODE 2 Dim Float u(51),w(51),a,p,q,t,v=0,x=0 Dim Integer g,b,i,j,c(51),d(51),e(51),n(51),nn,dd Dim Integer f(13,41),l(13,41),m(26,41),y,z,cc,tt Const r=(2*Pi)/235,k=255,s=50 CLS RGB(black) t=Rnd*10:Math set 1,e() 't=1 nn=Peek(varaddr n()) dd=Peek(varaddr d()) cc=Peek(varaddr c()) For g=0 To 41 For b=0 To 51 Â n(b)=RGB(g*6,b*5,128*(g+b>30)*(g+b<60)) Â If g<26 And b<13 Then n(b)=RGB(0,128,0) Next Memory pack nn, Peek(varaddr m(0,g)),52,32 Next g Do Inc t,0.01:g=0':Print Timer:Timer =0 For i=50To 255Step 5 b=0:a=r*i z=Peek(varaddr f(0,g)):Memory unpack z,cc,52,16 y=Peek(varaddr l(0,g)):Memory unpack y,dd,52,16 Box c(),d(),e(),e(),0,,0'Pixel c(),d(),0 For j=50To 255Step 4:u(b)=Sin(i+v)+Sin(x):v=Cos(i+v)+Cos(x):x=u(b)+a+t:w(b)=v:Inc b:Next Math Scale u(),70,c():Math Scale w(),60,d() Math add c(),160,c():Math Add d(),120,d() Memory unpack Peek(varaddr m(0,g)),nn,52,32 Box c(),d(),e(),e(),0,,n()'Pixel c(),d(),n() Memory pack cc,z,52,16:Memory pack dd,y,52,16 Inc g Next Loop Edited 2024-01-15 22:58 by Bleep |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Wauw Kevin, You are the king. I have never seen this run on a picomite so fast... V50800RC3 at 252MHz. Volhout Edited 2024-01-15 23:01 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 509 |
:-) Most of the time is in the Sin and Cos functions, if there was a way of optimising those it could possibly be a lot faster. ;-) If you want to run it on an LCD it is worth increasing the size of the drawn box, so change the line 'Math set 1,e()' to use 2 or 3, it makes the points bigger and easier to see on the smaller screen. Regards, Kevin. |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1113 |
The values that uses SIN and COS in this Program are integers. So you can precalculate a "lookup Table" with all results of 0 to 359 dim Sin1(360),Cos1(360) for f=0 to 356:Sin1(f)=sin(f):Cos1(f)=Cos(f):next then replace the Sin and Cos in the Program with Sin1 and Cos1. if it is out of range, a MOD360 would help I have no Idea if this is faster ;-) 'no comment |
||||
javavi Senior Member Joined: 01/10/2023 Location: UkrainePosts: 213 |
Bubble Universe for PicoMiteVGA @252MHz color optimization added a little speed MODE 2 FRAMEBUFFER LAYER FRAMEBUFFER WRITE L RX=MM.HRes:RY=MM.VRes:CX=RX\2:CY=RY\2 r=(2*Pi)/25:x=0:v=0:t=0:SC=RY\4 Dim integer CV(15) For i=0 To 15: Read CV(i): Next i Data &H000000,&H0000FF,&H004000,&H0040FF Data &H008000,&H0080FF,&H00FF00,&H00FFFF Data &HFF0000,&HFF00FF,&HFF4000,&HFF40FF Data &HFF8000,&HFF80FF,&HFFFF00,&HFFFFFF Do :CLS :c=1  For i=50 To 80 Step 2   For j=50 To 100 Step 1    u=Sin(i+v)+Sin(r*i+x)    v=Cos(i+v)+Cos(r*i+x)    x=u+t    Pixel CX+u*SC,CY+v*SC   Next j   Inc c: If c>15 Then c=1   Colour CV(c)  Next i Inc t,.025 FRAMEBUFFER COPY L,N,B Loop Edited 2024-01-16 04:44 by javavi |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
For those wanting to run Bubble Universe at 378MHz on a PicoMiteVGA load this .OPT file. Remove or change any Options that don't suit your setup with: OPTION xxxxx DELETE Then load your options. PicoMiteVGA_5.08.00RC3_378MHz.zip > option list PicoMiteVGA MMBasic Version 5.08.00RC3 OPTION SYSTEM I2C GP6,GP7 OPTION COLOURCODE ON OPTION KEYBOARD US OPTION CPUSPEED (KHz) 378000 OPTION SDCARD GP13, GP10, GP11, GP12 OPTION RTC AUTO ENABLE OPTION COUNT GP2,GP3,GP4,GP5 Refer to Peter's reasons for limiting the speed to 252MHz. The use of certain new features may cause instability at 378MHz. Mainly, I think, things that make use of the second core. The above programs are working fine for me. |
||||
Print this page |