Skip to content

Commit 3dc08f6

Browse files
committed
working on tutorial sketch
1 parent a5e76dd commit 3dc08f6

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

preview/global/sketch.js

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,50 @@
1-
// p5.disableFriendlyErrors = true;
1+
p5.disableFriendlyErrors = true;
22
function windowResized() {
33
resizeCanvas(windowWidth, windowHeight);
44
}
5-
let myShader;
6-
let filterShader;
7-
let video;
85

6+
let myModel;
7+
let starShader;
8+
let starStrokeShader;
9+
let stars;
10+
11+
function starShaderCallback() {
12+
const time = uniformFloat(() => millis());
13+
getWorldInputs((inputs) => {
14+
inputs.position.y += instanceID() * 20 - 1000;
15+
inputs.position.x += 40*sin(time * 0.001 + instanceID());
16+
return inputs;
17+
});
18+
getObjectInputs((inputs) => {
19+
inputs.position *= sin(time*0.001 + instanceID());
20+
return inputs;
21+
})
22+
}
923

1024
async function setup(){
1125
createCanvas(windowWidth, windowHeight, WEBGL);
12-
13-
// filterShader = baseFi
14-
15-
filterShader = baseFilterShader().modify(() => {
16-
const time = uniformFloat(() => millis());
17-
18-
getColor((input, canvasContents) => {
19-
let myColor = texture(canvasContents, uvCoords());
20-
const d = distance(input.texCoord, [0.5, 0.5]);
21-
myColor.x = smoothstep(0, 0.5, d);
22-
myColor.y = sin(time*0.001)/2;
23-
return myColor;
24-
})
25-
});
26-
27-
myShader = baseMaterialShader().modify(() => {
28-
const time = uniformFloat(() => millis());
29-
30-
getFinalColor((col) => {
31-
col.x = uvCoords().x;
32-
col.y = uvCoords().y;
33-
col.z = 1;
34-
return col;
35-
});
36-
37-
getWorldInputs((inputs) => {
38-
inputs.position.y += 20 * sin(time * 0.001 + inputs.position.x * 0.05);
39-
return inputs;
40-
})
41-
});
26+
stars = buildGeometry(() => sphere(20, 7, 4))
27+
starShader = baseMaterialShader().modify(starShaderCallback);
28+
starStrokeShader = baseStrokeShader().modify(starShaderCallback)
4229
}
4330

4431
function draw(){
45-
// orbitControl();
46-
background(0);
32+
background(0,200,240);
33+
orbitControl();
34+
// noStroke();
35+
36+
push();
37+
stroke(255,0,255)
38+
fill(255,200,255)
39+
strokeShader(starStrokeShader)
40+
shader(starShader);
41+
model(stars, 100);
42+
pop();
43+
push();
44+
shader(baseMaterialShader());
4745
noStroke();
48-
fill('blue')
49-
sphere(100)
50-
shader(myShader);
51-
filter(filterShader);
52-
// filterShader.setUniform('time', millis());
46+
rotateX(HALF_PI);
47+
translate(0, 0, -250);
48+
plane(10000)
49+
pop();
5350
}

0 commit comments

Comments
 (0)