Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
feat: add my canvaz solution (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-sampsonorson authored May 22, 2022
1 parent cb81677 commit 6a109c6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
Binary file added src/art/sampsonorson/icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added src/art/sampsonorson/index.css
Empty file.
17 changes: 17 additions & 0 deletions src/art/sampsonorson/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HacktoberFox | Sampson Orson Jackson</title>
<link rel="stylesheet" href="index.css">
</head>

<body>
<canvas id="canvaz"></canvas>
</body>
<script src="index.js"></script>

</html>
46 changes: 46 additions & 0 deletions src/art/sampsonorson/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
window.addEventListener("load", (e) => {
const canvazEl = document.getElementById("canvaz");

if (!canvazEl?.getContext) return;

// Resizing
sizeCanvaz(canvazEl);

const context = canvazEl.getContext("2d");
const radian = Math.PI / 180;
let r = 50;
let x = -50;
let startAngle = 90 * radian;
let endAngle = 2 * Math.PI;
let currentAngle = 0;
let oldTime = getTime();

// x, y, radius, startAngle, endAngle [, counterclockwise]
// the x and y position is relative to the center of the circle
setInterval(() => {
let newTime = getTime();
let diff = newTime - oldTime;

context.fillStyle = "#000";
context.fillRect(0, 0, context.canvas.width, context.canvas.height);

context.beginPath();
context.fillStyle = "red";
context.arc(x++, context.canvas.height / 2, r, startAngle + currentAngle, endAngle + currentAngle);
context.fill();

currentAngle += 0.1;
currentAngle %= 2 * Math.PI;

if (x >= context.canvas.width + r) {
x = -r;
}
}, 10);
});

const sizeCanvaz = (el) => {
el.width = "350";
el.height = "350";
};

const getTime = () => (new Date()).getTime();
5 changes: 5 additions & 0 deletions src/art/sampsonorson/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"art_name": "HacktoberFox",
"author_name": "Sampson Orson Jackson",
"author_github_url": "https://github.com/dev-sampsonorson"
}

0 comments on commit 6a109c6

Please sign in to comment.