Funny cluster in spiral

Share your advanced PureBasic knowledge/code with the community.
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Funny cluster in spiral

Post by threedslider »

I show you a little nice effect and move your mouse and click with left button ;)

Here the code :

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Written in PB 6.20 by threedslider (05/2025)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()
InitMouse()

move.f = 0

Structure myround
  x.f
  y.f
  rayon.i
  r.f
  g.f
  b.f
EndStructure

Myvar.myround

myvar\x = 1.0
myvar\y = 1.0
myvar\rayon = 3
myvar\r = 0.0
myvar\g = 0.0
myvar\b = 0.0

Dim cc1.f(360)
Dim cc2.f(360)

Procedure lerp(*a.myround, *b.myround, c.f)
  Shared myvar.myround
  myvar\r = (*a\r + (*b\r - *a\r) * c)
  myvar\g = *a\g + (*b\g - *a\g) * c
  myvar\b = *a\b + (*b\b - *a\b) * c
EndProcedure

Procedure myCircle(X, Y, *cl.myround)
  
  Shared cc1()
  Shared cc2()
  
    For n=0 To 360
        cc1(n) = *cl\rayon * Cos(n)
        cc2(n)=  *cl\rayon * Sin(n)
    Next
      
  
  
  For n=0 To 360
              
        glPointSize_(2.0)
        
        glBegin_(#GL_POINTS)
        
        lerp(@red, @white, 0.5)
        
        glColor3f_(1.0, 0.0, 0.0)
        
        glVertex3f_(-25.0+cc1(n)+*cl\x+ X, 15.0+cc2(n)+*cl\y-Y, 0.0) 
        
        glEnd_()
        
      Next
EndProcedure  
    
Procedure mySim(X, Y, *cl.myround, iter)
  
  Shared move
  radius.f = 0.0
  Shared Myvar.myround
  
  Shared cc1()
  Shared cc2()
  
    For n=0 To 360
        cc1(n) = (*cl\rayon + radius*0.1) * Cos(n+move*iter)*iter
        cc2(n)=  (*cl\rayon + radius*0.1) * Sin(n+move*iter)*iter
        
        radius = radius + 1.0
    Next
      
  
  
  For n=0 To 360
              
        glPointSize_(2.0)
        
        glBegin_(#GL_POINTS)
        
        red.myround
        
        red\r = 1.0
        red\g = 0.0
        red\b = 0.0
        
        white.myround
        
        white\r = 1.0
        white\g = 1.0
        white\b = 1.0
        
        lerp(@red, @white, 0.8555)
        
        
        glColor3f_(myvar\r, myvar\g, myvar\b)
        
        glVertex3f_(-25.0+cc1(n)+*cl\x+ X, 15.0+cc2(n)+*cl\y-Y, 0.0) 
        
        glEnd_()
        

        
        
        
      Next
      
      If iter = 0
        iter = 0
      Else
        mySim(X, Y, @cl, iter-1)
      EndIf
      
     
EndProcedure  

OpenWindow(1, 0,0,800/DesktopResolutionX(),600/DesktopResolutionY(),"Funny cluster in spiral ", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800,600,0,0,0)


glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_() 
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(0, 0, -50)
glShadeModel_(#GL_SMOOTH)
glEnable_(#GL_LIGHT0)
glEnable_(#GL_LIGHTING)
glEnable_(#GL_COLOR_MATERIAL)
glEnable_(#GL_DEPTH_TEST)
glEnable_(#GL_CULL_FACE)   
glViewport_(0, 0, 800, 600)

glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)

glClearColor_(0.1, 0.1, 0.1, 0) ; background color

Repeat
  
  event = WindowEvent()
  ClearScreen(RGB(0,0,0))
  
   
  
   ExamineMouse()
   
   mpx.f = MouseX()
   mpy.f = MouseY()
   
   If mpx < 0
     mpx = 10
   EndIf
   
   If mpy < 0
     mpy = 10
   EndIf
   
   If mpx > 50
     mpx = 50
   EndIf
   
   If mpy > 30
     mpy = 30
   EndIf
    
   
   myCircle(mpx, mpy, @Myvar)
    
   radius + 1/1000
    
   If MouseButton(#PB_MouseButton_Left)
      move  +  1/10
         If move > 50
           move = 0.0
           move + 1/10
         EndIf
      mySim(mpx,mpy, @myvar, 30)
    EndIf
    
         
     
 
  ExamineKeyboard()
 FlipBuffers()
  
Until event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End



However it is a bit strange for movement of mouse not smoothly and I don't know why :|

Enjoy !
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Funny cluster in spiral

Post by Caronte3D »

threedslider wrote: Sat May 17, 2025 7:43 pm However it is a bit strange for movement of mouse not smoothly and I don't know why :|
Change:

Code: Select all

Procedure myCircle(X, Y, *cl.myround)
for:

Code: Select all

Procedure myCircle(X.f, Y.f, *cl.myround)
You forget the type in the parameters variables, :wink:
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Funny cluster in spiral

Post by threedslider »

Thanks a lot ! :shock:
User avatar
NicTheQuick
Addict
Addict
Posts: 1517
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Funny cluster in spiral

Post by NicTheQuick »

I don't see anything on Linux. Is there a bug in Purebasic because it's the second time in the last weeks that I check out graphical examples from the forum where it just shows a black screen.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Funny cluster in spiral

Post by threedslider »

@NicTheQuick : Have you seen the red circle on screen ?
User avatar
NicTheQuick
Addict
Addict
Posts: 1517
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Funny cluster in spiral

Post by NicTheQuick »

threedslider wrote: Tue May 20, 2025 6:43 pm @NicTheQuick : Have you seen the red circle on screen ?
No. As I said. It's just a black screen and the mouse is centered on the screen.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Funny cluster in spiral

Post by threedslider »

Ok I think it is a bug on Linux and Window works fine here :?

Sorry I don't know how to fix that on Linux .... :|
BarryG
Addict
Addict
Posts: 4168
Joined: Thu Apr 18, 2019 8:17 am

Re: Funny cluster in spiral

Post by BarryG »

The mouse just sticks to each side of the window when I move it? It doesn't go in the center or anything.
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Funny cluster in spiral

Post by threedslider »

@NickTheQuick : maybe remove at the line 57 -> lerp(@red, @white, 0.5), is it working for you ?
User avatar
NicTheQuick
Addict
Addict
Posts: 1517
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Funny cluster in spiral

Post by NicTheQuick »

threedslider wrote: Wed May 21, 2025 2:28 pm @NickTheQuick : maybe remove at the line 57 -> lerp(@red, @white, 0.5), is it working for you ?
No. That makes no difference. It's something different. I at least got the background color working when I enable `AutoStretch` in `OpenWindoedScreen()`.
But then it is just black or whatever color I define for `ClearScreen()` and nothing else. But I also had to properly write the event loop like this:

Code: Select all

	Repeat
		event = WindowEvent()
		Select event
			Case #PB_Event_CloseWindow
				Break 2
		EndSelect
	Until event = 0
It is essential to always retrieve all the available events or else in the next iteration of the loop there will again be new ones and then you never can process all of them.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply