Bleep
 Guru
 Joined: 09/01/2022 Location: United KingdomPosts: 798 |
| Posted: 05:54pm 22 Apr 2026 |
|
|
|
Sorry another one :-( Because the TraceCache works with If statments, I converted the Case statment in the below code to a If, ElseIf.... type structure, when I run it without the TraceCache it works fine, stars of various colours, when I enable the TraceCache, 'Almost' all the stars are Blue, as though it is defaulting to the Else statment at the end, strangely there are a few yellow stars? I did try making the Else a ElseIf stz(st) >= 0.8 but then almost all the stars were white, no Blue or Cyan PS, it was considerably faster with the If, ElseIf, than the Case, so that bit works, assuming it's not faster because it's always defaulting to the Else statment? Kevin.
'set mode here if appropriate 'Option TraceCache On 32 MODE 3 'change maxst for more or fewer stars Dim Integer maxst=1250,h=MM.VRES,w=MM.HRES,x,y,st,c Dim Float f,stx(maxst),stxx(maxst),sty(maxst),styy(maxst),stz(maxst) Dim Integer ox(maxst),oy(maxst),oxl(maxst),oyl(maxst),cl(maxst),s(maxst) 'FRAMEBUFFER create 'FRAMEBUFFER write f CLS 'initialise the stars For st=0 To maxst stxx(st)=(Rnd*w>>1)-(w>>2):styy(st)=(Rnd*h>>1)-(h>>2) stz(st)=Int(Rnd*5+5)/10 cl(st)=RGB(White) Next 'initialise array for box size Math Set 2,s()
Do 'move stars forward Math Add stz(),-0.025,stz() 'do the calculation (stx/stz)+half width Math C_div stxx(),stz(),stx():Math Add stx(),w>>1,stx() 'do the calculation (sty/stz)+half height Math C_div styy(),stz(),sty():Math Add sty(),h>>1,sty() 'reset rouge stars 'Inc c:c=c*(c<=maxst) Inc c:If c>maxst Then c=0 'stx(c)=stx(c)*(stz(c)>0.1) If stz(c)<0 Then stx(c)=0 'loop for all stars 'set star colour and check for star off screen For st=0 To maxst x=stx(st):y=sty(st) ' Select Case stz(st) ' Case < 0.2 ' cl(st)=&HFFFF00'RGB(Yellow) ' Case < 0.6 ' cl(st)=&HFFFFFF'RGB(White) ' Case < 0.8 ' cl(st)=&HFFFF'RGB(Cyan) ' Case Else ' cl(st)=&HFF'RGB(Blue) ' End Select If stz(st) < 0.2 Then cl(st)=&HFFFF00'RGB(Yellow) ElseIf stz(st) < 0.6 Then cl(st)=&HFFFFFF'RGB(White) ElseIf stz(st) < 0.8 Then cl(st)=&HFFFF'RGB(Cyan) Else cl(st)=&HFF'RGB(Blue) EndIf
If (x>0 And x<w And y>0 And y<h)Then ox(st)=x:oy(st)=y Else Inc f,0.025:If f>0.09 Then f=0 stxx(st)=(Rnd*w>>1)-(w>>2) styy(st)=(Rnd*h>>1)-(h>>2) stz(st)=Int(Rnd*5+5)/10+f EndIf Next 'blank out last times stars, replace with new stars ' Pixel oxl(),oyl(),0:Pixel ox(),oy(),cl() Box oxl(),oyl(),s(),s(),0,,0:Box ox(),oy(),s(),s(),0,,cl() 'copy this times stars, to last times stars array Math Add ox(),0,oxl():Math add oy(),0,oyl() ' FRAMEBUFFER copy f,n,b Print Timer:Timer =0 Loop Edited 2026-04-23 04:00 by Bleep |