Cube Designer 1.0

I bet you never thought I could do this, well HA! I DID IT! Muahahahaha! I’m kidding.

WARNING: PLEASE PASTE INTO PROJECT FOR FULL COMPATIBILITY

Features:
-A cube, that you can move with touch
-Size, you can increase/decrease the size of the cube
-Textures, 6 different textures to choose from
-Auto Rotation, can be toggled on and off

COMING SOON:
-Options menu
-Custom vertices
-Physics

Very special thanks to @Ignatz @yojimbo2000 and @dave1707 for the help and support for 3D, it’s greatly appreciated!

Any feedback and update ideas would be appreciated, thanks!

function setup()
    parameter.number("Size", 1,100,10)
parameter.boolean("Auto_Rotate", true)
    parameter.action("Change Texture", texPage)
parameter.action("Options", opPressed) 
    camX,camY,camZ = 0,0,-500
    lookX,lookY,lookZ = 0,0,-1000
    X,Y,Z = 50,0,-1000
    moveZ = 5
RX,RY,RZ = 0,0,0
    rX,rY,rZ = 0.1,0.5,1.0
    SetupCube(Size)
end
function opPressed()
    if opPressed then
        parameter.clear()
    parameter.action("?", returned)
parameter.watch("No options yet. :(")
    end
end
function SetupCube(Size)
    local d = 0.5 * Size
local vertices = {
      vec3(-d, -d,  d), 
      vec3( d, -d,  d), 
      vec3( d,  d,  d), 
      vec3(-d,  d,  d),
      vec3(-d, -d, -d), 
      vec3( d, -d, -d), 
      vec3( d,  d, -d), 
      vec3(-d,  d, -d), 
    }


local cVert = {  
      vertices[1], vertices[2], vertices[3],
      vertices[1], vertices[3], vertices[4],

      vertices[2], vertices[6], vertices[7],
      vertices[2], vertices[7], vertices[3],
    
      vertices[6], vertices[5], vertices[8],
      vertices[6], vertices[8], vertices[7],
    
      vertices[5], vertices[1], vertices[4],
      vertices[5], vertices[4], vertices[8],
    
      vertices[4], vertices[3], vertices[7],
      vertices[4], vertices[7], vertices[8],
    
      vertices[5], vertices[6], vertices[2],
      vertices[5], vertices[2], vertices[1],
    }
    
    local texvertices = { vec2(0.03,0.24),
                          vec2(0.97,0.24),
                          vec2(0.03,0.69),
                          vec2(0.97,0.69) }
                
    
    local tCoords = {
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],

      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    }

    m = mesh()
    m.vertices = cVert
    m.texture = "Planet Cute:Dirt Block"
    m.texCoords = tCoords
    m:setColors(255,255,255,255)
end

function draw()
background(0)
perspective()
    camera(camX, camY, camZ, lookX, lookY, lookZ)
pushMatrix()
    translate(X,Y,Z)

rotate(-CurrentTouch.y, 1, 0, 0)
    rotate(CurrentTouch.x, 0,1,0)
        rotate(RZ,0,0,1)
    if Auto_Rotate == true then
rotate(ElapsedTime*10, 1,0,0)
    rotate(ElapsedTime*10, 0,1,0)
        rotate(ElapsedTime*10, 0,0,1)
else
  rotate(0, 1,0,0)
    rotate(0, 0,1,0)
        rotate(0, 0,0,1)
  end            
    local s = Size*0.25
scale(s,s,s)
    m:draw()
    resetMatrix()
    sprite("SpaceCute:Background", 0, 0, 300, 300)

    
    rotate(45,0,1,0)
    translate(0, -100, -200)    
popMatrix()
    popStyle()


    end
function texPage()
if texPage then
        parameter.clear()
parameter.action("?", returned)
        parameter.action("Dirt", function() m.texture = "Planet Cute:Dirt Block"end)
parameter.action("Grass", function() m.texture = "Planet Cute:Grass Block"end)
parameter.action("Stone", function() m.texture = "Planet Cute:Stone Block"end)
        parameter.action("Wood", function() m.texture = "Planet Cute:Wood Block"end)
    parameter.action("Water", function() m.texture = "Planet Cute:Water Block"end)
parameter.action("Quartz & Wood", function() m.texture = "Planet Cute:Wall Block"end)
    end
    end

function returned()
    if returned then
        parameter.clear()
       parameter.number("Size", 1,100,Size)
parameter.boolean("Auto_Rotate", true)
    parameter.action("Change Texture", texPage) 
        parameter.action("Options", opPressed)    
    end
end


https://codea.io/talk/discussion/4505/roll-your-own-lighting-shader-with-this-code

@LL_Phoenix456 If you want to impress someone, learn everything that you can and then be good at it. Then start helping the new coders who are trying to learn and you’ll impress them. Then you’ll impress the rest of us, not only by what you do, but by how well you do it.

WOW I TRIED TO CREATE A COOL APP BECAUSE I FINALLY FOUND OUT HOW TO DO 3D BUT OF COURSE ITS DONE AND ITS BETTER! WOWOWOWOWOWOW I CANT IMPRESS ANYONE. :frowning:

Your program is nice for someone just starting out, but of course other people will have made better programs, because they have been doing it longer.

You shouldn’t be worrying about impressing anyone just yet. Just enjoy learning and having fun.

Sorry, I didn’t post that link to discourage you. Your code reminded me of the shader printer and I thought you might be interested in it. It’s inevitable that a forum like this is going to have code of all sorts of levels posted to it, from beginner to expert and everything inbetween. You’re having fun and learning new stuff, that’s the main thing.

Ok, sorry. I took it the wrong way. I understand that. In a second I’m posting a new update that will improve the app ALOT.

function setup()
textures = {"Planet Cute:Dirt Block","Planet Cute:Grass Block","Planet Cute:Stone Block",
  "Planet Cute:Wood Block","Planet Cute:Water Block","Planet Cute:Wall Block"}
    parameter.number("Size", 1,100,10)
parameter.boolean("Auto_Rotate", true)
    parameter.action("Change Texture", texPage)
parameter.action("Options", opPressed) 
                parameter.number("Width", 10, 100, Size)
parameter.number("Height", 10, 100, Size)
    parameter.number("Length", 0, 100, Size)
    camX,camY,camZ = 0,0,-500
    lookX,lookY,lookZ = 0,0,-1000
    X,Y,Z = 50,0,-1000
    moveZ = 5
RX,RY,RZ = 0,0,0
    rX,rY,rZ = 0.1,0.5,1.0
    SetupCube(Size)
end
function opPressed()
    if opPressed then
        parameter.clear()
    parameter.action("?", returned)
    end
end
function SetupCube(Size)
    local d = 0.5 * Size
local vertices = {
      vec3(-d, -d,  d), 
      vec3( d, -d,  d), 
      vec3( d,  d,  d), 
      vec3(-d,  d,  d),
      vec3(-d, -d, -d), 
      vec3( d, -d, -d), 
      vec3( d,  d, -d), 
      vec3(-d,  d, -d), 
    }


local cVert = {  
      vertices[1], vertices[2], vertices[3],
      vertices[1], vertices[3], vertices[4],

      vertices[2], vertices[6], vertices[7],
      vertices[2], vertices[7], vertices[3],
    
      vertices[6], vertices[5], vertices[8],
      vertices[6], vertices[8], vertices[7],
    
      vertices[5], vertices[1], vertices[4],
      vertices[5], vertices[4], vertices[8],
    
      vertices[4], vertices[3], vertices[7],
      vertices[4], vertices[7], vertices[8],
    
      vertices[5], vertices[6], vertices[2],
      vertices[5], vertices[2], vertices[1],
    }
    
    local texvertices = { vec2(0.03,0.24),
                          vec2(0.97,0.24),
                          vec2(0.03,0.69),
                          vec2(0.97,0.69) }
                
    
    local tCoords = {
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],

      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    }

    m = mesh()
    m.vertices = cVert
    m.texture = "Planet Cute:Dirt Block"
    m.texCoords = tCoords
    m:setColors(255,255,255,255)
end

function draw()
background(0)
perspective()
    camera(camX, camY, camZ, lookX, lookY, lookZ)
pushMatrix()
    translate(X,Y,Z)
rotate(-CurrentTouch.y, 1, 0, 0)
    rotate(CurrentTouch.x, 0,1,0)
        rotate(RZ,0,0,1)
    if Auto_Rotate == true then
rotate(ElapsedTime*10, 1,0,0)
    rotate(ElapsedTime*10, 0,1,0)
        rotate(ElapsedTime*10, 0,0,1)
else
  rotate(0, 1,0,0)
    rotate(0, 0,1,0)
        rotate(0, 0,0,1)
  end            
    local s = Size*0.25
scale(s,s,s)
    scale(Width, Height, Length)
m:draw()
    
    resetMatrix()
sprite("SpaceCute:Background", 0,0,300,300)

    
    rotate(45,0,1,0)
    translate(0, -100, -200)    
popMatrix()
    popStyle()


    end
function texPage()
if texPage then
        parameter.clear()
parameter.action("?", returned)
        parameter.action("Dirt", function() m.texture = "Planet Cute:Dirt Block"end)
parameter.action("Grass", function() m.texture = "Planet Cute:Grass Block"end)
parameter.action("Stone", function() m.texture = "Planet Cute:Stone Block"end)
        parameter.action("Wood", function() m.texture = "Planet Cute:Wood Block"end)
    parameter.action("Water", function() m.texture = "Planet Cute:Water Block"end)
parameter.action("Quartz & Wood", function() m.texture = "Planet Cute:Wall Block"end)
    end
    end

function returned()
    if returned then
        parameter.clear()
       parameter.number("Size", 1,100,Size)
parameter.boolean("Auto_Rotate", true)
    parameter.action("Change Texture", texPage) 
        parameter.action("Options", opPressed)    
    end
end