Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:01 02 Jun 2026 Privacy Policy
Jump to

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 : PicoMiteVGA DEMO

     Page 12 of 12    
Author Message
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 558
Posted: 04:49pm 26 Apr 2026
Copy link to clipboard 
Print this post

Rotating 2D sphere
with and without cache tracing

'Option TraceCache On 32

Const NumPoints = 500
Const Radius = 190
Const Dist = 500
Const X0 = MM.HRES\2
Const Y0 = MM.VRES\2

Dim x(NumPoints), y(NumPoints), z(NumPoints)
Dim angleX, angleY

For i=1 To NumPoints
phi=2*Pi*Rnd
theta=ACos(2*Rnd-1)
x(i)=Radius*Sin(theta)*Cos(phi)
y(i)=Radius*Sin(theta)*Sin(phi)
z(i)=Radius*Cos(theta)
Next

Colour RGB(Cyan)

Do
Inc angleX,.02
Inc angleY,.03
CLS : Print Timer: Timer =0

For i=1 To NumPoints
 ny=y(i)*Cos(angleX)-z(i)*Sin(angleX)
 nz=y(i)*Sin(angleX)+z(i)*Cos(angleX)
 nx=x(i)*Sin(angleY)+nz*Cos(angleY)

 finalZ=-x(i)*Sin(angleY)+nz*Cos(angleY)
 proj=dist/(dist-finalZ)
 Pixel X0+nx*proj,Y0+ny*proj
Next
Loop While Inkey$=""
 
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 558
Posted: 10:45am 02 May 2026
Copy link to clipboard 
Print this post

Rotating 2D sphere with Option TraceCache
Option TraceCache On 32
CLS
Dim N=600, R=200
Dim X(N), Y(N), Z(N)

For i=1 To N
TH=Pi*Rnd
PH=2*Pi*Rnd
X(i)=R*Sin(TH)*Cos(PH)
Y(i)=R*Sin(TH)*Sin(PH)
Z(i)=R*Cos(TH)
Next

AY=0.05: CY=Cos(AY): SY=Sin(AY)
AX=0.03: CX=Cos(AX): SX=Sin(AX)
OX=MM.HRES\2: OY=MM.VRES\2

Do
Timer =0
For i=1 To N
 If Z(i)>0 Then Pixel OX+X(i),OY+Y(i),0
 XT=X(i)*CY-Z(i)*SY:ZT=X(i)*SY+Z(i)*CY
 X(i)=XT:Z(i)=ZT
 YT=Y(i)*CX-Z(i)*SX:ZT=Y(i)*SX+Z(i)*CX
 Y(i)=YT: Z(i)=ZT
 If Z(i)>0 Then Pixel OX+X(i),OY+Y(i)
Next
Print @(0,0)Timer;
Loop While Inkey$=""
 
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 558
Posted: 11:07am 09 May 2026
Copy link to clipboard 
Print this post

"The Fragility of Being" by Sierpinsky

Const N=1023
Const SclX=N/MM.HRES
Const SclY=N/MM.VRES
Dim integer X,Y

Colour RGB(Green):CLS

For X=0 To N
 For Y=0 To N
   If X And Y Then Y=Y+(X And Y)\2
   Pixel (X+Y\2)/SclX,MM.VRES-Y/SclY
 Next
Next

Edited 2026-05-09 21:08 by javavi
 
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 558
Posted: 04:03pm 24 May 2026
Copy link to clipboard 
Print this post

Bubbler

Type Bubble
 x As INTEGER
 y As INTEGER
 r As INTEGER
 c As INTEGER
 s As INTEGER
End Type

Dim b(30) As Bubble

Dim c(15)=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
Colour Map c(),c()

For i=1 To 30
 b(i).x=Int(Rnd*MM.HRES)
 b(i).y=MM.VRES+Int(Rnd*200)
 b(i).r=10+Int(Rnd*20)
 b(i).c=c(1+Int(Rnd*14))
 b(i).s=1+Int(Rnd*4)
Next

Do
 For i=1 To 30
   Circle b(i).x, b(i).y, b(i).r,,,0,0
   b(i).y=b(i).y-b(i).s
   b(i).x=b(i).x+Int(Rnd*3)-1

   If b(i).y+b(i).r<0 Then
     b(i).x=Int(Rnd*MM.HRES)
     b(i).y=MM.VRES+b(i).r
     b(i).r=10+Int(Rnd*20)
     b(i).c=c(1+Int(Rnd*14))
     b(i).s=1+Int(Rnd*4)
   EndIf
   Circle b(i).x, b(i).y, b(i).r,,,b(i).c
   Circle b(i).x-Int(b(i).r/3), b(i).y-Int(b(i).r/3), Int(b(i).r/5)
 Next
Loop While Inkey$=""
 
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 558
Posted: 06:58pm 31 May 2026
Copy link to clipboard 
Print this post

Soap bubbles  

MODE 3
Dim c(15)=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
Colour Map c(),c()

Type Bubble
 x As INTEGER
 y As INTEGER
 dx As INTEGER
 dy As INTEGER
 r As INTEGER
 c As INTEGER
 act As INTEGER
 pop As INTEGER
End Type

Const maxBubbles = 20
Dim b(maxBubbles) As Bubble

For i=1 To maxBubbles
InitBubble(i)
Next

Do
 For i=1 To maxBubbles
   Circle b(i).x, b(i).y, b(i).r,,,0,0
   If b(i).act=1 Then
     b(i).x=b(i).x+b(i).dx
     b(i).y=b(i).y+b(i).dy
     If b(i).x-b(i).r<0 Or b(i).x+b(i).r>MM.HRES Then
       b(i).dx=-b(i).dx
     EndIf
     If b(i).y-b(i).r<0 Or b(i).y+b(i).r>MM.VRES Then
       b(i).dy=-b(i).dy
     EndIf
     For j=i+1 To maxBubbles
       If b(j).act=1 Then
         dist!=Sqr((b(i).x-b(j).x)^2+(b(i).y-b(j).y)^2)
         minDist!=b(i).r+b(j).r
         If dist!<minDist! Then
           t=b(i).dx: b(i).dx=b(j).dx: b(j).dx=t
           t=b(i).dy: b(i).dy=b(j).dy: b(j).dy=t
           If Int(Rnd*10)=0 Then
             b(i).act=2
             b(i).pop=5
           EndIf
         EndIf
       EndIf
     Next j

     If Int(Rnd*1000)=0 Then
       b(i).act=2
       b(i).pop=5
     EndIf
     Circle b(i).x, b(i).y, b(i).r,2,,b(i).c
     t=310-b(i).x\16
     Arc b(i).x, b(i).y, b(i).r-8,,t,50+t,b(i).c

   ElseIf b(i).act=2 Then
     For p=1 To 8
       angle!=p*0.785
       px=b(i).x+(b(i).r+(5-b(i).pop)*3)*Cos(angle!)
       py=b(i).y+(b(i).r+(5-b(i).pop)*3)*Sin(angle!)
       Pixel px,py,b(i).c
     Next p
     b(i).pop=b(i).pop-1
     If b(i).pop <=0 Then
       t=b(i).r*10: Play Tone t,t,20
       Circle b(i).x, b(i).y, b(i).r+15,,,0,0
       InitBubble(i)
     EndIf
   EndIf
 Next i
Loop While Inkey$=""

Sub InitBubble(i As INTEGER)
 b(i).r=Int(Rnd*40)+15
 b(i).x=Int(Rnd*(MM.HRES-2*b(i).r))+b(i).r
 b(i).y=Int(Rnd*(MM.VRES-2*b(i).r))+b(i).r
 b(i).dx=(Rnd*4)-2: If b(i).dx=0 Then b(i).dx=1
 b(i).dy=(Rnd*4)-2: If b(i).dy=0 Then b(i).dy=1
 b(i).c=c(Int(Rnd*14)+1)
 b(i).act=1
 b(i).pop=0
End Sub
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1456
Posted: 08:12am 01 Jun 2026
Copy link to clipboard 
Print this post

  Quote  Soap bubbles

Nice
'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5899
Posted: 08:20am 01 Jun 2026
Copy link to clipboard 
Print this post

Version that runs on RP2040 VGA

Volhout - RP2040 work around for mode 3, color map, added framebuffer to avoid screen flicker, and lowered number of bubbles to better fit 320x240 mode 2 screen, smaller bubbles.

'SOAP BUBBLES original Javavi 2026

 if instr("2350",mm.device$) then
   MODE 3
   Dim c(15)=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
   Colour Map c(),c()
 else
   mode 2
   dim c(15):For f%=1 To 15:Read c(f%):Next f%
 end if
 
 framebuffer create
 framebuffer write F

Type Bubble
 x As INTEGER
 y As INTEGER
 dx As INTEGER
 dy As INTEGER
 r As INTEGER
 c As INTEGER
 act As INTEGER
 pop As INTEGER
End Type
 
 Const maxBubbles = 5'20
 Dim b(maxBubbles) As Bubble
 
 For i=1 To maxBubbles
   InitBubble(i)
 Next
 
 Do
   For i=1 To maxBubbles
     Circle b(i).x, b(i).y, b(i).r,,,0,0
     If b(i).act=1 Then
       b(i).x=b(i).x+b(i).dx
       b(i).y=b(i).y+b(i).dy
       If b(i).x-b(i).r<0 Or b(i).x+b(i).r>MM.HRES Then
         b(i).dx=-b(i).dx
       EndIf
       If b(i).y-b(i).r<0 Or b(i).y+b(i).r>MM.VRES Then
         b(i).dy=-b(i).dy
       EndIf
       For j=i+1 To maxBubbles
         If b(j).act=1 Then
           dist!=Sqr((b(i).x-b(j).x)^2+(b(i).y-b(j).y)^2)
           minDist!=b(i).r+b(j).r
           If dist!<minDist! Then
             t=b(i).dx: b(i).dx=b(j).dx: b(j).dx=t
             t=b(i).dy: b(i).dy=b(j).dy: b(j).dy=t
             If Int(Rnd*10)=0 Then
               b(i).act=2
               b(i).pop=5
             EndIf
           EndIf
         EndIf
       Next j
       
       If Int(Rnd*1000)=0 Then
         b(i).act=2
         b(i).pop=5
       EndIf
       Circle b(i).x, b(i).y, b(i).r,2,,b(i).c
       t=310-b(i).x\16
       Arc b(i).x, b(i).y, b(i).r-8,,t,50+t,b(i).c
       
     ElseIf b(i).act=2 Then
       For p=1 To 8
         angle!=p*0.785
         px=b(i).x+(b(i).r+(5-b(i).pop)*3)*Cos(angle!)
         py=b(i).y+(b(i).r+(5-b(i).pop)*3)*Sin(angle!)
         Pixel px,py,b(i).c
       Next p
       b(i).pop=b(i).pop-1
       If b(i).pop <=0 Then
         t=b(i).r*10: Play Tone t,t,20
         Circle b(i).x, b(i).y, b(i).r+15,,,0,0
         InitBubble(i)
       EndIf
     EndIf
   Next i
   framebuffer copy F,N
 Loop While Inkey$=""
 
Sub InitBubble(i As INTEGER)
 b(i).r=Int(Rnd*40)+15
 b(i).x=Int(Rnd*(MM.HRES-2*b(i).r))+b(i).r
 b(i).y=Int(Rnd*(MM.VRES-2*b(i).r))+b(i).r
 b(i).dx=(Rnd*4)-2: If b(i).dx=0 Then b(i).dx=1
 b(i).dy=(Rnd*4)-2: If b(i).dy=0 Then b(i).dy=1
 b(i).c=c(Int(Rnd*14)+1)
 b(i).act=1
 b(i).pop=0
End Sub
 
 '--Colorscheme accordung to matherp
 Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED)
 Data RGB(MAGENTA),RGB(YELLOW),RGB(WHITE),RGB(MYRTLE)
 Data RGB(COBALT) ,RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST)
 Data RGB(FUCHSIA),RGB(BROWN),RGB(LILAC)

Edited 2026-06-01 18:22 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 12 of 12    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026