Page 1 of 1

Something wrong with Static

Posted: Thu Mar 24, 2016 7:17 pm
by Comtois
This code work fine with 1.20 and dont work with 1.30 , This is probably due to static, but I do not know how to highlight (comment le mettre en évidence)

Code: Select all

;*****************************************************************************
;*
;* Name   : Dots
;* Author : Petr Vavrin (peterb)
;* Date   : 15.06.09
;* Notes  :
;*
;* Adaptation SpiderBasic Comtois , le 28/02/16
;*****************************************************************************
Macro SinCos(a,b)
  (Sin(a)+Cos(b))
EndMacro
 
#p=#PI/180
#n=0.001
 
Global Dim x(99)
Global Dim y(99)
Global Dim v.f(99)
Global Dim w(99)
Global Size=400
InitSprite()
OpenWindow(0,0,0,Size,Size,"",$C80001)
 
 
OpenWindowedScreen(WindowID(0),0,0,Size,Size,1,0,0)
CreateSprite(0,Size,Size)

CreateSprite(1,32,32,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(1))
  Circle(16,16,16, RGB(255,0,0))
StopDrawing()

 
Procedure RenderFrame()
  Static.f a,b,c,e,f,g,i
  Static h=99,k=99, s.f=20
 
  If h=k
    e=Random(k)
    f=Random(k)
    g=Random(k)
    i=s-Random(50)
    h=0
  EndIf
  h+1
  a.f+#n*e
  b.f+#n*f
  c.f+#n*g
  s-i/k
  x(0)=SinCos(a,b)*30+Size/2
  y(0)=SinCos(b,a)*30+Size/2
  v(0)=c
  w(0)=s
  l=30
  nb=1
  While l
    n=l-1
    x(l)=x(n)
    y(l)=y(n)
    v(l)=v(n)
    w(l)=w(n)
    m=0
    While m<360
      t.f=m*#p+v(l)
      u.f=#p-v
      DisplayTransparentSprite(1,x(l)+SinCos(t,u)*w(l),y(l)+SinCos(u,t)*w(l),255-(l*8))
      Nb + 1
      m+60
    Wend
    l-1
  Wend
 
  FlipBuffers() ; continue the rendering
EndProcedure
 
FlipBuffers() ; start the rendering
BindEvent(#PB_Event_RenderFrame, @RenderFrame())

Re: Something wrong with Static

Posted: Tue Mar 29, 2016 10:24 pm
by mahan
Suggestions:
  1. Try using EnableExplicit, work out all the declarations, and see if you find any problem.
  2. Reduce complexity, until you pinpoint the problem.
Remember: A good bug report is the minimal program that exhibits the issue.

Re: Something wrong with Static

Posted: Wed Mar 30, 2016 12:18 pm
by ChrisM
It all worked OK for me after I Installed the free version of 1.30 - but only after I re-booted my Win10 PC/Firefox 45.0.1.

It looks and behaves like Petr Vavrin's (peterb) original PB code:
http://www.purebasic.fr/english/viewtop ... 9&start=64

Re: Something wrong with Static

Posted: Wed Mar 30, 2016 1:56 pm
by Comtois
Thank you for your answers.
I am very confused, many of my code no longer worked with 1.30. And I have perhaps not posted one who posed (haved ?) most problems.
After a few more tests, it seems that the problem is due the way i was loading sprites (worked with 1.20 not with 1.30).
I'll have to change my code to follow the SpiderBasic's examples and it should probably solve my problems. I will come back with new code.

Maybe version 1.30 is less tolerant ?

About the code, yes the author is mentioned on top.

Code: Select all

;*****************************************************************************
;*
;* Name   : Dots
;* Author : Petr Vavrin (peterb)
;* Date   : 15.06.09

Re: Something wrong with Static

Posted: Thu Mar 31, 2016 10:47 am
by ChrisM
I added the link as it really helped me with understanding your translation to SpiderBasic. I have come from a BASIC that is far away and I thought the link may help other newcomers. This is a really fascinating and flexible language.

I haven't had any problems with your code on 1.3 Free - it has been very interesting to play with SpiderBasic. Just to begin to understand it more I have changed lots of the code but it has exactly the same core elements. It would be interesting to hear if this runs on your system. Please understand that this is my first attempt at SpiderBasic coding and so it may not be very elegant! With all the Random elements the display could take a little time to become as interesting as the original..

Code: Select all

;*****************************************************************************
;*
;* Name   : Dots
;* Author : Petr Vavrin (peterb)
;* Date   : 15.06.09
;* Notes  : http://www.purebasic.fr/english/viewtopic.php?f=12&t=37609&start=64
;*
;* Adaptation SpiderBasic Comtois , le 28/02/16
;* Adaptation SpiderBasic ChrisM , on 31/03/16 1.3 Free Win10 Firefox 45.0.1
;*****************************************************************************

  Enumeration Sprites
    #sBox
    #sDot
  EndEnumeration
  
Macro SinCos(a,b)
  (Sin(a)+Cos(b))
EndMacro
 
Global Dim x(20)
Global Dim y(20)
Global Dim v.f(20)
Global Dim w(20)
Global WinX       =600
Global WinY       =600
Global SpriteX    =WinX/10
Global SpriteY    =WinY/10
Global SpriteR    =SpriteX/2
Global Sprite     
Global SpriteNo   =1
Global TrailCount =20
Global Fade       =255/(TrailCount-1)
Global Angle      =(360/SpriteNo)
Global Speed      =5
Global Gap.f      =Speed*0.00025
Global Radians.f  =#PI/180

InitSprite()

EnableJS
  document.title = "Boxes & Dots"
DisableJS

OpenWindow(0,0,0,WinX,WinY,"Boxes & Dots",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,WinX,WinY,1,0,0,#PB_Screen_WaitSynchronization)
ClearScreen(RGB(255, 0, 0)) 

CreateSprite(#sBox,SpriteX,SpriteY,#PB_Sprite_AlphaBlending)  ;Draw Box Sprite
StartDrawing(SpriteOutput(#sBox))
  Box(0,0,SpriteX,SpriteY, RGB(255,255,255))                  ; white outline
  Box(1,1,SpriteX-2,SpriteY-2, RGB(255,0,0))                  ; red square
StopDrawing()
 
CreateSprite(#sDot,SpriteX,SpriteY,#PB_Sprite_AlphaBlending)  ;Draw Dot Sprite
StartDrawing(SpriteOutput(#sDot))
  Circle(SpriteR,SpriteR,SpriteR, RGB(255,255,255))           ; white outline
  Circle(SpriteR,SpriteR,SpriteR-1, RGB(255,0,0))             ; white circle
StopDrawing()

FlipBuffers() ; start the rendering

Procedure RenderFrame()
  Static.f a,b,c,e,f,Rotation,i
  Static h=99,k=99,s.f=20
  Static RandomSprite=#sBox
  
  Select Random(2000) ; random change of background colour
    Case 10
      ClearScreen(RGB(248, 248, 248))
    Case 20
      ClearScreen(RGB(255, 0, 0))
  EndSelect   
  
  If h=k
   Select Random(1,10) ; random change of drawing parameters
     Case 1,7
       e=Random(k):f=Random(k):Rotation=Random(k)
      Case 2
        e=90:f=40:Rotation=40
      Case 3
        e=10:f=40:Rotation=60
      Case 4
        e=70:f=70:Rotation=70
      Case 5
        e=120:f=90:Rotation=30
      Case 6
        e=30:f=10:Rotation=10
   EndSelect 
   
   If Random(1)=1   ; random change to reverse the rotation  
      Rotation=-Rotation
   EndIf
    
    i=s-Random((WinX+WinY)/6)
    h=0
  EndIf
  
  h+1
  a+Gap*e
  b+Gap*f
  c+Gap*Rotation
  s-i/k
  
  x(0)=(WinX-SpriteX)/4.5+SinCos(a,b)*60
  y(0)=(WinY-SpriteY)/2+SinCos(b,a)*60
  v(0)=c
  w(0)=s
  
  For Layer=TrailCount To 0 Step -1
    x(Layer)=x(Layer-1)
    y(Layer)=y(Layer-1)
    v(Layer)=v(Layer-1)
    w(Layer)=w(Layer-1)
    
    If Random(20000)=1 And SpriteNo<9     ;increase sprites up to 8 total
      SpriteNo+1
    EndIf
    If Random(20000)=1 And SpriteNo>1     ;decrease sprites down to 1 minimum
      SpriteNo-1
    EndIf
    
    If Random(10000)=1 And RandomSprite=#sBox ;change Sprite to render
      RandomSprite=#sDot
    EndIf
    If Random(10000)=1 And RandomSprite=#sDot 
      RandomSprite=#sBox
    EndIf
    
    Angle=(360/SpriteNo)
    
    For Sprite=1 To SpriteNo
      t.f=Sprite*Angle*Radians+v(Layer)
      u.f=Radians-v
      DisplayTransparentSprite(RandomSprite,x(Layer)+SinCos(t,u)*w(Layer),y(Layer)+SinCos(u,t)*w(Layer),255-(Layer*Fade))
    Next Sprite
  Next Layer
   
  FlipBuffers() ; continue the rendering
EndProcedure

BindEvent(#PB_Event_RenderFrame, @RenderFrame())