Re: sunflower: filling the space tightly with seeds
Posted: Fri Sep 11, 2015 9:15 am
Hi IdeasVacuum, it is not derived, it is an experimental number to estimate visualy if the seeds with a certain radius are compact or not.IdeasVacuum wrote:
How is that 5.3 value derived?
in fact 5.3 are not necessary , i just have copied the code blindly and now i see that
Code: Select all
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
EndProcedureCode: Select all
Procedure floret(n.i)
r.f : ang.f : xc.f : yc.f
r = Sqr(n*golden)
ang = (n*golden)
xc = r*Cos(ang)/19
yc = r*Sin(ang)/19
z\x=xc : z\y=yc
EndProcedureand 20 are even better than 19
evidently and certainly there should be a simple formula in which one of its elements is the seed (sphere) radius to replace the number 19 so instead of experiments we then have a definitive value. it is may be a simple modification but i don't catch it now.
on the other hand i have found a good picture to describe the golden angle:

look http://www.math.smith.edu/phyllo/About/fibogolden.html
divide 360 by the golden mean (1.618)
360/1.618 = 222.496
360 - 222.496 = 137.503 which considered the golden angle
i have tried AttachEntityObject to attach the spheres to the first sphere instead of StaticGeometry, it is a simpler code but its FPS = 30 on my system, while in the previous code with staticGeometry it is 60. note the spheres Segments, Rings = 5x5 (CreateSphere(1,0.08, 5,5)) , so it is like a polygon, i have tried now 16,16 and it does not destroy the performance
Code: Select all
#sphere = 3
Structure coor
x.f
y.f
z.f
EndStructure
Global z.coor
Define.f KeyX , KeyY
#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 = Sqr(n*golden)
ang = (n*golden)
xc = r*Cos(ang)/19
yc = r*Sin(ang)/19
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(0,0.08, 5,5)
CreateEntity(0,MeshID(0),MaterialID(0))
For i=1 To 2000 ; number of objects
floret(i)
CreateEntity(i,MeshID(0),MaterialID(1))
MoveEntity(i, z\x, z\y, 0, #PB_Absolute)
AttachEntityObject(0, "", EntityID(i))
Next
CreateLight(0,RGB(255,255,255),-50,40,30)
AmbientColor(RGB(100,100,100))
;SkyBox("desert07.jpg")
angleY.f :dir.f = 1
;ShowCursor_(1)
Repeat
ExamineKeyboard()
;Event = WindowEvent()
If KeyboardPushed(#PB_Key_Up)
KeyY = -0.1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 0.1
Else
KeyY = 0
EndIf
angleY.f + 0.5*dir
If angleY >= 45
dir *-1
ElseIf angleY <= -45
dir = 1
EndIf
RotateEntity(0, 0, angleY, 0, #PB_Absolute)
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)
MoveCamera(0, KeyX, 0, KeyY)
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
EndIfAdded: #PB_Entity_DisableContactResponse and #PB_Entity_EnableContactResponse for SetEntityAttribute()
the spheres will still have weights and even joints but will not collide to each other or other objects.


