Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Added my canvas #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/art/Harsha/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/art/Harsha/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<canvas id="myCanvas"></canvas>
<script src="script.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions src/art/Harsha/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"art_name": "Earth revolving around the Sun",
"author_name": "Harsha Vardhan",
"author_github_url": "https://github.com/Harsha70/"
}
71 changes: 71 additions & 0 deletions src/art/Harsha/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
window.onload = function() {
// Retrieve the canvas element
var canvas = document.getElementById("myCanvas");

// Check if the browser supports canvas
if (canvas.getContext) {
var ctx = canvas.getContext("2d");

// Set canvas size
canvas.width = 800;
canvas.height = 600;

// Define the sun
var sun = {
x: canvas.width / 2,
y: canvas.height / 2,
radius: 50,
color: "rgba(255, 223, 0, 1)"
};

// Define the earth
var earth = {
orbitRadius: 200,
radius: 30,
color: "rgba(0, 119, 190, 1)",
angle: 0,
speed: 0.01
};

// Animation loop
function animate() {
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);

// Draw the sun
ctx.beginPath();
ctx.arc(sun.x, sun.y, sun.radius, 0, 2 * Math.PI);
ctx.fillStyle = sun.color;
ctx.shadowColor = "rgba(255, 223, 0, 0.4)";
ctx.shadowBlur = 50;
ctx.fill();

// Update the earth's position
earth.angle += earth.speed;
var earthX = sun.x + earth.orbitRadius * Math.cos(earth.angle);
var earthY = sun.y + earth.orbitRadius * Math.sin(earth.angle);

// Draw the earth
ctx.beginPath();
ctx.arc(earthX, earthY, earth.radius, 0, 2 * Math.PI);
ctx.fillStyle = earth.color;
ctx.shadowColor = "rgba(0, 119, 190, 0.4)";
ctx.shadowBlur = 20;
ctx.fill();

// Draw the earth's orbit
ctx.strokeStyle = "rgba(0, 119, 190, 0.3)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.arc(sun.x, sun.y, earth.orbitRadius, 0, 2 * Math.PI);
ctx.stroke();

// Request the next animation frame
requestAnimationFrame(animate);
}

// Start the animation
animate();
}
};

5 changes: 5 additions & 0 deletions src/art/Harsha/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Add any custom styles here */
canvas {
border: 1px solid #000;
}