Professional Documents
Culture Documents
UNIT TITLE:
INIT CODE:
STUDENT NAME:
TASK: ASSIGNMENT
SUBMISSION DATE:
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
<style>
#myCanvas {
</style>
</head>
<body>
<script>
function draw() {
context.moveTo(100, 150);
context.moveTo(50, 100);
context.moveTo(150, 100);
context.strokeStyle = '#000000';
context.stroke();
window.onload = draw;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
<link rel="stylesheet" href="styles.css" />
<style>
#my-canvas{
</style>
</head>
<body>
</canvas>
<script>
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'blue';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'green';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'blue';
ctx.beginPath();
ctx.fill();
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.fill();}
drawBullseye (400,250)
</script>
</body>
</html>
OTHER CODE
JAVA CODE. SAVE WITH THE APPROPRIATE NAME AND INDICATE THE DIRECTORY:
var data = {
canvas: null,
ctx: null,
clickedDot: null,
dots: [{x: 100, y: 100}, {x: 200, y: 200}, {x: 200, y: 100}, {x: 100, y:
200}]
};
x = c1.x - c2.x,
y = c1.y - c2.y;
function prepCanvas () {
scale = 1 / res;
data.canvas = document.getElementById('dots');
data.ctx = data.canvas.getContext('2d');
checkForDot(e);
});
function drawDots () {
var i = 0;
var d = data.dots[i];
data.ctx.beginPath();
data.ctx.fillStyle = '#777';
data.ctx.fill();
data.ctx.closePath();
}
data.ctx.beginPath();
data.ctx.moveTo(data.clickedDot.x, data.clickedDot.y);
data.ctx.lineTo(toDot.x, toDot.y);
data.ctx.lineWidth = 5;
data.ctx.strokeStyle = '#777';
data.ctx.stroke();
data.ctx.closePath();
var d = data.dots[i],
}
data.clickedDot = col;
prepCanvas();
drawDots();
SEPARATE THIS ONE WITH THE ABOVE AND RUN THE CODE DIFFERENTLY.
function getDocumentWidth() {
};
function getDocumentHeight() {
};
var vw = getDocumentWidth(),
vh = getDocumentHeight();
function onResize() {
vw = getDocumentWidth();
vh = getDocumentHeight();
resizeCanvas();
}
function resizeCanvas() {
canvas.width = vw;
canvas.height = vh;
drawDots();
}
resizeCanvas();
// grid
function drawGrid(){
cellH = 10;
// vertical lines
context.moveTo(x, 0); // x, y
context.lineTo(x, vh);
}
// horizontal lines
context.moveTo(0, y); // x, y
context.lineTo(vw, y);
}
context.strokeStyle = "#cccccc";
context.stroke();
}
// drawGrid();
// dots
function drawDots() {
var r = 2,
cw = 30,
ch = 30;
context.fillStyle = '#000000';
context.fillRect(x-r/2,y-r/2,r,r);
}
}
}
drawDots();
THE HTML FILE FOR THE ABOVE TWO JavaScript CODE:
<!doctype html>
<html>
<head>
<title>Connecting Dots</title>
<style>
body {
margin:0;
.container {
width:100%;
height:100%;
#dotCanvas {
display:block;
</style>
</head>
<body>
<div class="container">
<canvas id="dotCanvas"></canvas>
</div>
<canvas id="dots"></canvas>
</html>
REFERENCES
Grady, M. (2010). Functional programming using JavaScript and the HTML5 canvas element. Journal of
computing sciences in colleges, 26(2), 97-105.
Cecco, R. (2011). Supercharged JavaScript Graphics: with HTML5 canvas, jQuery, and More. " O'Reilly
Media, Inc.".
Abudahab, K., Underwood, A., Taylor, B., Yeats, C., & Aanensen, D. M. (2021). Phylocanvas. gl: A
WebGL-powered JavaScript library for large tree visualisation.