Add initial camera code

This commit is contained in:
Lev
2021-07-21 19:49:21 -05:00
parent 387ae3e7b4
commit cd9139a69d
3 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<!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>Document</title>
</head>
<body>
<script src="p5.min.js"></script>
<script src="sketch.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,32 @@
function setup() {
createCanvas(900, 600, WEBGL);
angleMode(DEGREES);
}
function draw() {
background(125);
// camera
let zLoc = ((sin(frameCount) + 1)/2 * height) + 200;
// or
zLoc = map(sin(frameCount), -1, 1, 200, 600);
// using noise
xLoc = map(noise(frameCount/200), 0, 1, -500, 500);
yLoc = map(noise(frameCount/200 + 100), 0, 1, -500, 500);
zLoc = map(noise(frameCount/200 + 150), 0, 1, 300, 800);
// to rotate
xLoc = cos(frameCount) * height;
yLoc = sin(frameCount) * 300;
zLoc = sin(frameCount) * height;
// camera location x, y, z | Pointing to x, y, z | Orientation(tilt) x,y,z
camera(xLoc, yLoc, zLoc, 0, 0, 0, 0, 1, 0);
// objects
normalMaterial();
torus(200, 50, 50, 50);
translate(0, 100, 0);
rotateX(90);
fill(200);
plane(500, 500);
}