Draw many rectangles
authorJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 00:02:19 +0000 (19:02 -0500)
committerJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 00:02:25 +0000 (19:02 -0500)
For loop iteration, table iteration, and rectangles drawn diagonally

source/main.lua

index c5dbbd8..5cedb2d 100644 (file)
@@ -1,11 +1,16 @@
 local pd <const> = playdate
 local gfx <const> = playdate.graphics
 
-local r = pd.geometry.rect.new(0, 0, 32, 32)
+local rects = {}
+for i=1, 10 do
+    rects[i] = pd.geometry.rect.new(32 * (i-1), 32 * (i-1), 32, 32)
+end
 
 
 function playdate.update()
-    gfx.drawRect(r)
+    for i,r in ipairs(rects) do
+        gfx.drawRect(r)
+    end
     if playdate.buttonJustPressed("a") then
         playdate.display.setInverted(not playdate.display.getInverted())
     end