- Divide the screen into 4x4 grid
- Automatically generate rectangles (boxes) of different colors.
-
- random() – [0,1] real
- random( m ) – [1,m] integer
- random( m, n) – [m, n] integer
- However, have TWO and only two of the same color (There should be total 8 colors).
- The size of each box should be changed automatically based on different device resolutions (i.e., different width/heights)
- When a box is tapped, it is visibly marked by making it larger so it stands out.
- g., you may change stroke color of the selected box
- When another box is tapped:
- If its color matches the box that is visibly marked, the two boxes disappear.
- If all boxes are disappeared, display some congratulation message and go back to your title screen.
- If the colors do not match, the newly tapped box is visibly marked and the previously marked box is unmarked.
There isn’t a question in there.
Is this for a class?
YES, this is a project for class. I don’t know how to Automatically generate rectangles (boxes) of different colors into 4*4. could you please help out of this.
Follow up questions:
-
What specific class is this for (give a class title)?
-
Is there an online syllabus or other links associated with the class?
I’m asking because this information will directly influence the kind of help I’ll be willing to give. I’m happy to help you puzzle through something you’ve tried and failed to understand, but merely giving solutions to specs… no way. That is your job.
Having said all that, I’ll give you some breadcrumbs to follow:
Places To Get Examples and Docs
-
The API docs: https://docs.coronalabs.com/daily/api/index.html
-
The Corona SDK simulator (which I assume you’ve downloaded) comes with a TON of examples.
-
My gits have tons of examples and libraries:
- https://github.com/roaminggamer/CoronaGeek
- https://github.com/roaminggamer/RG_FreeStuff
- https://github.com/roaminggamer/SSKLegacy
Some Partial Solutions For the Above Spec (again, you haven’t asked a real question yet)
Determine Coordinate of 2 x 2 (update to 4 x 4 on your own) positions
-- Not tested: May contain typos -- local cx, cy = display.contentCenterX, display.contentCenterY local fw, fh = display.actualContentWidth, display.actualContentHeight local positions = {} positions[1] = { x = cx - fw/2, y = cy - fh/2 } positions[2] = { x = cx + fw/2, y = cy - fh/2 } positions[3] = { x = cx - fw/2, y = cy + fh/2 } positions[4] = { x = cx - fw/2, y = cy + fh/2 } -- Place markers to show these positions for i = 1, #positions do display.newCircle( positions[1].x, positions[1].y, 10 ) end
Random Colors
-- Not tested: May contain typos -- local colors = {} colors[1] = { 1, 0, 0 } colors[2] = { 0, 1, 0 } colors[3] = { 0, 0, 1 } colors[4] = { 1, 1, 0 } -- Choose random color local tmp = display.newCircle( display.contentCenterX, display.contentCenterY, 40 ) tmp:setFillColor( unpack( colors[math.random( 1, #colors )] ) )
Detecting Touches
-- Not tested: May contain typos -- local function onTouch( self, event ) if( event.phase == "began" ) then print("Clicked object ", self.myNum ) end end local tmp = display.newRect( 50, 50, 50, 50 ) tmp.myNum = 1 tmp.touch = onTouch tmp:addEventListener("touch") local tmp = display.newRect( 150, 50, 50, 50 ) tmp.myNum = 2 tmp.touch = onTouch tmp:addEventListener("touch")
Beyond this, read the guides and search the site.
thanks a lot! but it still has some problems. how to use the picture instead of position?
local positions = {}
positions[1] = { x = X/8, y = Y/8 }
positions[2] = { x = X/8+X/4, y = Y/8 }
positions[3] = { x = X/8+X/2, y = Y/8 }
positions[4] = { x = X/8+X*3/4, y = Y/8}
positions[5] = { x = X/8, y = Y/8 +Y/4 }
positions[6] = { x = X/8+X/4, y = Y/8 +Y/4}
positions[7] = { x = X/8+X/2, y = Y/8 +Y/4}
positions[8] = { x = X/8+X*3/4, y = Y/8+Y/4}
positions[9] = { x = X/8, y = Y/8 +Y/2 }
positions[10] = { x = X/8+X/4, y = Y/8+Y/2 }
positions[11] = { x = X/8+X/2, y = Y/8+Y/2 }
positions[12] = { x = X/8+X*3/4, y = Y/8+Y/2}
positions[13] = { x = X/8, y = Y/8 +Y*3/4}
positions[14] = { x = X/8+X/4, y = Y/8 +Y*3/4}
positions[15] = { x = X/8+X/2, y = Y/8+Y*3/4 }
positions[16] = { x = X/8+X*3/4, y = Y/8+Y*3/4}
local pictures ={}
pictures[1]={“sa.png”}
pictures[2]={“sa.png”}
pictures[3]={“sb.png”}
pictures[4]={“sb.png”}
pictures[5]={“sc.png”}
pictures[6]={“sc.png”}
pictures[7]={“sd.png”}
pictures[8]={“sd.png”}
pictures[9]={“se.png”}
pictures[10]={“se.png”}
pictures[11]={“sf.png”}
pictures[12]={“sf.png”}
pictures[13]={“sg.png”}
pictures[14]={“sg.png”}
pictures[15]={“sp.png”}
pictures[16]={“sp.png”}
– Place markers to show these positions
for i = 1, #positions do
c = display.newCircle( positions[i].x, positions[i].y, 10 )
end
Try and try again. You’ll figure it out. Also, you need to read the docs. Try looking up each function I used in my sample in the API docs. That will get you a long ways to figuring out how to use images. I won’t code it for you.
Also you didn’t answer my follow up questions.
Follow up questions:
- What specific class is this for (give a class title)?
- Is there an online syllabus or other links associated with the class?
I’m asking because this information will directly influence the kind of help I’ll be willing to give. I’m happy to help you puzzle through something you’ve tried and failed to understand, but merely giving solutions to specs… no way. That is your job.

There isn’t a question in there.
Is this for a class?
YES, this is a project for class. I don’t know how to Automatically generate rectangles (boxes) of different colors into 4*4. could you please help out of this.
Follow up questions:
-
What specific class is this for (give a class title)?
-
Is there an online syllabus or other links associated with the class?
I’m asking because this information will directly influence the kind of help I’ll be willing to give. I’m happy to help you puzzle through something you’ve tried and failed to understand, but merely giving solutions to specs… no way. That is your job.
Having said all that, I’ll give you some breadcrumbs to follow:
Places To Get Examples and Docs
-
The API docs: https://docs.coronalabs.com/daily/api/index.html
-
The Corona SDK simulator (which I assume you’ve downloaded) comes with a TON of examples.
-
My gits have tons of examples and libraries:
- https://github.com/roaminggamer/CoronaGeek
- https://github.com/roaminggamer/RG_FreeStuff
- https://github.com/roaminggamer/SSKLegacy
Some Partial Solutions For the Above Spec (again, you haven’t asked a real question yet)
Determine Coordinate of 2 x 2 (update to 4 x 4 on your own) positions
-- Not tested: May contain typos -- local cx, cy = display.contentCenterX, display.contentCenterY local fw, fh = display.actualContentWidth, display.actualContentHeight local positions = {} positions[1] = { x = cx - fw/2, y = cy - fh/2 } positions[2] = { x = cx + fw/2, y = cy - fh/2 } positions[3] = { x = cx - fw/2, y = cy + fh/2 } positions[4] = { x = cx - fw/2, y = cy + fh/2 } -- Place markers to show these positions for i = 1, #positions do display.newCircle( positions[1].x, positions[1].y, 10 ) end
Random Colors
-- Not tested: May contain typos -- local colors = {} colors[1] = { 1, 0, 0 } colors[2] = { 0, 1, 0 } colors[3] = { 0, 0, 1 } colors[4] = { 1, 1, 0 } -- Choose random color local tmp = display.newCircle( display.contentCenterX, display.contentCenterY, 40 ) tmp:setFillColor( unpack( colors[math.random( 1, #colors )] ) )
Detecting Touches
-- Not tested: May contain typos -- local function onTouch( self, event ) if( event.phase == "began" ) then print("Clicked object ", self.myNum ) end end local tmp = display.newRect( 50, 50, 50, 50 ) tmp.myNum = 1 tmp.touch = onTouch tmp:addEventListener("touch") local tmp = display.newRect( 150, 50, 50, 50 ) tmp.myNum = 2 tmp.touch = onTouch tmp:addEventListener("touch")
Beyond this, read the guides and search the site.
thanks a lot! but it still has some problems. how to use the picture instead of position?
local positions = {}
positions[1] = { x = X/8, y = Y/8 }
positions[2] = { x = X/8+X/4, y = Y/8 }
positions[3] = { x = X/8+X/2, y = Y/8 }
positions[4] = { x = X/8+X*3/4, y = Y/8}
positions[5] = { x = X/8, y = Y/8 +Y/4 }
positions[6] = { x = X/8+X/4, y = Y/8 +Y/4}
positions[7] = { x = X/8+X/2, y = Y/8 +Y/4}
positions[8] = { x = X/8+X*3/4, y = Y/8+Y/4}
positions[9] = { x = X/8, y = Y/8 +Y/2 }
positions[10] = { x = X/8+X/4, y = Y/8+Y/2 }
positions[11] = { x = X/8+X/2, y = Y/8+Y/2 }
positions[12] = { x = X/8+X*3/4, y = Y/8+Y/2}
positions[13] = { x = X/8, y = Y/8 +Y*3/4}
positions[14] = { x = X/8+X/4, y = Y/8 +Y*3/4}
positions[15] = { x = X/8+X/2, y = Y/8+Y*3/4 }
positions[16] = { x = X/8+X*3/4, y = Y/8+Y*3/4}
local pictures ={}
pictures[1]={“sa.png”}
pictures[2]={“sa.png”}
pictures[3]={“sb.png”}
pictures[4]={“sb.png”}
pictures[5]={“sc.png”}
pictures[6]={“sc.png”}
pictures[7]={“sd.png”}
pictures[8]={“sd.png”}
pictures[9]={“se.png”}
pictures[10]={“se.png”}
pictures[11]={“sf.png”}
pictures[12]={“sf.png”}
pictures[13]={“sg.png”}
pictures[14]={“sg.png”}
pictures[15]={“sp.png”}
pictures[16]={“sp.png”}
– Place markers to show these positions
for i = 1, #positions do
c = display.newCircle( positions[i].x, positions[i].y, 10 )
end
Try and try again. You’ll figure it out. Also, you need to read the docs. Try looking up each function I used in my sample in the API docs. That will get you a long ways to figuring out how to use images. I won’t code it for you.
Also you didn’t answer my follow up questions.
Follow up questions:
- What specific class is this for (give a class title)?
- Is there an online syllabus or other links associated with the class?
I’m asking because this information will directly influence the kind of help I’ll be willing to give. I’m happy to help you puzzle through something you’ve tried and failed to understand, but merely giving solutions to specs… no way. That is your job.
