[CT404]: Start Assignment 1
This commit is contained in:
5
year4/semester1/CT404: Graphics & Image Processing/assignments/assignment1/code/.idea/.gitignore
generated
vendored
Normal file
5
year4/semester1/CT404: Graphics & Image Processing/assignments/assignment1/code/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
12
year4/semester1/CT404: Graphics & Image Processing/assignments/assignment1/code/.idea/code.iml
generated
Normal file
12
year4/semester1/CT404: Graphics & Image Processing/assignments/assignment1/code/.idea/code.iml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/code.iml" filepath="$PROJECT_DIR$/.idea/code.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>CT404: Assignment 01</title>
|
||||||
|
<link rel="stylesheet" href="styles.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="myCanvas" width="800" height="600"></canvas>
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1 @@
|
|||||||
|
console.log('Happy developing ✨')
|
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "code",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"private": true
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
const canvas = document.getElementById('myCanvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// set canvas dimensions
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
|
||||||
|
// draw the stick figures
|
||||||
|
draw();
|
||||||
|
|
||||||
|
// Draw stick figure function
|
||||||
|
function drawStickFigure(x, y) {
|
||||||
|
ctx.lineWidth = 3;
|
||||||
|
ctx.strokeStyle = 'black';
|
||||||
|
|
||||||
|
// draw the stick figure's head
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x, y - 30, 20, 0, Math.PI * 2);
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// draw the stick figure's left eye
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x - 7, y - 33, 1, 0, Math.PI * 2);
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// draw the stick figure's right eye
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x + 7, y - 33, 1, 0, Math.PI * 2);
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// draw the stick figure's mouth
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x, y - 25, 6, 0, Math.PI);
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// Body
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x, y - 10);
|
||||||
|
ctx.lineTo(x, y + 50); // Length of body
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// Arms
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x - 30, y + 10); // Left arm
|
||||||
|
ctx.lineTo(x + 30, y + 10); // Right arm
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
// Legs
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x, y + 50); // Start at bottom of body
|
||||||
|
ctx.lineTo(x - 20, y + 100); // Left leg
|
||||||
|
ctx.moveTo(x, y + 50);
|
||||||
|
ctx.lineTo(x + 20, y + 100); // Right leg
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animation function
|
||||||
|
// function animate() {
|
||||||
|
// ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
|
||||||
|
//
|
||||||
|
// drawStickFigure(x, y); // Draw stick figure at current position
|
||||||
|
//
|
||||||
|
// // Update position
|
||||||
|
// x += dx;
|
||||||
|
// y += dy;
|
||||||
|
//
|
||||||
|
// // Check boundaries and reverse direction if necessary
|
||||||
|
// if (x + 20 > canvas.width || x - 20 < 0) dx = -dx; // Horizontal boundary check
|
||||||
|
// if (y + 100 > canvas.height || y - 50 < 0) dy = -dy; // Vertical boundary check
|
||||||
|
//
|
||||||
|
// requestAnimationFrame(animate); // Recursive call to keep animation going
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Start animation
|
||||||
|
// animate();
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
// prompt the user to enter a number in a range and not continuing under a number in that range is selected
|
||||||
|
let numberStickFigures = 0;
|
||||||
|
while (numberStickFigures < 1 || numberStickFigures > 5) {
|
||||||
|
numberStickFigures = prompt("Enter an integer between 1 and 5");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i <= numberStickFigures; i++) {
|
||||||
|
// place the stick figure randomly on the canvas
|
||||||
|
const x = Math.floor(Math.random() * canvas.width);
|
||||||
|
const y = Math.floor(Math.random() * canvas.height);
|
||||||
|
|
||||||
|
drawStickFigure(x, y);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user