Here’s a variation on my 3D Bézier code above.
displayMode(FULLSCREEN)
function setup()
pos=0
tab1={}
assert(craft, "Please include Craft as a dependency")
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
skyMaterial=scene.sky.material
skyMaterial.sky=color(158, 202, 223, 255)
skyMaterial.horizon=color(98, 166, 114, 255)
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 450, 0, 1000)
v.ry=90
val=300
for z=1,20 do
x1=math.random(-val,val)
y1=math.random(-val,val)
z1=math.random(-val,val)
x2=math.random(-val,val)
y2=math.random(-val,val)
z2=math.random(-val,val)
bezier()
end
r,g,b=255,0,0
createSphere(0,0,-150,15)
createSphere(0,0,150,15)
r,g,b=255,255,255
createSphere(tab1[1].x,tab1[1].y,tab1[1].z,10)
end
function draw()
update(DeltaTime)
scene:draw()
fill(255)
text("Slide your finger around the screen to rotate the image.",WIDTH/2,HEIGHT-25)
text("Use two fingers to zoom in, out or to move the image.",WIDTH/2,HEIGHT-50)
if pos<#tab1 then
pos=pos+1
else
pos=1
end
mv.position=vec3(tab1[pos].x,tab1[pos].y,tab1[pos].z)
end
function update(dt)
scene:update(dt)
end
function bezier()
local tab1={}
x={0,0}
y={0,0}
z={-150,150}
dir=not dir
a,b,c=0,1,.01
if dir then
a,b,c=1,0,-.01
end
for t=a,b,c do
xt = (1-t)^3 * x[1] + 3 * t * (1-t)^2 * x1 + 3 * t^2 * (1-t) * x2 + t^3 * x[2]
yt = (1-t)^3 * y[1] + 3 * t * (1-t)^2 * y1 + 3 * t^2 * (1-t) * y2 + t^3 * y[2]
zt = (1-t)^3 * z[1] + 3 * t * (1-t)^2 * z1 + 3 * t^2 * (1-t) * z2 + t^3 * z[2]
table.insert(tab1,vec3(xt,yt,zt))
end
r=math.random(255)
g=math.random(255)
b=math.random(255)
for z=1,#tab1 do
createSphere(tab1[z].x,tab1[z].y,tab1[z].z,2)
end
end
function createSphere(x,y,z,size)
local pt=scene:entity()
pt1=pt:add(craft.rigidbody,STATIC)
pt.position=vec3(x,y,z)
pt.model = craft.model.icosphere(size,2)
pt:add(craft.shape.sphere,size)
pt.material = craft.material("Materials:Specular")
pt.material.diffuse=color(r,g,b)
if size==2 then
table.insert(tab1,vec3(x,y,z))
elseif size==10 then
mv=pt
end
end