Lotto Machine simulation
Posted: Sun Sep 22, 2013 5:55 pm
Lotto machine simulation
make a transparent big sphere as a container with a hole in it, put inside it many small balls which have numbers from 0-9 . press space key to start the jumping balls,
the big spherical containder made using the Comtois procedure CreateSphere2 , because i want to make a hole in it http://purebasic.fr/english/viewtopic.p ... 15#p418885
now when you press space we move the bigSphere container up slightly. and this will push the balls giving them the power to jump, this depends on Restitution which are here 0.2 line 113 : EntityPhysicBody(100+i, #PB_Entity_SphereBody , 1, 0.2, 1)
now why these balls free energy continue, in my artistic Analysis the reason is this:
the bigSphere have a static physics (#PB_Entity_StaticBody) and it should not move, but when we press space key we moved it using MoveEntity up, so the bullet engine don't know what to do so it considers the bigSphere as vibrating between the original position and the current position after the push. change line 169 MoveEntity(#bigsphere,0,4,0) to MoveEntity(#bigsphere,0,7,0) and press space and you will see very powerful balls filling the bigSphere and it will penetrate the sphere walls rapidly, this is because the vibrating are more powerfull between the previous bigSphere position and the current one.
this is my theory
this is version 0.001, i have more ideas but for a future versions.

make a transparent big sphere as a container with a hole in it, put inside it many small balls which have numbers from 0-9 . press space key to start the jumping balls,
the big spherical containder made using the Comtois procedure CreateSphere2 , because i want to make a hole in it http://purebasic.fr/english/viewtopic.p ... 15#p418885
now when you press space we move the bigSphere container up slightly. and this will push the balls giving them the power to jump, this depends on Restitution which are here 0.2 line 113 : EntityPhysicBody(100+i, #PB_Entity_SphereBody , 1, 0.2, 1)
now why these balls free energy continue, in my artistic Analysis the reason is this:
the bigSphere have a static physics (#PB_Entity_StaticBody) and it should not move, but when we press space key we moved it using MoveEntity up, so the bullet engine don't know what to do so it considers the bigSphere as vibrating between the original position and the current position after the push. change line 169 MoveEntity(#bigsphere,0,4,0) to MoveEntity(#bigsphere,0,7,0) and press space and you will see very powerful balls filling the bigSphere and it will penetrate the sphere walls rapidly, this is because the vibrating are more powerfull between the previous bigSphere position and the current one.
this is my theory
this is version 0.001, i have more ideas but for a future versions.

Code: Select all
Declare CreateSphere2(No, mRadius, mNumRings, mNumSegments) ; ; the new CreateSphere2 procedure by Comtois changed in some parts, the Goto function added by me.
Enumeration
#Tex = 50
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA
#mainwin
#ball
#cube
#cube2
#cube3
#cube4
#bigSphere
EndEnumeration
Global Quit.b = #False
Global x.f = 0
Global y.f = 10
Global z.f = -30
Global zoom.f = 13
Global.f ro = -35, rotVal=1
Global ballNum.l
Speed = 0.5
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "space to start the machine, UP/Down to zoom _ version 0.001 , Z/A rotate camera ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-4, 0, 0, 0)
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
SetFrameRate(60)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
; transparent Texture from example CreateTextureAlpha.pb in Purebasic 3D folder
CreateTexture(#mat, 256, 256)
StartDrawing(TextureOutput(#mat))
DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_AlphaBlend)
Box(0, 0, 256, 256, RGBA(0, 0, 0, 255))
Box(0, 0, 256, 256, RGBA(100, 255, 0, 20))
;Circle(127, 127, 50, RGBA(0, 0, 0, 0))
StopDrawing()
CreateMaterial(#mat, TextureID(#mat))
MaterialBlendingMode(#mat, #PB_Material_AlphaBlend)
MaterialCullingMode(#MAT, #PB_Material_NoCulling)
DisableMaterialLighting(#mat, 1)
CreateMaterial(#MAT_plane, LoadTexture(#MAT_plane, "Geebee2.bmp"))
;CreatePlane(#Mesh, TileSizeX, TileSizeZ, TileCountX, TileCountZ, TextureRepeatCountX, TextureRepeatCountZ)
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane), 0, -1.5,-0.7)
RotateEntity(#plane, 6,0,0)
EntityPhysicBody(#plane, #PB_Entity_StaticBody )
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))
CreateCamera(#CAMERA, 0, 0, 400, 400)
MoveCamera(#CAMERA, 0, 4, 13)
RotateCamera(#CAMERA, -15, 0, 0)
;the mother of the jumping balls witch we will make 500 copies
CreateSphere(#ball, 1)
CreateEntity(#ball, MeshID(#ball),#PB_Material_None )
ScaleEntity(#ball, 0.1, 0.1, 0.1)
MoveEntity(#ball, 0,2,3)
EntityPhysicBody(#ball, #PB_Entity_SphereBody , 1, 0.3, 1)
;material for the jumping balls
LoadTexture(0, "white.jpg")
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, 1)
; make 9 textures
For i=1 To 9
CopyTexture(0,i)
CopyMaterial(0,i)
AddMaterialLayer(i, TextureID(i), #PB_Material_AlphaBlend )
Next
MaterialCullingMode(0, #PB_Material_NoCulling)
Font = LoadFont(#PB_Any, "Arial" , 72, #PB_Font_Bold)
ballNum.l ; assign numbers from 0 to 9 to the balls
;make 501 small balls and assign numbers from 0 to 9 to the balls
For i=0 To 500
CopyEntity(#ball , 100+i) ; entities numbering begins from 100
x.f = Random(1, 0)
y.f= Random(3, 0)
z.f = Random(2, 0)
StartDrawing(TextureOutput(ballNum))
DrawingFont(FontID(Font))
ballNum = ballNum+1
DrawText(0, 0, Str(ballNum), RGB(0, 0, 0),RGB(255, 255, 255))
If ballNum = 10: ballNum=0:EndIf
SetEntityMaterial(100+i, MaterialID(ballNum))
StopDrawing()
MoveEntity(100+i, x,y,z)
EntityPhysicBody(100+i, #PB_Entity_SphereBody , 1, 0.2, 1)
Next
CreateSphere2(#bigSphere, 3, 20, 20)
CreateEntity(#bigSphere, MeshID(#bigSphere), MaterialID(#MAT), 0,3.5,1 )
EntityPhysicBody(#bigSphere, #PB_Entity_StaticBody , 1, 2, 2)
CreateCube(#cube, 1)
CreateEntity(#cube, MeshID(#cube),#PB_Material_None, 0.7,-1.5,2)
ScaleEntity(#cube, 10,1,0.2)
RotateEntity(#cube,0,90,0)
CopyEntity(#cube, #cube2)
CopyEntity(#cube, #cube3)
MoveEntity(#cube2, -0.3,-1.5,2)
RotateEntity(#cube2, 0,90,0)
ScaleEntity(#cube3, 0.1,0.4,0.1)
MoveEntity(#cube3, 0,-1.7,4)
SetEntityMaterial(#cube3, MaterialID(#mat))
EntityPhysicBody(#cube, #PB_Entity_StaticBody )
EntityPhysicBody(#cube2, #PB_Entity_StaticBody )
EntityPhysicBody(#cube3, #PB_Entity_StaticBody )
EndIf
WorldGravity(-9.8)
;WorldGravity(0)
SkyBox("desert07.jpg")
;Main loop
Repeat
Event = WindowEvent()
rot.f+rotVal
RotateEntity(#bigSphere, rot,0,0)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
zoom-0.5
MoveCamera(#camera, 0,4, zoom, #PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Down)
zoom+0.5
MoveCamera(#camera, 0,4, zoom,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Z)
ro-0.5
RotateCamera(#camera,ro,0,0)
ElseIf KeyboardPushed(#PB_Key_A)
ro+0.5
RotateCamera(#camera,ro,0,0)
EndIf
If KeyboardReleased(#PB_Key_Escape)
Quit = #True
EndIf
If KeyboardReleased(#PB_Key_Space)
MoveEntity(#bigsphere,0,4,0)
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
; CreateSphere2 routines
Procedure Build(Radius, NumRings, NumSegments)
DeltaRingAngle.f = #PI / NumRings ; for full sphere
;DeltaRingAngle.f = #PI / NumRings/2 ; for half sphere
DeltaSegAngle.f = #PI*2 / NumSegments
offset = 0
For ring = 0 To NumRings
r0.f = Radius * Sin(ring * DeltaRingAngle)
y0.f = Radius * Cos(ring * DeltaRingAngle)
For seg = 0 To NumSegments;
x0.f = r0 * Sin(seg * DeltaSegAngle)
z0.f = r0 * Cos(seg * DeltaSegAngle)
MeshVertexPosition(x0, y0, z0)
MeshVertexNormal(x0, y0, z0); should be normalized if Radius <> 1
MeshVertexTextureCoordinate(seg / NumSegments, ring / NumRings)
If ring <> NumRings
;bypass the segments 0,1,20 to make a hole in the sphere
If (seg = 0 Or seg = 1 Or seg = 20 ) And ring = 1:Goto jmp:EndIf
If seg <> NumSegments
;If ring <> NumRings-1
If ring <> NumRings
MeshFace(offset + NumSegments + 2, offset, offset + NumSegments + 1)
EndIf
If ring <> 0
MeshFace(offset + NumSegments + 2, offset + 1, offset)
EndIf
EndIf
jmp:
offset + 1
EndIf
Next
Next
EndProcedure
Procedure CreateSphere2(No, Radius, NumRings, NumSegments)
CreateMesh(No)
Build(Radius, NumRings, NumSegments)
;AddSubMesh()
;Build(Radius, NumRings, NumSegments)
FinishMesh(#True)
UpdateMeshBoundingBox(0)
EndProcedure
DataSection
Data.i 255, 0, 0, 127
Data.f -20, 0, 5
Data.i 0, 0, 255, 127
Data.f 20, 0, 5
Data.i 0, 255, 0, 127
Data.f 0, 40, -5
EndDataSection
