{"id":9819,"student_id":1470,"content":"setBackdrop(\"black\");\n\n\nvar balls = [],\n numOfBalls = 50;\n\nvar ball = {\n x: 320,\n y: 0,\n vx: 10,\n vy: -10,\n r: 5,\n friction: 2\n};\n\nvar gravity = 2,\n bounceFactor = 0.8,\n surfaceFriction = 3;\n\nfunction update(obj) {\n //Upper and lower bounds\n if (obj.y + obj.vy + obj.r \u003e 480) { //if the ball is about to touch the lower bound\n obj.y = 480 - obj.r; //don't move\n obj.vy *= -1 * bounceFactor; //and also reverse the direction in the X co-ordinate, but not fully (energy absorbed by wall)\n } else if (obj.y + obj.vy + obj.r \u003c 0) { //if the ball is about to touch upper bound\n obj.y = 0 - obj.r; //don't move\n obj.vy *= -1 * bounceFactor; //see above\n } else { //if it's not touching the upper or lower bounds\n obj.y += obj.vy; //move\n }\n //Leftmost and rightmost bounds\n if (obj.x + obj.vx + obj.r \u003e 640) { //if the ball is about to touch the right bound\n obj.x = 640 - obj.r; //don't move\n obj.vx *= -1; //reverse X velocity\n } else if (obj.x + obj.vx - obj.r \u003c 0) { //if the ball is about to touch leftmost bound\n obj.x = 0 + obj.r; //don't move \n obj.vx *= -1 * bounceFactor; //reverse X velocity\n } else { //not touching left/rightmost bounds\n obj.x += obj.vx; //move as normal\n }\n\n obj.vy += gravity * bounceFactor; //affected by gravity\n obj.vx -= obj.vx / (250/obj.friction); //air drag\n if(obj.y == 480-obj.r){\n obj.vx -= obj.vx / (250/surfaceFriction); //apply friction again, to rolling targets\n }\n\n\n\n\n}\n\nfunction initBalls(n) {\n for (var i = 0; i \u003c n; i++) {\n var newBall = {\n x: Math.random()*640,\n y: Math.random()*480,\n vx: Math.random()*50-25,\n vy: 0,\n r: Math.random()*10+4,\n friction: 0,\n colour: Math.round(Math.random()*360)\n };\n newBall.friction = newBall.r/2;\n balls.push(newBall);\n }\n}\n\ninitBalls(numOfBalls);\n//balls.splice(0,1);\nforever(function () {\n for(var i = 0; i \u003c numOfBalls; i++){\n update(balls[i]);\n var color = \"hsl(\"+balls[i].colour+\", 100%, 50%)\"\n \n pen.fillColor = color;\n pen.color = color;\n pen.drawCircle(balls[i].x, balls[i].y, balls[i].r);\n if(balls[i].y \u003e= 480-balls[i].r \u0026\u0026 Math.abs(balls[i].vx) \u003c= 1 \u0026\u0026 Math.abs(balls[i].vy) \u003c= 2){ //if it's on the floor, it's not moving in the x direction, and it's not bouncing\n balls.splice(i, 1);\n initBalls(1);\n }\n }\n})\n","created_at":"2017-03-01T20:52:04.729+08:00","updated_at":"2019-10-18T05:14:43.678+08:00","name":"療癒跳跳球","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/9819/89edcce60b8890776f43b51e69f48ea4.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":440,"hashid":"rdvs663r","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":217799,"file_name":"0.png","project_id":9819,"asset_id":6,"created_at":"2017-08-23T13:44:24.604+08:00","updated_at":"2017-08-23T13:44:24.604+08:00"},{"id":217800,"file_name":"1.svg","project_id":9819,"asset_id":7,"created_at":"2017-08-23T13:44:24.608+08:00","updated_at":"2017-08-23T13:44:24.608+08:00"},{"id":217801,"file_name":"2.png","project_id":9819,"asset_id":8,"created_at":"2017-08-23T13:44:24.612+08:00","updated_at":"2017-08-23T13:44:24.612+08:00"},{"id":217802,"file_name":"0.wav","project_id":9819,"asset_id":9,"created_at":"2017-08-23T13:44:24.616+08:00","updated_at":"2017-08-23T13:44:24.616+08:00"},{"id":217803,"file_name":"1.wav","project_id":9819,"asset_id":10,"created_at":"2017-08-23T13:44:24.620+08:00","updated_at":"2017-08-23T13:44:24.620+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦