Page 1 of 1

Code questions

PostPosted: Tue Jun 07, 2016 1:34 am
by tazinator
First question: Is this real Lua? I am (still) a complete programming noob. Sorry guys :oops:

  Code:
function setup()
    fors()
end

function draw()
    background(50,50,50,255)
    fill(150,200,100,255)
    strokeWidth(2)
    for a = 1,w do
        for b = a,h do
            rect(xX[a],yY[b],WIDTH/w,HEIGHT/h)
        end
    end
end

function fors()
    h = 80
    w = 100
    xX = {}
    yY = {}
    for a = 1,w do
        local x = WIDTH/w*a-WIDTH/w
        table.insert(xX,x)
    end
    for a = 1,h do
        local y = HEIGHT/h*a-HEIGHT/h
        table.insert(yY,y)
    end
end



Second question, if I bump up w to 1000 and h to 800, it won't draw the rectangles. I'm not sure why.

I'm just playing around with drawing lots of rectangles on an iPad and wondering if maybe I have terrible methods for drawing grids :P

Re: Code questions

PostPosted: Tue Jun 07, 2016 6:48 pm
by bobdaduck
Looks like lua to me! Does it throw any error messages? Maybe the rectangles are just too big.

Re: Code questions

PostPosted: Wed Jun 08, 2016 9:52 pm
by tazinator
^didnt see any, but idk how Codea works tbh

But, new theory, maybe iPad has limitations on what it can draw on screen. Also, realized that it was making the rectangles smaller than a pixel anyway which may have had something to do with it :oops:

ANYWAY... Ignoring that problem, I'll make a new question.

How should I save user inputs for a music writing app? Should I just throw everything in tables?

Re: Code questions

PostPosted: Thu Jun 09, 2016 4:54 pm
by Fordcars
Yes, or even a table of tables if you want to be object oriented :)

Re: Code questions

PostPosted: Sat Jun 11, 2016 9:08 pm
by tazinator
  Code:
-- Table Of Tables

function setup()
    tables()
end

function draw()
    background(40, 40, 50)
    strokeWidth(2)
    fill(50,20,100,255)
    for i = 1,a*b do
        rect(coordinates[1][i],coordinates[2][i], WIDTH/a,HEIGHT/b)
        --X y width height of rectangle
    end
end

function tables()
    coordinates = {{},{}}
    a = 12
    b = 7
    for i = 1,a do
        for j = 1,b do
            local x = WIDTH/a*i-WIDTH/a
            local y = HEIGHT/b*j-HEIGHT/b
            table.insert(coordinates[1],x)
            table.insert(coordinates[2],y)
        end
    end
end


Table of tables like this?

Also, I only need 12 X coordinates and 7 y coordinates but I am pretty sure my for loops actually make 84 of each. Not sure, still trying to find a print command that actually tells me the number of items in a table

Re: Code questions

PostPosted: Sun Jun 12, 2016 9:52 am
by Fordcars
Try logprint(#table) to print the amount of elements in a table :)

I am not really sure what you are trying to do though, is it supposed to draw a bunch of triangles based on user input?

Re: Code questions

PostPosted: Mon Jun 13, 2016 10:26 pm
by tazinator
Actually rectangles arranged to look like a triangle, idk if rect(x, y, w, h) is a standard Lua command or if it's only in Codea like the touched function

Be easier if I had a desktop :(