사용자:Riemann/testplugin: 두 판 사이의 차이
백괴게임>Riemann 잔글 (partial work) |
백괴게임>Riemann 잔글 (-_-) |
||
(같은 사용자의 중간 판 3개는 보이지 않습니다) | |||
4번째 줄: | 4번째 줄: | ||
{{#vardefine:name| | {{#vardefine:name|riemann_testplugin}} | ||
{{#vardefine:creat|Riemann}} | {{#vardefine:creat|Riemann}} | ||
{{#vardefine:version|0.6. | {{#vardefine:version|0.6.13}} | ||
{{#vardefine:descript|test}} | {{#vardefine:descript|test}} | ||
{{#vardefine:local|true}} | {{#vardefine:local|true}} | ||
48번째 줄: | 48번째 줄: | ||
You.update = function() { | You.update = function() { | ||
event = new MouseEvent("mouse"); | event = new MouseEvent("mouse"); | ||
norm = Math.sqrt( Math.pow(mouseX - 250, 2) + Math.pow(mouseY - 250, 2)); | norm = Math.sqrt( Math.pow(mouseX - 250, 2) + Math.pow(mouseY - 250, 2)); | ||
this.x = 250 + 50 * (mouseX - 250) / norm; | this.x = 250 + 50 * (mouseX - 250) / norm; | ||
76번째 줄: | 75번째 줄: | ||
function loop() { | function loop() { | ||
ctx.fillStyle = 'rgb(240, 240, 240)'; | ctx.fillStyle = 'rgb(240, 240, 240)'; | ||
ctx.fillRect(0, 0, 500, 500); | ctx.fillRect(0, 0, 500, 500); | ||
while (asterList.length < 5) { | while (asterList.length < 5) { | ||
var aster = new Asteroid(Math.floor(460 * Math.random()) + 20, Math.floor(460 * Math.random()) + 20, Math.cos(2 * Math.PI * Math.random()), Math.sin(2 * Math.PI * Math.random()) ); | |||
asterList.push(aster); | |||
} | } | ||
for (var i = 0; i < asterList.length; i++) { | for (var i = 0; i < asterList.length; i++) { | ||
asterList[i].draw(); | |||
asterList[i].update(); | |||
} | if (asterList[i].x > 500 || asterList[i].x < 0 || asterList[i].y > 500 || asterList[i].y < 0) { | ||
asterList.splice(i, 1); | |||
Earth.draw(); | } | ||
You.draw(); | } | ||
You.update(); | |||
Earth.draw(); | |||
requestAnimationFrame(loop); | You.draw(); | ||
You.update(); | |||
window.requestAnimationFrame(loop); | |||
} | } | ||
loop(); | loop(); |
2018년 7월 30일 (월) 16:46 기준 최신판
이 플러그인에 대한 설명문서는 사용자:Riemann/testplugin/설명문서에서 만들 수 있습니다.
$("#wa").append('<canvas id="can" width="500" height="500">Alt text</canvas>'); var c = document.getElementById("can"); var ctx = c.getContext("2d"); var Earth = {}; Earth.x = 250; Earth.y = 250; Earth.draw = function() { ctx.beginPath(); ctx.fillStyle = 'gray'; ctx.arc(this.x, this.y, 50, 0, 2 * Math.PI); ctx.fill(); } var You = {}; You.x = 250; You.y = 250; var mouseX; var mouseY; document.addEventListener("mousemove", mouseMoveHandler, false); function mouseMoveHandler(e) { mouseX = e.clientX - $("#can").offset().left; mouseY = e.clientY - $("#can").offset().top; } You.draw = function() { ctx.beginPath(); ctx.fillStyle = 'black'; ctx.arc(this.x, this.y, 10, 0, 2 * Math.PI); ctx.fill(); } You.update = function() { event = new MouseEvent("mouse"); norm = Math.sqrt( Math.pow(mouseX - 250, 2) + Math.pow(mouseY - 250, 2)); this.x = 250 + 50 * (mouseX - 250) / norm; this.y = 250 + 50 * (mouseY - 250) / norm; } function Asteroid(x, y, dx, dy) { this.x = x; this.y = y; this.dx = dx; this.dy = dy; } Asteroid.prototype.draw = function() { ctx.beginPath(); ctx.fillStyle = 'gray'; ctx.arc(this.x, this.y, 20, 0, 2 * Math.PI); ctx.fill(); } Asteroid.prototype.update = function() { this.x += this.dx; this.y += this.dy; } var asterList = [] function loop() { ctx.fillStyle = 'rgb(240, 240, 240)'; ctx.fillRect(0, 0, 500, 500); while (asterList.length < 5) { var aster = new Asteroid(Math.floor(460 * Math.random()) + 20, Math.floor(460 * Math.random()) + 20, Math.cos(2 * Math.PI * Math.random()), Math.sin(2 * Math.PI * Math.random()) ); asterList.push(aster); } for (var i = 0; i < asterList.length; i++) { asterList[i].draw(); asterList[i].update(); if (asterList[i].x > 500 || asterList[i].x < 0 || asterList[i].y > 500 || asterList[i].y < 0) { asterList.splice(i, 1); } } Earth.draw(); You.draw(); You.update(); window.requestAnimationFrame(loop); } loop();