create table with some black rect

Hi,

I am Fabio, an italian guy…im on my first steps with Corona and app world, so be patience with me :smiley:

Anyway i need to recreate a table like in the image attached 

So a table with 4 columns and 5 rows…with one black rect on each row

this is my code…someone can help me??

thanks in advance

local tile local tileRowGroup = display.newGroup() local \_W = display.contentWidth local \_H = display.contentHeight local numeroDiRighe = 5 local numeroDiColonne = 4 local larghezzaTile = display.contentWidth/numeroDiColonne local altezzaTile = display.contentHeight/numeroDiRighe --tile = display.newRect( 80, 96, display.contentWidth/4, display.contentHeight/5 ) --tile:setFillColor( 255,255,255 ) --tile:setStrokeColor( 200,240,34 ) function loadRow() local piazzamentoTile = {x=\_W-(larghezzaTile\*numeroDiColonne)+(larghezzaTile/2), y=\_H-(altezzaTile\*numeroDiRighe)+(altezzaTile/2)} local random = math.random( 1, 3 ) for righe = 0, numeroDiRighe - 1 do for colonne =0, numeroDiColonne - 1 do tileXX = piazzamentoTile.x + (colonne \* larghezzaTile) tileYY = piazzamentoTile.y + (righe \* altezzaTile) --creazione dei mattoni tile = display.newRect( tileXX, tileYY, larghezzaTile, altezzaTile ) tile.name = "tile" tile.strokeWidth = 2 tile:setFillColor( 255,255,255 ) tile:setStrokeColor( 0, 0, 0 ) --physics.addBody( tile, "static", {density=1, friction=0, bounce = 0} ) --tileRowGroup:insert(tile) end end end

Your code was a bit difficult for me to read since all the variables are in Italian, so I started from scratch. This spawns a 4x5 grid and colors a random tile in each row black.

math.randomseed(os.time()) local COLS, ROWS = 4, 5 local tileWidth = display.contentWidth / COLS local tileHeight = display.contentHeight / ROWS local tiles = {} -- spawn tiles for i = 1, ROWS do local row = {} for j = 1, COLS do local tile = display.newRect((j - 1) \* tileWidth, (i - 1) \* tileHeight, tileWidth, tileHeight) tile.anchorX, tile.anchorY = 0, 0 tile.strokeWidth = 2 tile:setStrokeColor(0) row[j] = tile end tiles[i] = row end -- color 1 tile in each row black for row = 1, #tiles do local col = math.random(1,4) tiles[row][col]:setFillColor(0) end

sorry for the language, thank you so much for your help _memo :slight_smile:

Your code was a bit difficult for me to read since all the variables are in Italian, so I started from scratch. This spawns a 4x5 grid and colors a random tile in each row black.

math.randomseed(os.time()) local COLS, ROWS = 4, 5 local tileWidth = display.contentWidth / COLS local tileHeight = display.contentHeight / ROWS local tiles = {} -- spawn tiles for i = 1, ROWS do local row = {} for j = 1, COLS do local tile = display.newRect((j - 1) \* tileWidth, (i - 1) \* tileHeight, tileWidth, tileHeight) tile.anchorX, tile.anchorY = 0, 0 tile.strokeWidth = 2 tile:setStrokeColor(0) row[j] = tile end tiles[i] = row end -- color 1 tile in each row black for row = 1, #tiles do local col = math.random(1,4) tiles[row][col]:setFillColor(0) end

sorry for the language, thank you so much for your help _memo :slight_smile: