/
151019.tsx
56 lines (44 loc) · 1.15 KB
/
151019.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from "react";
import type p5 from "p5";
import { P5Renderer } from "Renderers/P5";
const sketch = (p: p5) => {
let w: number;
let h: number;
let cols: number;
let rows: number;
const scale = 20;
const terrain: number[][] = [];
let xOff = 0;
let yOff = 0;
const maxZOff = 60;
p.setup = () => {
p.createCanvas(p.windowWidth, p.windowHeight, p.WEBGL);
p.background(20);
p.frameRate(24);
w = p.windowWidth;
h = p.windowHeight;
cols = w / scale;
rows = h / scale;
for (let y = 0; y < rows; y++) terrain[y] = [];
};
p.draw = () => {
p.background(20);
p.stroke(255);
p.strokeWeight(0.7);
p.noFill();
p.rotateX(p.PI / 3);
p.translate(-p.width / 2, -p.height / 2);
for (let y = 0; y < rows - 1; y++) {
p.beginShape(p.TRIANGLE_STRIP);
for (let x = 0; x < cols; x++) {
terrain[y][x] = p.map(p.noise(xOff, yOff), 0, 1, -maxZOff, maxZOff);
p.vertex(x * scale, y * scale, terrain[y][x]);
xOff += 0.01;
}
yOff += 0.01;
p.endShape();
}
};
};
const S151019 = () => <P5Renderer sketch={sketch} />;
export default S151019;