Skip to content

Commit 6082ca9

Browse files
committed
add 3d
1 parent 642f731 commit 6082ca9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pages/p5js-examples/three-dim.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const P5Wrapper = dynamic(() => import("src/P5Wrapper"), { ssr: false });
99
import { geometries } from "src/sketches/three-dim/geometries";
1010
import { sineCosine } from "src/sketches/three-dim/sine-cosine";
1111
import { multipleLights } from "src/sketches/three-dim/multiple-lights";
12+
import { orbitControl } from "src/sketches/three-dim/orbit-control";
1213

1314
const ThreeDim: NextPage = () => {
1415
return (
@@ -37,6 +38,7 @@ const ThreeDim: NextPage = () => {
3738
<P5Wrapper sketch={geometries} />
3839
<P5Wrapper sketch={sineCosine} />
3940
<P5Wrapper sketch={multipleLights} />
41+
<P5Wrapper sketch={orbitControl} />
4042
</VStack>
4143
</Layout>
4244
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type p5 from "p5";
2+
3+
export const orbitControl = (p: p5) => {
4+
p.setup = () => {
5+
p.createCanvas(720, 400, p.WEBGL);
6+
};
7+
8+
p.draw = () => {
9+
p.background(250);
10+
let radius = p.width * 1.5;
11+
12+
// drag to move the world.
13+
p.orbitControl();
14+
15+
p.normalMaterial();
16+
p.translate(0, 0, -600);
17+
for (let i = 0; i <= 12; i++) {
18+
for (let j = 0; j <= 12; j++) {
19+
p.push();
20+
const a = (j / 12) * p.PI;
21+
const b = (i / 12) * p.PI;
22+
p.translate(
23+
p.sin(2 * a) * radius * p.sin(b),
24+
(p.cos(b) * radius) / 2,
25+
p.cos(2 * a) * radius * p.sin(b)
26+
);
27+
if (j % 2 === 0) {
28+
p.cone(30, 30);
29+
} else {
30+
p.box(30, 30, 30);
31+
}
32+
p.pop();
33+
}
34+
}
35+
};
36+
};

0 commit comments

Comments
 (0)