#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Craft example spheres

Posts: 8,449

Here’s something I threw together just to see what would happen. I found it kind of interesting, so I thought I’d share it. When the program starts, 300 random spheres move towards coords 0,0,0 . Once they collect there, you can tap the screen to shoot another sphere at them to cause a collision. You can keep tapping the screen to shoot more spheres. To restart the program, just tap the restart icon in the lower left of the screen. It doesn’t do a whole lot, but I thought someone else might find it interesting.

``````displayMode(FULLSCREEN)

function setup()
tab={}
assert(craft, "Please include Craft as a dependency")
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
scene.physics.gravity=vec3(0,0,0)
for z=1,300 do
create()
end
end

function draw()
update(DeltaTime)
scene:draw()
if not tch then
for a=1,#tab do
x,y,z=tab[a].x,tab[a].y,tab[a].z
tab[a].linearVelocity=vec3(-x/2,-y/2,-z/2)
end
end
v.rx=v.rx+.2
v.ry=v.ry+.2
end

function update(dt)
scene:update(dt)
end

function create()
size=math.random(40)/10
sphere=scene:entity()
s.restitution=1
sphere.position=vec3(math.random(-300,300),
math.random(-300,300),
math.random(-300,300))
sphere.model = craft.model.icosphere(size,2)
sphere.material = craft.material("Materials:Specular")
r,g,b=math.random(255),math.random(255),math.random(255)
sphere.material.diffuse=color(r,g,b)
table.insert(tab,{s,sphere})
end

function touched(t)
if t.state==BEGAN then
if not tch then
for z=1,#tab do
tch=true
tab[z].linearVelocity=vec3(0,0,0)
end
end
sp9=scene:entity()