Added index and js file.

This commit is contained in:
2018-07-11 17:59:21 +02:00
parent 71c032e4fb
commit 73038c06e2
2 changed files with 49 additions and 0 deletions

17
index.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cubewaves</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.14/p5.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.js"></script>
<script src="public/sketch.js"></script>
<script> console.log('called');</script>
</head>
<body>
<p>Hello world</p>
</body>
</html>

32
public/sketch.js Normal file
View File

@@ -0,0 +1,32 @@
let angle = 0;
let w = 24;
function setup() {
createCanvas(400, 400, WEBGL);
}
function draw() {
background(175);
ortho();
directionalLight(255, 255, 255, 0, -1, 0);
translate(0, 50, -50);
rotateX(PI / 8);
rectMode(CENTER);
let offset = 0;
for (let x = 0; x < width; x += w) {
push();
let a = angle + offset;
let h = map(sin(a), -1, 1, 0, 100);
translate(x - width / 2, 0, 0);
ambientMaterial(255);
box(w, h, w);
//rect(x - width / 2 + w / 2, 0, w - 2, h);
offset += 0.1;
pop();
}
angle += 0.1;
}