
Code : Tout sélectionner
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coded with Purebasic v.6.04 by threedslider 01/27/2024
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A little of modification from Infratec and Fred, thank you all :)
; Updated for my smooth running, it works now !
EnableExplicit
Procedure spiral(move.f)
Protected.i mult
Protected.f multiplier, radius, spiral_x, spiral_y
multiplier = 500.0 * #PI
radius = 20.0
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glBegin_(#GL_LINE_STRIP)
For mult = 0 To 360
spiral_x = radius * Cos(((radius * move) / 7000) + multiplier) / 2
spiral_y = radius * Sin(((radius * move) / 7000) + multiplier) / 2
glColor3f_(mult / 10.0, mult / 100.0, mult / 100.0)
glVertex3f_(spiral_x * 0.3, spiral_y * 0.3 , 0.0)
radius = radius + 1.0
Next
glEnd_()
SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
EndProcedure
Define move.f, event.i
OpenWindow(1, 0, 0, 800, 600, "Spiral with complex color in OpenGL", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenGLGadget(0, 0, 0, 800, 600)
SetGadgetAttribute(0, #PB_OpenGL_SetContext, #True)
Define ScreenPixelWidth = DesktopScaledX(800)
Define ScreenPixelHeight = DesktopScaledY(600)
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(45.0, ScreenPixelWidth / ScreenPixelHeight, 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, ScreenPixelWidth, ScreenPixelHeight)
Repeat
If move < 10000
event = WindowEvent()
move + 0.5
spiral(move)
Else
event = WaitWindowEvent()
EndIf
Until event = #PB_Event_CloseWindow