åã®ç« ã§ã¯ãããã¤ãã®åºæ¬çãªã¢ãã¡ã¼ã·ã§ã³ã使ãã¦ãç©ã®åããæ¹ãå¦ã³ã¾ããããã®ãã¼ãã§ã¯ã éåãã®ãã®ããã詳細ã«è¦ã¦ã ã¢ãã¡ã¼ã·ã§ã³ãããé«åº¦ã«ããããã®ç©çã追å ãã¦ããã¾ãããã
ãã¼ã«ã®æç»ã¢ãã¡ã¼ã·ã§ã³ã®åå¼·ã®ããã«ããã¼ã«ã使ããã¨æãã®ã§ãæåã«ãã¼ã«ããã£ã³ãã¹ä¸ã«æãã¾ãããã以ä¸ã®ã³ã¼ãã§è¨å®ãã¾ãã
<canvas id="canvas" width="600" height="300"></canvas>
æ®ééããã¾ãæç»ã³ã³ããã¹ããå¿
è¦ã«ãªãã¾ãããã¼ã«ãæãããã ball
ãªãã¸ã§ã¯ãã使ãã¦ãããããã£ã¨ããã£ã³ãã¹ã«ãã¼ã«ãæãããã® draw()
ã¡ã½ãããæã¤ããã«ãã¾ãã
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const ball = {
x: 100,
y: 100,
radius: 25,
color: "blue",
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
},
};
ball.draw();
ããã§ã¯ç¹å¥ãªãã¨ã¯ãªãããã¼ã«ã¯æ¬å½ã«åç´ãªåã§ãarc()
ã¡ã½ããã®å©ããåãã¦æããã¦ãã¾ãã
ãã¼ã«ãã§ããã®ã§ããã®ãã¥ã¼ããªã¢ã«ã®åã®ç« ã§å¦ãã ãããªãåºæ¬çãªã¢ãã¡ã¼ã·ã§ã³ã追å ããæºåãã§ãããã¨ã«ãªãã¾ããããã§ã window.requestAnimationFrame()
ãã¢ãã¡ã¼ã·ã§ã³ãå¶å¾¡ããã®ã«å½¹ç«ã£ã¦ãã¾ãããã¼ã«ã¯ãä½ç½®ã«é度ãã¯ãã«ã追å ãããã¨ã§ç§»åãã¾ããã¾ãããã¬ã¼ã ãã¨ã« clear ãã£ã³ãã¹ã«ä»¥åã®ãã¬ã¼ã ããå¤ãåãåé¤ãã¦ãã¾ãã
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let raf;
const ball = {
x: 100,
y: 100,
vx: 5,
vy: 2,
radius: 25,
color: "blue",
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
},
};
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ball.draw();
ball.x += ball.vx;
ball.y += ball.vy;
raf = window.requestAnimationFrame(draw);
}
canvas.addEventListener("mouseover", (e) => {
raf = window.requestAnimationFrame(draw);
});
canvas.addEventListener("mouseout", (e) => {
window.cancelAnimationFrame(raf);
});
ball.draw();
å¢ç
å¢çã§è¡çªãã¹ããè¡ããªãã¨ããã¼ã«ã¯ããã«ãã£ã³ãã¹ããé£ã³åºãã¦ãã¾ãã¾ãããã¼ã«ã® x
㨠y
ã®ä½ç½®ããã£ã³ãã¹ã®å¯¸æ³ããå¤ãã¦ãããã©ããããã§ãã¯ããé度ãã¯ãã«ã®åããå転ãããå¿
è¦ãããã¾ãããã®ããã«ãdraw
ã¡ã½ããã«æ¬¡ã®ãããªãã§ãã¯ã追å ãã¾ãã
if (
ball.y + ball.vy > canvas.height - ball.radius ||
ball.y + ball.vy < ball.radius
) {
ball.vy = -ball.vy;
}
if (
ball.x + ball.vx > canvas.width - ball.radius ||
ball.x + ball.vx < ball.radius
) {
ball.vx = -ball.vx;
}
æåã®ãã¢
ããã¾ã§ã§å®éã«ã©ã®ããã«è¦ãããè¦ã¦ã¿ã¾ãããã
HTML<canvas id="canvas" style="border: 1px solid" width="600" height="300"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let raf;
const ball = {
x: 100,
y: 100,
vx: 5,
vy: 2,
radius: 25,
color: "blue",
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
},
};
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ball.draw();
ball.x += ball.vx;
ball.y += ball.vy;
if (
ball.y + ball.vy > canvas.height - ball.radius ||
ball.y + ball.vy < ball.radius
) {
ball.vy = -ball.vy;
}
if (
ball.x + ball.vx > canvas.width - ball.radius ||
ball.x + ball.vx < ball.radius
) {
ball.vx = -ball.vx;
}
raf = window.requestAnimationFrame(draw);
}
canvas.addEventListener("mouseover", (e) => {
raf = window.requestAnimationFrame(draw);
});
canvas.addEventListener("mouseout", (e) => {
window.cancelAnimationFrame(raf);
});
ball.draw();
çµæ
ãã£ã³ãã¹ã«ãã¦ã¹ãç§»åããã¨ã¢ãã¡ã¼ã·ã§ã³ãéå§ãã¾ãã
å éåãããããªã¢ã«ã«ããããã«ãä¾ãã°ãããªé¢¨ã«ç§»åéãå¤åããããã¨ãã§ãã¾ãã
ball.vy *= 0.99;
ball.vy += 0.25;
ããã«ããããã¬ã¼ã ãã¨ã«åç´æ¹åã®é度ãé ããªããæçµçã«ãã¼ã«ã¯åºã®ä¸ã§ãã¦ã³ãããã ãã«ãªãã¾ãã
第 2 ã®ã㢠HTML<canvas id="canvas" style="border: 1px solid" width="600" height="300"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let raf;
const ball = {
x: 100,
y: 100,
vx: 5,
vy: 2,
radius: 25,
color: "blue",
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
},
};
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ball.draw();
ball.x += ball.vx;
ball.y += ball.vy;
ball.vy *= 0.99;
ball.vy += 0.25;
if (
ball.y + ball.vy > canvas.height - ball.radius ||
ball.y + ball.vy < ball.radius
) {
ball.vy = -ball.vy;
}
if (
ball.x + ball.vx > canvas.width - ball.radius ||
ball.x + ball.vx < ball.radius
) {
ball.vx = -ball.vx;
}
raf = window.requestAnimationFrame(draw);
}
canvas.addEventListener("mouseover", (e) => {
raf = window.requestAnimationFrame(draw);
});
canvas.addEventListener("mouseout", (e) => {
window.cancelAnimationFrame(raf);
});
ball.draw();
çµæ å¾å¼ã广
ããã¾ã§ãåã®ãã¬ã¼ã ãã¯ãªã¢ããã¨ã㯠clearRect
ã¡ã½ããã使ç¨ãã¦ãã¾ããããã®ã¡ã½ãããåéæã® fillRect
ã«ç½®ãæããã¨ãç°¡åã«å¾å¼ã广ãä½ããã¨ãã§ãã¾ãã
ctx.fillStyle = "rgb(255 255 255 / 30%)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
第 3 ã®ã㢠HTML
<canvas id="canvas" style="border: 1px solid" width="600" height="300"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let raf;
const ball = {
x: 100,
y: 100,
vx: 5,
vy: 2,
radius: 25,
color: "blue",
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
},
};
function draw() {
ctx.fillStyle = "rgb(255 255 255 / 30%)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ball.draw();
ball.x += ball.vx;
ball.y += ball.vy;
ball.vy *= 0.99;
ball.vy += 0.25;
if (
ball.y + ball.vy > canvas.height - ball.radius ||
ball.y + ball.vy < ball.radius
) {
ball.vy = -ball.vy;
}
if (
ball.x + ball.vx > canvas.width - ball.radius ||
ball.x + ball.vx < ball.radius
) {
ball.vx = -ball.vx;
}
raf = window.requestAnimationFrame(draw);
}
canvas.addEventListener("mouseover", (e) => {
raf = window.requestAnimationFrame(draw);
});
canvas.addEventListener("mouseout", (e) => {
window.cancelAnimationFrame(raf);
});
ball.draw();
çµæ ãã¦ã¹å¶å¾¡ã®è¿½å
ãã¼ã«ã«å¯¾ãã¦ã¡ãã£ã¨ããå¶å¾¡ãããããã«ããã¨ãã° mousemove
ã¤ãã³ãã使ç¨ãã¦ãã¼ã«ã«ãã¦ã¹ã追ãããããããããªãã¨ãã§ãã¾ããclick
ã¤ãã³ãã§ãã¼ã«ãè§£æ¾ãã¦ãã¾ããã¦ã³ãããããã¨ãã§ãã¾ãã
<canvas id="canvas" style="border: 1px solid" width="600" height="300"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let raf;
let running = false;
const ball = {
x: 100,
y: 100,
vx: 5,
vy: 1,
radius: 25,
color: "blue",
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
},
};
function clear() {
ctx.fillStyle = "rgb(255 255 255 / 30%)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
function draw() {
clear();
ball.draw();
ball.x += ball.vx;
ball.y += ball.vy;
if (
ball.y + ball.vy > canvas.height - ball.radius ||
ball.y + ball.vy < ball.radius
) {
ball.vy = -ball.vy;
}
if (
ball.x + ball.vx > canvas.width - ball.radius ||
ball.x + ball.vx < ball.radius
) {
ball.vx = -ball.vx;
}
raf = window.requestAnimationFrame(draw);
}
canvas.addEventListener("mousemove", (e) => {
if (!running) {
clear();
ball.x = e.clientX;
ball.y = e.clientY;
ball.draw();
}
});
canvas.addEventListener("click", (e) => {
if (!running) {
raf = window.requestAnimationFrame(draw);
running = true;
}
});
canvas.addEventListener("mouseout", (e) => {
window.cancelAnimationFrame(raf);
running = false;
});
ball.draw();
çµæ
ãã¦ã¹ã§ãã¼ã«ãåãããã¯ãªãã¯ã§ãã¼ã«ãæ¾ãã¾ãã
ãããã¯å´©ããã®çãç« ã§ã¯ãããé«åº¦ãªã¢ãã¡ã¼ã·ã§ã³ã使ããããã®ãã¯ããã¯ãããã¤ã説æããã ãã§ããä»ã«ãããããããã¾ããããã«ãã¬ã³ã¬ã追å ãã¦ããã®ãã¢ããããã¯å´©ãã²ã¼ã ã«ããã®ã¯ã©ãã§ããããï¼ã²ã¼ã éçºé åã§ã¯ãã²ã¼ã é¢é£ã®è¨äºã夿°æ²è¼ãã¦ãã¾ãã
é¢é£æ å ±RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4