-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7373 from GregStanton/dev-2.0
Overhaul custom shapes for p5.js 2.0
- Loading branch information
Showing
66 changed files
with
3,909 additions
and
3,453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,55 @@ | ||
console.log(p5); | ||
const vertSrc = `#version 300 es | ||
precision mediump float; | ||
uniform mat4 uModelViewMatrix; | ||
uniform mat4 uProjectionMatrix; | ||
in vec3 aPosition; | ||
in vec2 aOffset; | ||
void main(){ | ||
vec4 positionVec4 = vec4(aPosition.xyz, 1.0); | ||
positionVec4.xy += aOffset; | ||
gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4; | ||
} | ||
`; | ||
|
||
const fragSrc = `#version 300 es | ||
precision mediump float; | ||
out vec4 outColor; | ||
void main(){ | ||
outColor = vec4(0.0, 1.0, 1.0, 1.0); | ||
} | ||
`; | ||
|
||
let myShader; | ||
function setup(){ | ||
createCanvas(200, 200); | ||
createCanvas(100, 100, WEBGL); | ||
|
||
// Create and use the custom shader. | ||
myShader = createShader(vertSrc, fragSrc); | ||
|
||
describe('A wobbly, cyan circle on a gray background.'); | ||
} | ||
|
||
async function draw(){ | ||
background(0, 50, 50); | ||
circle(100, 100, 50); | ||
function draw(){ | ||
// Set the styles | ||
background(125); | ||
noStroke(); | ||
shader(myShader); | ||
|
||
// Draw the circle. | ||
beginShape(); | ||
for (let i = 0; i < 30; i++){ | ||
const x = 40 * cos(i/30 * TWO_PI); | ||
const y = 40 * sin(i/30 * TWO_PI); | ||
|
||
// Apply some noise to the coordinates. | ||
const xOff = 10 * noise(x + millis()/1000) - 5; | ||
const yOff = 10 * noise(y + millis()/1000) - 5; | ||
|
||
fill('white'); | ||
textSize(30); | ||
text('hello', 10, 30); | ||
// Apply these noise values to the following vertex. | ||
vertexProperty('aOffset', [xOff, yOff]); | ||
vertex(x, y); | ||
} | ||
endShape(CLOSE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.