This commit is contained in:
2025-03-22 10:32:54 -05:00
parent 87e1e634a9
commit 8b0eff9b34
13 changed files with 606 additions and 134 deletions

View File

@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Canvas</title>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
<script src="cs.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Canvas</title>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
<script src="cs.js"></script>
</body

82
9/cs.js
View File

@@ -1,42 +1,42 @@
let canvas = document.querySelector("#canvas");
let ctx = canvas.getContext("2d");
let width = canvas.width;
let height = canvas.height;
let x = 0;
let y = 0;
let forwards = true;
function drawCircle(x, y) {
ctx.fillStyle = "rgb(0, 128, 255)";
ctx.beginPath();
ctx.arc(x, y, 10, 0, Math.PI * 2, false);
ctx.fill();
}
function update() {
if (forwards === true) {
x += 1;
y = 10
}
else{
x -= 1;
y = 10
}
if (x >= 300){
forwards = false;
}
if (x <= 0){
forwards = true
}
// y += 1;
// x %= width;
// y %= height;
}
function draw() {
ctx.clearRect(0, 0, width, height);
drawCircle(x, y);
}
setInterval(() => {
update();
draw();
let canvas = document.querySelector("#canvas");
let ctx = canvas.getContext("2d");
let width = canvas.width;
let height = canvas.height;
let x = 0;
let y = 0;
let forwards = true;
function drawCircle(x, y) {
ctx.fillStyle = "rgb(0, 128, 255)";
ctx.beginPath();
ctx.arc(x, y, 10, 0, Math.PI * 2, false);
ctx.fill();
}
function update() {
if (forwards === true) {
x += 1;
y = 10
}
else{
x -= 1;
y = 10
}
if (x >= 300){
forwards = false;
}
if (x <= 0){
forwards = true
}
// y += 1;
// x %= width;
// y %= height;
}
function draw() {
ctx.clearRect(0, 0, width, height);
drawCircle(x, y);
}
setInterval(() => {
update();
draw();
}, 1);