sunflower: filling the space tightly with seeds
Posted: Mon Jul 13, 2015 10:47 am
i have stumbled over a good algorithm to plot a sun flower seeds arrangement here http://www.thinbasic.com/community/show ... L-geometry
the sunflower arranges its seeds in that it is generated by the "golden angle" = 137.508 = 2.3999 radians , change the golden angle a little and you will not get a space filling spheres, try it. increase the number of spheres to 20000 to be sure the spheres are still compact or not.
thinbasic is an interpreter which is using a kind of opengl wrapper for graphics, i remake it here with staticGeometry to draw more spheres .
i get FPS = 60 until 20000 spheres, with 30000 the fps = 50 , with 50000 the fps degrade to 30. note that the spheres are 5X5 (Segments, Rings). the camera are following a blue sphere so gives an illusion that the sun_flower spheres are waving
the sunflower arranges its seeds in that it is generated by the "golden angle" = 137.508 = 2.3999 radians , change the golden angle a little and you will not get a space filling spheres, try it. increase the number of spheres to 20000 to be sure the spheres are still compact or not.
thinbasic is an interpreter which is using a kind of opengl wrapper for graphics, i remake it here with staticGeometry to draw more spheres .
i get FPS = 60 until 20000 spheres, with 30000 the fps = 50 , with 50000 the fps degrade to 30. note that the spheres are 5X5 (Segments, Rings). the camera are following a blue sphere so gives an illusion that the sun_flower spheres are waving
Code: Select all
#sphere = 3
Structure coor
x.f
y.f
z.f
EndStructure
Global z.coor
#golden_angle = 137.508
Global golden.f = Radian(#golden_angle); = 2.3999 also = golden_angle*PI/180
Procedure floret(n.i)
r.f : ang.f : xc.f : yc.f
r =(5.3 * Sqr(n*golden))
ang = (n*golden)
xc = r*Cos(ang)/100
yc = r*Sin(ang)/100
z\x=xc : z\y=yc
EndProcedure
If InitEngine3D()
InitMouse()
InitKeyboard()
InitSprite()
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "Up/Down to zoom in/out", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
Add3DArchive(".",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures\",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\GUI",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
Global monitor=CreateSprite(#PB_Any,120,40)
CreateCamera(0,0,0,100,100)
CameraBackColor(0,RGB(0, 0, 0))
MoveCamera(0,0,0,10)
CreateLight(0,RGB(255, 255, 95),-50,50,100)
CreateMaterial(0,TextureID(LoadTexture(#PB_Any,"ground_diffuse.png")))
CreateMaterial(1,TextureID(LoadTexture(#PB_Any,"Geebee2.bmp")))
CreateSphere(1,0.08, 5,5)
CreateEntity(1,MeshID(1),MaterialID(1))
CreateStaticGeometry(23,10000,10000,10000,#False)
For i=1 To 2000 ; number of objects
floret(i)
AddStaticGeometryEntity(23,EntityID(1), z\x, z\y, 0, 1,1,1)
Next
BuildStaticGeometry(23)
FreeEntity(1)
CreateSphere(#sphere, 0.07) ;the guide of the CameraFollow
CreateEntity(#sphere, MeshID(#sphere), MaterialID(0))
MoveEntity(#sphere,0,0,0)
CreateLight(0,RGB(255,255,255),-50,40,30)
AmbientColor(RGB(100,100,100))
;SkyBox("desert07.jpg")
Global Height.f = 0
Global dist.f = 10
;ShowCursor_(1)
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
dist - 0.03
ElseIf KeyboardPushed(#PB_Key_Down)
dist + 0.03
EndIf
MoveEntity(#sphere, 0.03, 0, 0.0, #PB_Local)
RotateEntity(#sphere, 0, 0, 0.6, #PB_Relative)
CameraFixedYawAxis(0, 1, 0,1,0 )
;CameraFollow(#Camera, ObjectID, Angle, Height, Distance, RotationPercent, PositionPercent [, Mode])
CameraFollow(0, EntityID(#sphere) , 0, Height ,dist, 1, 1, #True )
;CameraLookAt(0, EntityX(#sphere), EntityY(#sphere), EntityZ(#sphere))
CameraLookAt(0, 0,0,0)
RenderWorld()
StartDrawing(SpriteOutput(monitor))
DrawText(5,5,"FPS : "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
DrawText(5,20,"Tris : "+StrF(Engine3DStatus(#PB_Engine3D_NbRenderedTriangles)))
StopDrawing()
DisplaySprite(monitor,0,0)
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
EndIf
