3D rect

Its not totally 3D… Hopfully 0.2 will have fully 3D rect!

– 3D Rect simulator

function setup()

--The parameters to translate our rect

parameter.integer("RotationZ", 0, 700)

parameter.integer("Angle", 0, 700)

parameter.boolean(“KeepRotating”)

parameter.boolean(“KeepZRotating”)

end

function draw()

background(40, 40, 50)

if KeepRotating == true then

    Angle = Angle + 1

end

if KeepZRotating == true then

    RotationZ = RotationZ + 1

end

strokeWidth(3)–The stroke of our rectangle(i thought i could do outlines while your translating it)

rotate(Angle, 400, 500, RotationZ) --translates our rectangle using parameters

fill(255, 0, 0, 255)

rect(400, 500, 100, 100)

end

@Code_maker I’m not sure what you were trying to do. Here’s an example of a 3D rect rotating.


supportedOrientations(PORTRAIT)

function setup()
    parameter.integer("R",-360,360, -170)
    parameter.number("x",0,1,.5)
    parameter.number("y",0,1,.5)
    parameter.number("z",0,1,.5)
    parameter.integer("sizex", 0, 50, 20)
    parameter.integer("sizey", 0, 50, 20)
    parameter.integer("sizez", 0, 50, 20)
end

function draw()
    background(0, 0, 0, 255)
    perspective(50,WIDTH/HEIGHT)
    camera(-200,0,0,0,0,0,0,1,0)
    rotate(R,x,y,z)
    cube(0,0,0,sizex,sizey,sizez)
end

function cube(x,y,z,w,h,d)
    local cube = mesh()
    
    local v = { vec3(x-w,y-h,z+d),vec3(x-w,y+h,z+d),
                vec3(x+w,y-h,z+d),vec3(x+w,y+h,z+d),
                vec3(x-w,y-h,z-d),vec3(x-w,y+h,z-d),
                vec3(x+w,y-h,z-d),vec3(x+w,y+h,z-d) }
       
    local faces = { v[1],v[2],v[3],v[2],v[3],v[4],
                    v[2],v[4],v[6],v[4],v[6],v[8],
                    v[1],v[2],v[5],v[2],v[5],v[6],
                    v[3],v[4],v[7],v[4],v[7],v[8],
                    v[1],v[3],v[5],v[3],v[5],v[7],
                    v[5],v[6],v[7],v[6],v[7],v[8] } 
                    
    local c = { color(255, 0, 0, 255), color(0, 255, 0, 255), 
                color(255, 243, 0, 255), color(0, 0, 255, 255), 
                color(255, 255, 255, 255), color(255, 0, 189, 255)}  
                  
    local colors = {}
    for i = 1, 6 do
        for j = 1, 6 do
        table.insert(colors, c[i])
        end
    end    
    cube.vertices = faces
    cube.colors = colors
    cube:draw()
end