Howdy, Stranger!

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

Craft circles

dave1707dave1707 Mod
edited January 3 in Codea Craft Posts: 6,486

Not much going on, so I thought I’d post a simple Craft example. Use one finger to rotate, and two fingers to zoom in or zoom out or move.

displayMode(FULLSCREEN)

function setup()
    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(143, 194, 223, 255)
    skyMaterial.horizon=color(143, 223, 180, 255)
    scene.sun.rotation=quat.eulerAngles(20,45,-30)
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 80, 0, 300)
    calc()
end

function createSphere(x,y,z,r,g,b)
    sphere1=scene:entity()
    sphere1:add(craft.rigidbody,STATIC)
    sphere1.position=vec3(x*20,y*20,z*20)
    sphere1.model = craft.model.icosphere(.8,2)
    sphere1.material = craft.material("Materials:Specular")
    sphere1.material.diffuse=color(r,g,b)
end

function draw()
    update(DeltaTime)
    scene:draw()    
end

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

function calc()
    for a=1,360,2 do
        x=math.sin(math.rad(a))
        y=math.cos(math.rad(a))
        z=0
        createSphere(x,y,z,255,0,0)

        x=math.sin(math.rad(a))
        y=math.cos(math.rad(a))
        z=math.cos(math.rad(45))*y
        y=math.sin(math.rad(45))*y
        createSphere(x,y,z,0,255,0)

        x=math.sin(math.rad(a))
        y=math.cos(math.rad(a))
        z=math.cos(math.rad(135))*y
        y=math.sin(math.rad(135))*y
        createSphere(x,y,z,255,255,0)

        x=math.sin(math.rad(0))
        y=math.cos(math.rad(0))
        z=math.cos(math.rad(a))*y
        y=math.sin(math.rad(a))*y
        createSphere(x,y,z,0,0,255)

        x=math.sin(math.rad(a))
        y=math.cos(math.rad(a))
        z=math.cos(math.rad(0))*y
        y=math.sin(math.rad(0))*y
        createSphere(x,y,z,255,0,255)

        z=math.sin(math.rad(a))
        y=math.cos(math.rad(a))
        x=math.cos(math.rad(0))*y
        y=math.sin(math.rad(0))*y
        createSphere(x,y,z,255,255,255)

        z=math.sin(math.rad(a))
        x=math.cos(math.rad(a))
        y=math.cos(math.rad(0))*x
        x=math.sin(math.rad(0))*z
        createSphere(x,y,z,255,255,255)
    end
end
Sign In or Register to comment.