With legends miracles seem trivial.
Omg, VirtualNomad *jaw drops* thats just perfect !
// The fibonacci sphere algorithm
// Created: 2022-01-16
// Have fun :)
//////////////////
// Display properties
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
SetClearColor(0,0,0)
SetErrorMode(2)
// Fog
SetFogMode(1)
SetFogColor(0,0,255)
SetFogRange(1,20)
SetSunActive(1)
SetAmbientColor(0,255,255)
// Cam pos
SetCameraPosition(1,0,0,-3)
SetCameraRotation(1,0,0,0)
SetCameraLookAt( 1, 0,0,0,0 )
//////////////////
// Math functions
#constant pi = 3.14159 // Pi
#constant samples = 1000 // Number of points
#constant rspeed = 0.8 // Sphere rotation speed
global sequence = 1 // Sequence number
global rangel = 3 // Turn sphere
global sphere // Sphere
global rcolor = 0 // runningcolor
//////////////////
// Variables
global dim points [ samples ]
//////////////////
// Create sphere
sphere = CreateObjectSphere(0,0,0)
SetObjectVisible(sphere,0) // hide sphere center
SetObjectPosition(sphere,0,0,0) // hide sphere position
//////////////////
// Create Fibonacci sphere
_fibonaccisphere ()
//////////////////
// Main loop
do
// Disp controls
print("The fibonacci sphere algorithm")
Print("Rotate sphere with arrowkeys")
Print("Press enter to create next pattern")
Print("Press Backspace to go back")
Print("Press escape to exit")
Print(sequence) // Display current pattern number
// Running color
if rcolor < samples
rcolor = rcolor + 1
SetObjectColor(points[rcolor],0,0,255,255)
elseif rcolor = samples
// next pattern
_nextp ()
endif
// Controls
_controls ()
Sync()
loop
//////////////////
// The Fibonacci sphere algorithm
function _fibonaccisphere ()
for i = 1 to samples
y# = 1.0 - (i/(samples-1.0)) * 2.0 // Y# goes from 1 to -1
radius# = SQRT(1-y#*y#) // Radius at y position
theta# = pi * sequence * i // Golden angle increment
x# = SIN(theta#) * radius# // Magic cross position math
z# = COS(theta#) * radius# // Magic cross position math
points[i] = CreateObjectSphere(0.02,0.02,0.02) // Create a sphere
FixObjectToObject(points[i],sphere) // Fix sphere to center sphere
SetObjectColor(points[i],0,255,255,255) // Set color of points
SetObjectTransparency(points[i],2) // Make dot transparent-
SetObjectPosition(points[i],x#,y#,z#) // Set object pos on calculated position
next i
endfunction
//////////////////
// controls
function _controls ()
// Detect if key pressed and react accordingly
if GetRawKeyState(38) // Up key
rangel = 1
elseif GetRawKeyState(40) // Down key
rangel = 2
elseif GetRawKeyState ( 37 ) // Right key
rangel = 3
elseif GetRawKeyState( 39 ) // Left key
rangel = 4
elseif GetRawKeyPressed(13) // Enter key
_nextp ()
elseif GetRawKeyPressed(8) // Backspace key
_previousp ()
elseif GetRawKeyState(27) // Escape key
End
endif
// Current rotation direction
select rangel
case 1
RotateObjectLocalZ(sphere, rspeed)
endcase
case 2
RotateObjectLocalZ(sphere, - rspeed)
endcase
case 3
RotateObjectLocalY(sphere, rspeed)
endcase
case 4
RotateObjectLocalY(sphere, - rspeed)
endcase
endselect
endfunction
//////////////////
// next pattern
function _nextp ()
sequence = sequence + 1 // Next number
_loadsphere()
endfunction
//////////////////
// previous pattern
function _previousp ()
sequence = sequence - 1 // Prev number
_loadsphere()
endfunction
//////////////////
// load pattern
Function _loadsphere()
for i = 1 to samples
DeleteObject(points[i]) // Delete all dots
next i
rangel = 3 // Reset rotation
SetObjectRotation(sphere, 0, 0, 0 ) // Reset sphere angel
rcolor = 0 // Reset running color
_fibonaccisphere () // Create new pattern
endfunction
Thank you @VirtualNomad
“I try all things, I achieve what I can.”
― Herman Melville, Moby-Dick or, the Whale