{"id":9297,"student_id":70,"content":"setBackdrop(\"white\");\nvar width=64,\n height=48;\nvar cells = [];\nfor(var x=0;x\u003cwidth;x++){\n var col = new Array(height).fill(0);\n cells.push(col);\n}\nfor(var i=0; i\u003c600; i++){\n cells[Math.floor(Math.random()*64)][Math.floor(Math.random()*48)]=1;\n}\npen.fillColor=\"black\";\nforever(function(){\n for(var x=0;x\u003cwidth;x++){\n for(var y=0;y\u003cheight;y++){\n if(cells[x][y]){\n pen.drawRect(x*10,y*10,10,10);\n }\n }\n }\n});\nsetInterval(function(){\n var newCells = [];\n for(var x=0;x\u003cwidth;x++){\n var col = new Array(height).fill(0);\n newCells.push(col);\n }\n for(var x=0;x\u003cwidth;x++){\n for(var y=0;y\u003cheight;y++){\n if( cells[x][y] ){\n if ( countNeighbors(x,y)\u003c2 ){\n newCells[x][y]=0;\n } else if ( countNeighbors(x,y)\u003c4 ){\n newCells[x][y]=1;\n } else {\n newCells[x][y]=0;\n }\n } else {\n if ( countNeighbors(x,y)==3 ){\n newCells[x][y]=1;\n } \n }\n }\n }\n cells = newCells;\n},1000);\n\nfunction countNeighbors(x,y){\n var result = 0;\n if (x \u003e= 1) { result += cells[x-1][y]; }\n if (x \u003c= 62) { result += cells[x+1][y]; }\n if (y \u003e= 1) { result += cells[x][y-1]; }\n if (y \u003c= 46) { result += cells[x][y+1]; }\n if (x\u003e=1 \u0026\u0026 y\u003e=1) { result += cells[x-1][y-1]; }\n if (x\u003e=1 \u0026\u0026 y\u003c=46) { result += cells[x-1][y+1]; }\n if (x\u003c=62 \u0026\u0026 y\u003e=1) { result += cells[x+1][y-1]; }\n if (x\u003c=62 \u0026\u0026 y\u003c=46) { result += cells[x+1][y+1]; }\n return result;\n}","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2021-10-19T19:23:25.512+08:00","name":"Game of Life","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/9297/4813f6df1a513631fd1b3cfdb0229647.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":401,"hashid":"882sqyqr","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":205075,"file_name":"0.png","project_id":9297,"asset_id":6,"created_at":"2017-08-15T17:01:10.796+08:00","updated_at":"2017-08-15T17:01:10.796+08:00"},{"id":205076,"file_name":"1.svg","project_id":9297,"asset_id":7,"created_at":"2017-08-15T17:01:10.799+08:00","updated_at":"2017-08-15T17:01:10.799+08:00"},{"id":205077,"file_name":"2.png","project_id":9297,"asset_id":8,"created_at":"2017-08-15T17:01:10.801+08:00","updated_at":"2017-08-15T17:01:10.801+08:00"},{"id":205078,"file_name":"0.wav","project_id":9297,"asset_id":9,"created_at":"2017-08-15T17:01:10.802+08:00","updated_at":"2017-08-15T17:01:10.802+08:00"},{"id":205079,"file_name":"1.wav","project_id":9297,"asset_id":10,"created_at":"2017-08-15T17:01:10.804+08:00","updated_at":"2017-08-15T17:01:10.804+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦