IsPrime to detect the primes since it is speedy.
it is easy to implement:
plot the 3D spiral:
x = t*Cos(6*t)
y = t*Sin(6*t)
z = t
number = number + 1 : IsPrime(number): if prime color=green
MeshVertexPosition(x, y, z)
MeshVertexColor(RGB(red,green,blue))
let the spiral rotate until its wide mouth facing you then press space bar to stop rotation, then press Page_Down to zoom out so you can see a pattern like this:

zoom Page_Up to see the details of the spiral
note that you can save the mesh of the spiral, uncomment line 83 "SaveMesh(1, "spiral.mesh") and open it in a mesh viewer. but i don't know if the saved mesh have the vertex color info inside it or not. any way you can use the pure 3D shape
references: djes article "Prime numbers spiral exploration": http://www.purebasic.fr/english/viewtop ... 12&t=46476
http://www.mathematische-basteleien.de/spiral.htm
http://www.intmath.com/blog/golden-spiral/6512
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
Procedure IsPrime(Number.l)
n = Sqr(number)
For t = 2 To n
If number % t = 0
ProcedureReturn 0
EndIf
Next t
ProcedureReturn 1
EndProcedure
Quit.b = #False
stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD Zoom ..., space: stop/rotate ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
;OpenWindowedScreen(WindowID(#mainwin), 0, 0, 800, 600-70, 0, 0, 0)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
WorldShadows(#PB_Shadow_Additive)
InitKeyboard()
SetFrameRate(60)
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))
CreateCamera(#CAMERA_ONE, 0, 0, 100, 100)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)
RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
CreateTexture(0,16,16)
StartDrawing(TextureOutput(0))
Box(0, 0, 16, 16,RGB(255,255,255))
StopDrawing()
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static )
SetMeshMaterial(1, MaterialID(0))
For number = 0 To 100000
t.f+0.01
x = t*Cos(6*t)
y = t*Sin(6*t)
z = t
If IsPrime(number)
red=0:green=255:blue=0
Else
red=255:green=0:blue=0
EndIf
MeshVertexPosition(x, y, z)
MeshVertexColor(RGB(red,green,blue))
Next
NormalizeMesh(1)
FinishMesh(#True)
CreateEntity(1, MeshID(1), MaterialID(0))
ScaleEntity(1,0.1,0.1,0.1)
;MoveEntity(1,-2,1.5,-2)
MoveEntity(1,0,1,-2)
SaveMesh(1, "spiral.mesh")
turn.b=0: rot.f=0.5
Repeat
Event = WindowEvent()
y+rot
RotateEntity(1,0,y,0)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space)
If turn
rot=0.5
Else
rot=0
EndIf
turn ! 1
ElseIf KeyboardPushed(#PB_Key_PageUp) ; scale up model
xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
ScaleEntity(1,xs,ys,zs)
ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
xs = 0.9:ys = 0.9:zs= 0.9
ScaleEntity(1,xs,ys,zs)
EndIf
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindowPS2: i know now how to see the spiral.mesh. since it is produced from red and green colore. just texture it with a yellow color (red+green) and you will see exactly the same original pattern
something like this:
CreateTexture(0,16,16)
StartDrawing(TextureOutput(0))
Box(0, 0, 16, 16,RGB(255,255,0))
StopDrawing()
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, #True)
LoadMesh(#MESH, "spiral.mesh")
SetMeshMaterial(#MESH, MaterialID(0))
