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 Demo
Page 1 of 2 | |||||
Author | Message | ||||
Goksteroo Senior Member Joined: 15/03/2021 Location: AustraliaPosts: 110 |
I found this little bit of basic code on Discord (Bubbles Demo and converted it to MMBasic. The result on my PC with MMB4W is spectacular. The code should run in any version of MM Basic's hardware - just need to change the mode it is to run in. mode 11 'change to suit your monitor/hardware and MMB version cls rgb(black) n=255 r=(2*pi)/235 x=0 'y=0 v=0 t=0 sz=200 s=0 scrw=mm.hres scrh=mm.vres sw=scrw/sz sh=scrh/sz offset=scrh/4.5 do page write 1 cls for i=50 to n for j=50 to n u=sin(i+v)+sin(r*i+x) v=cos(i+v)+cos(r*i+x) x=u+t pixel scrw/2+u*offset,scrh/2+v*offset,rgb(i,j,100) next j next i t=t+.025 page copy 1 to 0,B loop uTube Video (washed out colours!) |
||||
OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 875 |
Like to check out the video but it is reporting it is private. OA47 |
||||
scruss Regular Member Joined: 20/09/2021 Location: CanadaPosts: 79 |
Here's a video that is public for the BBC BASIC version to give you the idea: Bubble Universe |
||||
Goksteroo Senior Member Joined: 15/03/2021 Location: AustraliaPosts: 110 |
OOps... public video now |
||||
Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 321 |
Thanks Goksteroo! Nice. By commenting out (removing) following lines in your program: -mode 11 'change to suit your monitor/hardware and MMB version -page write 1 and -page copy 1 to 0,B it works on PicoMite (cheaper black module with WS2812 LED on board). Not tested with the "standard" green RP2040 modules. > option list PicoMite MMBasic Version 5.07.05RC8 OPTION SYSTEM SPI GP18,GP19,GP16 OPTION FLASH SIZE 4194304 OPTION CPUSPEED (KHz) 378000 OPTION DISPLAY 50, 91 OPTION LCDPANEL ST7789_320, LANDSCAPE,GP17,GP20,GP21 Fred |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 367 |
Tested it on the PICO, impressive! |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3807 |
Very pretty . Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3422 |
Amazing ! So few lines of code, such a beautiful result. This has similar magic as "mandelbrot" and "life". Too bad the pico cannot produce color in 640x480. This would be what the researchers at CERN observe,,, Volhout Edited 2022-11-15 23:38 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Goksteroo Senior Member Joined: 15/03/2021 Location: AustraliaPosts: 110 |
Add this little bit of code to the above between the lines in bold: t=t+.025 select case k page copy 1 to 0,Bcase 128 inc scrh,-4 case 129 inc scrh,4 case 130 inc scrw,-4 case 131 inc scrw,4 case 65,97 inc offset,4 case 90,122 inc offset,-4 end select ... to add zoom with [A] and [Z] and move display with the arrow keys. note: no error checking!! |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3641 |
Looks like k is never set. INKEY or some such? John |
||||
Goksteroo Senior Member Joined: 15/03/2021 Location: AustraliaPosts: 110 |
Yeh.... I'm blaming a bad copy and paste.... k=keydown(1) goes immediately before the above code. As agent 86 would say..."Missed it by that much." |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 1567 |
works on picomite lcd https://www.youtube.com/watch?v=9hnGAgYMIv0 |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 400 |
Hi, I've optimised this code for a LCD display, it now runs at approx 2Hz on a Pico running at 378MHz. I've reduced the number of plotted pixels, each pixel is drawn, then at the next iteration un_drawn, rather than doing a complete screen clear, I've also made them larger, to be more visible on a small screen, it's still managing to display about 1700 point per screen update. Bubble video Unfortunately it does make the code more unreadable. :-( ' Bubble Universe Dim Float u,y,a,b,p,q,s,g,v=0, z=0, t=0, x=0 Dim Integer i,j,tt,c(41),d(41),e(41),f(41),l(41),m(41) Const w=MM.HRes/2, h=MM.VRes/2, o=h/2, n=255 Const k=RGB(black), r=(2*Pi)/235 CLS RGB(black):Backlight 95 Math Add m(),3,m():t=Rnd*10':tt=t+3 Do g=t:Inc t,0.025 For i=50 To n Step 5 b=0 For j=50 To n Step 5 a=r*i:p=i+z:q=a+y u=Sin(p)+Sin(q):z=Cos(p)+Cos(q) y=u+g:f(b)=w+u*o:l(b)=h+z*o 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 e(b)=RGB(i,j,130):Inc b,1 Next Box f(),l(),m(),m(),0,,k Box c(),d(),m(),m(),0,,e() Next i Loop ' Until t>tt Edited 2022-11-21 20:29 by Bleep |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3422 |
Hi Bleep, Why are you calculating the f() and l() coordinates ? Could you copy them from c() and d() ? Using MATH ADD c(),0,f() Volhout PicomiteVGA PETSCII ROBOTS |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 400 |
Hi Volhout, You could, but you would then only get 41 pixels at any one time. Currently it calculates 41x41 (i&j) in the for loops, which then progressively update 41 pixels at a time. I did look at saving all the points in an array, but the array used to much memory, because all variables use 64bits only, I also looked at saving 2 or 4 smaller integers in each array element by masking & shifting, but even then the array was too big, though that was before I reduced the number of pixels displayed, so may now be possible, but may not gain a huge amount, because of the slowness of the serial data transfer to the display. Regards Kevin. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 1567 |
I changed CLS RGB(black)'Backlight 95 and it runs continuously but the original looked nicer imho. I commented the second cls in the do loop and version 1 runs continuously. Edited 2022-11-22 02:31 by stanleyella |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 400 |
Hi Volhout, Here you go, it is very fractionally faster, but still basically 2Hz update, however the two arrays use up 28kB of memory, in theory the update should be smoother as it now updates a pixel at a time. ' Bubble Universe Dim Float u,a,p,q,t,v=0, x=0 Dim Integer b,i,j,c(1764),d(1764) Const w=MM.HRes/2, h=MM.VRes/2 Const r=(2*Pi)/235, o=h/2 Backlight 95:CLS RGB(black) t=Rnd*10 Do Inc t,0.025:b=0 For i=50 To 255 Step 5 For j=50 To 255 Step 5 Box c(b),d(b),3,3,0,,0 a=r*i: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 Box c(b),d(b),3,3,0,,RGB(i,j,130):Inc b,1 Next Next i Loop |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8516 |
Doesn't this now assume that the "pixel" you are zeroing doesn't sit where a new pixel has been previously placed? Here is my version 375mSec per update @ 378MHz ' Bubble Universe Dim Float u,a,p,q,t,v=0, x=0 Dim Integer b,i,j,c(1764),d(1764),e(1764),f(1764),cc(1764),dd(1764) Math set 3,e() Const w=MM.HRes/2, h=MM.VRes/2 Const r=(2*Pi)/235, o=h/2 Backlight 95:CLS RGB(black) t=Rnd*10 Timer =0 b=0 For i=50 To 255 Step 5 For j=50 To 255 Step 5 f(b)=RGB(i,j,130) Inc b Next j Next i Do Print Timer Timer =0 Inc t,0.025:b=0 For i=50 To 255 Step 5 a=r*i 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:cc(b)=u*o+w:dd(b)=v*o+h Inc b Next Next Box c(),d(),e(),e(),0,,0 Box cc(),dd(),e(),e(),0,,f() Math scale cc(),1,c() Math scale dd(),1,d() Loop Edited 2022-11-22 04:04 by matherp |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 1567 |
ili version cls rgb(black) n=255:r=(2*pi)/235:x=0:v=0:t=0:sz=200:s=0:sw=scrw/sz:sh=scrh/sz:offset=scrh/4.5 scrw=320 'mm.hres scrh=240 'mm.vres do for i=50 to n for j=50 to n u=sin(i+v)+sin(r*i+x) v=cos(i+v)+cos(r*i+x) x=u+t pixel scrw/2+u*offset,scrh/2+v*offset,rgb(i,j,100) next j next i t=t+.025 loop |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 400 |
Smarty Pants ;-) Yes there will be a small number that get overwritten, but hopefully this is minimal, I certainly don't notice it. However I definitely missed the fact that 'a' was being calculated in the wrong place and the fact that the colours could be pre-calculated. :-( The reason I was doing it incrementally was to stop the fact that the whole pattern disappears and is then re-drawn, each iteration, I wanted it to look more fluid. I've modified mine, to include the moved 'a' calculation and pre-calculated the colours, so it's improved to 480mS, still not as good as yours, but over a 50mS improvement on my previous. Thanks :-) Any other tips? Regards, Kevin. Edited 2022-11-22 04:30 by Bleep |
||||
Page 1 of 2 |
Print this page |