Abstract rotation with color

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

Abstract rotation with color

Post by threedslider »

New for abstract rotation with color ! :mrgreen:

I use the plot with circles and rotation, it is quite fast enough and more various :wink: But sometime it shows black and other abstracts as well.

Recently I don't have used PB so much cause I work to my C++ too :shock:

Here the code that i share you as always :

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Created by threedslider 21/01/2025
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

InitSprite()
InitKeyboard()
InitMouse()

OpenWindow(1, 0,0,(800*2)/DesktopResolutionX(),(600*2)/DesktopResolutionY(),"abstract rotation with color", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800*2,600*2,0,0,0)


Structure color_3_f
  r.f
  g.f
  b.f
EndStructure

Structure color_3_i
  r.i
  g.i
  b.i
EndStructure


tri.color_3_f

tri\r = 1.0
tri\g = 1.0
tri\b = 1.0

tri2.color_3_f

tri2\r = 1.0
tri2\g = 0
tri2\b = 0

tri3.color_3_i

tri3\r = 0
tri3\g = 0
tri3\b = 0

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


Myvar.rond

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

Myvar2.rond

myvar2\x = 10
myvar2\y = 10
myvar2\rayon = 0

resultx.i = 0
resulty.i = 0

move.f = 0

f_move_circle.f = 0
max_move.f = 0
color_change.i = 0
rnd.i = 90
  

Procedure lerp(*a.color_3_f, *b.color_3_f, t.f)
  Shared tri3.color_3_i
  
  tri3\r = Int((*a\r + ( *b\r - *a\r) * t) * 255.999) 
  tri3\g = Int((*a\g + ( *b\g - *a\g) * t) * 255.999) 
  tri3\b = Int((*a\b + ( *b\b - *a\b) * t) * 255.999) 
EndProcedure

  
Procedure myCircle(X, Y, *cl.rond, rot, *col.color_3_i)
  
  Shared f_move_circle
  Shared rnd

  For n=0 To rot
    If rnd > 85 And rnd <= 90
        cx = *cl\rayon * Cos(n/rnd) * Sin(f_move_circle+n*rnd)
        cy=  *cl\rayon * Sin(n*4*rnd) * Cos(f_move_circle-n*rnd)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 75 And rnd < 85
        cx = *cl\rayon * Cos(n*Cos(rnd)*2*rnd)
        cy=  *cl\rayon * Sin(n*Cos(n*2)/rnd*n*rnd) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 65 And rnd < 75
        cx = *cl\rayon * Cos(rnd*n*4*Sin(n*rnd))
        cy=  *cl\rayon * Sin(rnd*n*4*Cos(n*rnd)) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 55 And rnd < 65
        cx = *cl\rayon * Cos(n*n*rnd*f_move_circle)
        cy=  *cl\rayon * Sin(n*n*rnd*f_move_circle) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 45 And rnd < 55
        cx = *cl\rayon * Cos(n*rnd) * Cos(n-rnd-100)
        cy=  *cl\rayon * Sin(n*rnd) * Cos(n+rnd+100)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 35 And rnd < 45
        cx = *cl\rayon * Cos(n/rnd*n) * Sin(n)
        cy=  *cl\rayon * Sin(n*rnd) * Cos(Sin(n)*n)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 25 And rnd < 35
        cx = *cl\rayon * Cos(n*rnd*f_move_circle)
        cy=  *cl\rayon * Sin(n*rnd*f_move_circle) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 15 And rnd < 25
        cx = *cl\rayon * Cos(n*rnd) * Sin(Cos(f_move_circle))
        cy=  *cl\rayon * Sin(n*rnd) * Cos(f_move_circle)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 0 And rnd < 15
        cx = *cl\rayon * Cos(n*rnd)
        cy=  *cl\rayon * Sin(n*rnd) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
    EndIf
  Next
      
EndProcedure   
    
Procedure Circle_rotation(X, Y, iter, c_rot.f)
  
  Shared Myvar2.rond
  Shared f_move_circle 
  Shared rnd
  Shared tri.color_3_f
  Shared tri2.color_3_f
  Shared tri3.color_3_i

  If f_move_circle <= 1.0
    lerp(@tri, @tri2, f_move_circle)
  EndIf

    myCircle(X, Y, @Myvar2, c_rot, @tri3)

  If iter > 0 And c_rot > 0.0 

        While c < rnd 
          
          If iter > 0

            Myvar2\rayon = f_move_circle*5.0 * c
          Else
            Myvar2\rayon = 5.0
          EndIf
          
          Circle_rotation(Exp((f_move_circle*5-c)/100)*Cos(f_move_circle*5+c)*100+X, Exp((f_move_circle*5-c)/100)*Sin(f_move_circle*5+c)*100+Y, iter-1, c_rot-1)
          c = c+1
          
      Wend

 EndIf

EndProcedure  


Repeat
  
  Repeat 
    event = WindowEvent()
     Select event
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until event = 0
  
  ExamineKeyboard()
  
  ClearScreen(RGB(0,0,0))  
  
  StartDrawing(ScreenOutput())
 
    move.f  +  1/1000
    
      wave_x.f = Cos(x)  * 200
      
      wave_y.f =  Sin(x) * 200
      
      
       If xm < 3
        xm = 3
      Else
        If xm >790*2
          xm = 790*2
        EndIf
      EndIf
      
      If ym < 3
        ym = 3
      Else
        If ym > 590*2
          ym = 590*2
        EndIf
      EndIf
  
      
      max_move = 10.0
  
      f_move_circle + 1/700.0
      
      If f_move_circle <= max_move 

        
        
        If move <= 1.0
          Circle_rotation(380*2, 300*2, 1, 3600)
          move = 0.0
        EndIf
        
        
      EndIf
      
      If f_move_circle > 1.0
         
        rnd = Random(90)
        
        tri\r = Random(10000) / 10000.0
        tri\g = Random(10000) / 10000.0
        tri\b = Random(10000) / 10000.0
        
        
        tri2\r = Random(10000) / 10000.0
        tri2\g = Random(10000) / 10000.0
        tri2\b = Random(10000) / 10000.0
        
        
        f_move_circle = 0.0
      Else
        f_move_circle = f_move_circle
      EndIf
  
  StopDrawing()
  
    If  KeyboardPushed(#PB_Key_Escape) Or Quit = #True
      End
    EndIf
  
 FlipBuffers()

ForEver
End
What do you think of my new code ?

Happy coding !
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Abstract rotation with color

Post by SPH »

Nothing :|

!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
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Abstract rotation with color

Post by threedslider »

What is nothing ? Please you could be more clear at this ? Is it work for you or not ? Have you seen this abstract shape ?
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 192
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: Abstract rotation with color

Post by moulder61 »

It works OK for me in Linux.

It looks a bit like a slow explosion. Kind of mesmerising. :shock:

It disappeared for a while, but it must have been using black on a black background, so waiting for a minute brought it back.

It makes a nice screensaver. :D

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Abstract rotation with color

Post by threedslider »

moulder61 wrote: Tue Jan 21, 2025 12:19 pm It works OK for me in Linux.

It looks a bit like a slow explosion. Kind of mesmerising. :shock:

It disappeared for a while, but it must have been using black on a black background, so waiting for a minute brought it back.

It makes a nice screensaver. :D

Moulder.
Thanks a lot for your input, yeah the black is a problem but now I have fixed that ! :D

Edit : fixed typo in color for tri structure !

Here the code :

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Created by threedslider 21/01/2025
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Fixed the show black sometime so not black screen anymore :)
;; Argh ! fixed typo in color for tri structure, sorry !

InitSprite()
InitKeyboard()
InitMouse()

OpenWindow(1, 0,0,(800*2)/DesktopResolutionX(),(600*2)/DesktopResolutionY(),"abstract rotation with color", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(1),0,0,800*2,600*2,0,0,0)


Structure color_3_f
  r.f
  g.f
  b.f
EndStructure

Structure color_3_i
  r.i
  g.i
  b.i
EndStructure


tri.color_3_f

tri\r = 1.0
tri\g = 1.0
tri\b = 1.0

tri2.color_3_f

tri2\r = 1.0
tri2\g = 0
tri2\b = 0

tri3.color_3_i

tri3\r = 0
tri3\g = 0
tri3\b = 0

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


Myvar.rond

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

Myvar2.rond

myvar2\x = 10
myvar2\y = 10
myvar2\rayon = 0

resultx.i = 0
resulty.i = 0

move.f = 0

f_move_circle.f = 0
max_move.f = 0
color_change.i = 0
rnd.i = 90
  

Procedure lerp(*a.color_3_f, *b.color_3_f, t.f)
  Shared tri3.color_3_i
  
  tri3\r = Int((*a\r + ( *b\r - *a\r) * t) * 255.999) 
  tri3\g = Int((*a\g + ( *b\g - *a\g) * t) * 255.999) 
  tri3\b = Int((*a\b + ( *b\b - *a\b) * t) * 255.999) 
EndProcedure

  
Procedure myCircle(X, Y, *cl.rond, rot, *col.color_3_i)
  
  Shared f_move_circle
  Shared rnd

  For n=0 To rot
    If rnd > 85 And rnd <= 90
        cx = *cl\rayon * Cos(n/rnd) * Sin(f_move_circle+n*rnd)
        cy=  *cl\rayon * Sin(n*4*rnd) * Cos(f_move_circle-n*rnd)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 75 And rnd < 85
        cx = *cl\rayon * Cos(n*Cos(rnd)*2*rnd)
        cy=  *cl\rayon * Sin(n*Cos(n*2)/rnd*n*rnd) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 65 And rnd < 75
        cx = *cl\rayon * Cos(rnd*n*4*Sin(n*rnd))
        cy=  *cl\rayon * Sin(rnd*n*4*Cos(n*rnd)) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 55 And rnd < 65
        cx = *cl\rayon * Cos(n*n*rnd*f_move_circle)
        cy=  *cl\rayon * Sin(n*n*rnd*f_move_circle) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 45 And rnd < 55
        cx = *cl\rayon * Cos(n*rnd) * Cos(n-rnd-100)
        cy=  *cl\rayon * Sin(n*rnd) * Cos(n+rnd+100)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 35 And rnd < 45
        cx = *cl\rayon * Cos(n/rnd*n) * Sin(n)
        cy=  *cl\rayon * Sin(n*rnd) * Cos(Sin(n)*n)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 25 And rnd < 35
        cx = *cl\rayon * Cos(n*rnd*f_move_circle)
        cy=  *cl\rayon * Sin(n*rnd*f_move_circle) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 15 And rnd < 25
        cx = *cl\rayon * Cos(n*rnd) * Sin(Cos(f_move_circle))
        cy=  *cl\rayon * Sin(n*rnd) * Cos(f_move_circle)
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
        ElseIf  rnd > 0 And rnd < 15
        cx = *cl\rayon * Cos(n*rnd)
        cy=  *cl\rayon * Sin(n*rnd) 
        
        Plot(cx+*cl\x+ X,cy+*cl\y+Y,RGB((*col\r),(*col\g),*col\b) )
        
    EndIf
  Next
      
EndProcedure   
    
Procedure Circle_rotation(X, Y, iter, c_rot.f)
  
  Shared Myvar2.rond
  Shared f_move_circle 
  Shared rnd
  Shared tri.color_3_f
  Shared tri2.color_3_f
  Shared tri3.color_3_i

  If f_move_circle <= 1.0
    lerp(@tri, @tri2, f_move_circle)
  EndIf

    myCircle(X, Y, @Myvar2, c_rot, @tri3)

  If iter > 0 And c_rot > 0.0 

        While c < rnd 
          
          If iter > 0

            Myvar2\rayon = f_move_circle*5.0 * c
          Else
            Myvar2\rayon = 5.0
          EndIf
          
          Circle_rotation(Exp((f_move_circle*5-c)/100)*Cos(f_move_circle*5+c)*100+X, Exp((f_move_circle*5-c)/100)*Sin(f_move_circle*5+c)*100+Y, iter-1, c_rot-1)
          c = c+1
          
      Wend

 EndIf

EndProcedure  


Repeat
  
  Repeat 
    event = WindowEvent()
     Select event
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until event = 0
  
  ExamineKeyboard()
  
  ClearScreen(RGB(0,0,0))  
  
  StartDrawing(ScreenOutput())
 
    move.f  +  1/1000
    
      wave_x.f = Cos(x)  * 200
      
      wave_y.f =  Sin(x) * 200
      
      
       If xm < 3
        xm = 3
      Else
        If xm >790*2
          xm = 790*2
        EndIf
      EndIf
      
      If ym < 3
        ym = 3
      Else
        If ym > 590*2
          ym = 590*2
        EndIf
      EndIf
  
      
      max_move = 10.0
  
      f_move_circle + 1/700.0
      
      If f_move_circle <= max_move 

        
        
        If move <= 1.0
          Circle_rotation(380*2, 300*2, 1, 3600)
          move = 0.0
        EndIf
        
        
      EndIf
      
      If f_move_circle > 1.0
         
        rnd = Random(90)
        
        tri\r = Random(10000) / 10000.0
        tri\g = Random(10000) / 10000.0
        tri\b = Random(10000) / 10000.0
        
        
        tri2\r = Random(10000) / 10000.0
        tri2\g = Random(10000) / 10000.0
        tri2\b = Random(10000) / 10000.0
        
        If rnd = 0
          rnd = 5
        EndIf
        
        If tri\r = 0.0 And tri\g = 0.0 And tri\b = 0.0
          tri\r = 0.3 
          tri\g = 0.3 
          tri\b = 0.3 
        EndIf
        
         If tri2\r = 0.0 And tri2\g = 0.0 And tri2\b = 0.0
          tri2\r = 0.3 
          tri2\g = 0.3 
          tri2\b = 0.3 
        EndIf          
       
        f_move_circle = 0.0
      Else
        f_move_circle = f_move_circle
      EndIf
  
  StopDrawing()
  
    If  KeyboardPushed(#PB_Key_Escape) Or Quit = #True
      End
    EndIf
  
 FlipBuffers()

ForEver
End
I hope to everyone can see now the abstract shapes :wink:
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Abstract rotation with color

Post by SPH »

threedslider wrote: Tue Jan 21, 2025 2:27 am What do you think of my new code ?
Nothiiiing :|

!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
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Abstract rotation with color

Post by threedslider »

SPH wrote: Tue Jan 21, 2025 2:01 pm Nothiiiing :|
Oh right, well you think it is good or bad ?
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Abstract rotation with color

Post by SPH »

Plutot... naz :twisted:

!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
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Abstract rotation with color

Post by Paul »

Kinda cool. Still has some that are to dark to see or don't do to much.

Here's a video for guys like SPH that don't seem to have a very good graphic card :lol:
https://youtu.be/wQf9_EGDzuk
Image Image
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Abstract rotation with color

Post by Denis »

Like Paul says : Kinda cool!

Win 11 Pro x64
Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz 2.90 GHz
Intel UHD 630 graphics card
RAM 32 Gb
A+
Denis
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Abstract rotation with color

Post by threedslider »

SPH wrote: Tue Jan 21, 2025 11:21 pm Plutot... naz :twisted:
Lol
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Abstract rotation with color

Post by threedslider »

thanks a lot to @Paul and @Denis if you find cool ! :mrgreen:
Post Reply