{"id":14005,"student_id":10,"content":"var SIZE = 16; // 公因數:10, 16, 20, 32, 40, 64, 80, 128...\nvar W = 640/SIZE;\nvar H = 480/SIZE;\nvar grid = [];\nvar groups = [];\n\nfor (var x=0; x\u003cW; x++) {\n grid[x] = [];\n for (var y=0; y\u003cH; y++) {\n grid[x][y] = '1234';\n groups.push([y*W + x]);\n }\n}\n\nfunction merge () {\n\n if (groups.length \u003c= 1) return;\n\n var rand = Math.floor(Math.random()*groups.length);\n var group1 = groups.splice(rand, 1)[0];\n var group2 = [];\n var a, b, direction;\n\n while (true) {\n a = group1[Math.floor(Math.random()*group1.length)];\n b = direction = undefined;\n\n direction = Math.ceil(Math.random()*4);\n\n if (direction == 1) b = a - W;\n if (direction == 2) b = a + 1;\n if (direction == 3) b = a + W;\n if (direction == 4) b = a - 1;\n\n if (group1.includes(b)) continue;\n if (b \u003c 0 || b \u003e W*H-1) continue;\n if (a%W == 0 \u0026\u0026 direction == 4) continue;\n if (a%W == W-1 \u0026\u0026 direction == 2) continue;\n\n var cell1 = grid[a%W][Math.floor(a/W)];\n var cell2 = grid[b%W][Math.floor(b/W)];\n grid[a%W][Math.floor(a/W)] = cell1.replace(direction, '');\n grid[b%W][Math.floor(b/W)] = cell2.replace(direction \u003e 2 ? direction - 2 : direction + 2, '');\n\n break;\n }\n\n for (var i=0; i\u003cgroups.length; i++) {\n if (groups[i].includes(b)) {\n var index = groups.indexOf(groups[i]);\n group2 = groups.splice(index, 1)[0];\n }\n }\n groups.push(group1.concat(group2));\n}\n\nforever(function(){\n for (var x=0; x\u003cgrid.length; x++) {\n for (var y=0; y\u003cgrid[x].length; y++) {\n var cell = grid[x][y];\n if (cell.includes(1)) pen.drawRect(x*SIZE, y*SIZE, SIZE, 2);\n if (cell.includes(2)) pen.drawRect(x*SIZE + SIZE - 2, y*SIZE, 2, SIZE);\n if (cell.includes(3)) pen.drawRect(x*SIZE, y*SIZE + SIZE - 2, SIZE, 2);\n if (cell.includes(4)) pen.drawRect(x*SIZE, y*SIZE, 2, SIZE);\n }\n }\n});\n\nforever(merge);","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2019-11-10T21:47:08.494+08:00","name":"迷宮產生器","language":"javascript","screenshot":{"url":"/uploads/project/screenshot/14005/05085366c0e388d48c6c31d0f0117217.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[1407,1934],"is_featured":true,"views":1360,"hashid":"gk4skyvz","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
Orange Apple Learning Platform
My Projects
View Project Page
Export
Remix
Import
Delete
Download Android APP (APK)
Screenshot
繁中
简中
English
日本語
1:1:1
1:1
Full Width
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer