Funny circles

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

Funny circles

Post by threedslider »

I have done in the past in the french forum so I share you as well :) :

Here my code :

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Created by threedslider 17/10/2023
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()
InitMouse()

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


Structure rond
  x.i
  y.i
  rayon.i
EndStructure


Myvar.rond

myvar\x = 10
myvar\y = 10
myvar\rayon = 5


Procedure Cercle(X, Y, *cl.rond)
  
  For n=0 To 1800
        cx = *cl\rayon * Cos(n)
        cy=  *cl\rayon * Sin(n)
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB(255,0,0)) 
      Next
EndProcedure   

Procedure sim(xx, yy, X1.i, Y1.i, iter)
  
  Myvar_other.rond
  
  myvar_other\x = 100
  myvar_other\y = 100
  myvar_other\rayon = 30
  
  For n=0 To 5
  
  d2 = Sqr((xx-myvar_other\x) * (xx-myvar_other\x) + (yy-myvar_other\y) * (yy-myvar_other\y))
  
  r2 = Sqr(myvar_other\rayon * myvar_other\rayon)
  
  in_d2 = Sqr((xx-x1)*(xx-x1) + (yy-y1)*(yy-y1))
   
    If d2*20 > r2 And in_d2*10 > r2
        myvar_other\rayon=Myvar_other\rayon-100/in_d2
        myvar_other\x = X1
        myvar_other\y = Y1
        Cercle(0,0,@myvar_other)      
       
       
     ; EndIf
      
;      Else
;        ;If d2 > r2
;         myvar_other\rayon =  30-n+2*2
;           ;myvar_other\x = xx
;          ;myvar_other\y =  yy
;          Cercle(0,0,@myvar_other)
;        ;EndIf
;        
        
   
   EndIf
 Next
 
 If iter > 0 ;And d2 > r2
     
     sim(xx, yy, X1+120, Y1, iter-1) 
  
 EndIf
    
EndProcedure
  

 ; Déplacement de la souris
  MouseLocate(0,0)  

Repeat
  ExamineKeyboard()
  Repeat 
    event = WindowEvent()
  Until event = 0

  ClearScreen(RGB(255,200,0))  
  
   
  ExamineMouse() ; Etat de la souris
  xm = MouseX()   ; Position en x de la souris                     
  ym = MouseY()   ; Position en y de la souris
  
  ;Debug x
  ;Debug y
  

  
 
  
  StartDrawing(ScreenOutput())
 
  For x = 0 To 4
   
    
    move.f  +  1/10000
    
      wave_x.f = Cos(x)  * 200
      
      wave_y.f =  Sin(x) * 200
      
      ;myvar\x = x+10
      ;myvar\y = y+10
      
       If xm < 3
        xm = 3
      Else
        If xm >750
          xm = 750
        EndIf
      EndIf
      
      If ym < 3
        ym = 3
      Else
        If ym > 550
          ym = 550
        EndIf
      EndIf
      
        
    cercle(xm,ym,@myvar)  
      
     sim(xm,ym, 100, 100+x*100, 5)

  Next
    
  StopDrawing()
  
    If  KeyboardPushed(#PB_Key_Escape)
      End
    EndIf
  
 FlipBuffers()
  
ForEver
End
User avatar
NicTheQuick
Addict
Addict
Posts: 1510
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Funny circles

Post by NicTheQuick »

It does nothing on my machine except 100% CPU usage. :D
Well, okay. It shows a few circles but nothing more.
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.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Funny circles

Post by SPH »

Not "very" nice ! 🤕

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Mr.L
Enthusiast
Enthusiast
Posts: 146
Joined: Sun Oct 09, 2011 7:39 am

Re: Funny circles

Post by Mr.L »

maybe you overcomplicate things a bit :wink:
here is a "slightly" modified version...

Code: Select all

InitSprite()
OpenWindow(0, 0, 0, 800,600, "Funny circles 2")
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)

Repeat
	mx = WindowMouseX(0)
	my = WindowMouseY(0)
	
	ClearScreen(RGB(255,200,0))  
	StartDrawing(ScreenOutput())
	DrawingMode(#PB_2DDrawing_Outlined)
	For y = 0 To 4
		For x = 0 To 5
			cx = 100 + x * 120
			cy = 60 + y * 120
			di.f = Sqr(Pow(cx - mx, 2) + Pow(cy - my, 2))
			If  di < 120
				scale.f = 1 - di / 120.0
				For i = 0 To 4
					Circle (cx, cy, Abs(30 - i * scale * 8), #Red)
				Next
			Else
				Circle (cx, cy, 30,#Red)
			EndIf
		Next
	Next
	Circle (mx, my, 5, #Red)
	StopDrawing()
	FlipBuffers()
	
	While WindowEvent()
		If Event() = #PB_Event_CloseWindow : End : EndIf
	Wend
ForEver
User avatar
Erolcum
User
User
Posts: 51
Joined: Fri Jun 07, 2024 10:45 am
Location: Turkiye
Contact:

Re: Funny circles

Post by Erolcum »

NicTheQuick wrote: Thu Aug 15, 2024 3:52 pm It does nothing on my machine except 100% CPU usage. :D
Well, okay. It shows a few circles but nothing more.
You need to go to the center of a circle with mouse, then gou out, then go in... it hypnotised me :D
You may visit my new Purebasic blog here..
:arrow: https://erolcum-github-io.translate.goo ... r_pto=wapp
User avatar
NicTheQuick
Addict
Addict
Posts: 1510
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Funny circles

Post by NicTheQuick »

Erolcum wrote: Sat Aug 17, 2024 8:05 pm
NicTheQuick wrote: Thu Aug 15, 2024 3:52 pm It does nothing on my machine except 100% CPU usage. :D
Well, okay. It shows a few circles but nothing more.
You need to go to the center of a circle with mouse, then gou out, then go in... it hypnotised me :D
If I had the chance to do that I would try it. But it didn't work until I tested the version from Mr.L which now runs fluently.
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: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Funny circles

Post by threedslider »

@Mr.L : Nice work :shock:

Yeah I am trying to make my own stuff from scratch :mrgreen: That mean it is more technical into this :lol:

Thank you.
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Funny circles

Post by threedslider »

NicTheQuick wrote: Sun Aug 18, 2024 2:44 pm If I had the chance to do that I would try it. But it didn't work until I tested the version from Mr.L which now runs fluently.
If you see my circles so it works well... Otherwise it will not show it :?
Post Reply