Add Initial commit
This commit is contained in:
17
CM2030 Graphics Programming/Topic 2/2.2.5b/index.html
Normal file
17
CM2030 Graphics Programming/Topic 2/2.2.5b/index.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>randomDot</title>
|
||||||
|
<script src="libraries/p5.min.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<script src="libraries/p5.dom.js" type="text/javascript"></script>
|
||||||
|
<script src="libraries/p5.sound.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<script src="sketch.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3031
CM2030 Graphics Programming/Topic 2/2.2.5b/libraries/p5.dom.js
Normal file
3031
CM2030 Graphics Programming/Topic 2/2.2.5b/libraries/p5.dom.js
Normal file
File diff suppressed because it is too large
Load Diff
36
CM2030 Graphics Programming/Topic 2/2.2.5b/libraries/p5.min.js
vendored
Normal file
36
CM2030 Graphics Programming/Topic 2/2.2.5b/libraries/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
12873
CM2030 Graphics Programming/Topic 2/2.2.5b/libraries/p5.sound.js
Normal file
12873
CM2030 Graphics Programming/Topic 2/2.2.5b/libraries/p5.sound.js
Normal file
File diff suppressed because it is too large
Load Diff
32
CM2030 Graphics Programming/Topic 2/2.2.5b/sketch.js
Normal file
32
CM2030 Graphics Programming/Topic 2/2.2.5b/sketch.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
function setup() {
|
||||||
|
createCanvas(900, 600);
|
||||||
|
background(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw()
|
||||||
|
{
|
||||||
|
background(125);
|
||||||
|
|
||||||
|
var mouse = createVector(mouseX, mouseY);
|
||||||
|
var center = createVector(width/2, height/2);
|
||||||
|
|
||||||
|
mouse.sub(center);
|
||||||
|
|
||||||
|
let normal = mouse.copy();
|
||||||
|
|
||||||
|
textSize(20);
|
||||||
|
text("Normal: " + normal.normalize(), 20, 50);
|
||||||
|
|
||||||
|
// We extract the direction of a vector using the p5.js .normalize() function
|
||||||
|
normal = normal.mult(50);
|
||||||
|
line(10, 60, 10 + normal.x, 60 + normal.y);
|
||||||
|
|
||||||
|
fill('white');
|
||||||
|
console.log(typeof normal);
|
||||||
|
|
||||||
|
// Center line
|
||||||
|
translate(width/2, height/2);
|
||||||
|
strokeWeight(3);
|
||||||
|
|
||||||
|
line(0,0, mouse.x, mouse.y);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user