3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/contributors-conference/bocoup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/bocoup.png
--------------------------------------------------------------------------------
/contributors-conference/edp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/edp.png
--------------------------------------------------------------------------------
/contributors-conference/itp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/itp.png
--------------------------------------------------------------------------------
/contributors-conference/logos.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/logos.png
--------------------------------------------------------------------------------
/contributors-conference/nea.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/nea.jpg
--------------------------------------------------------------------------------
/contributors-conference/studio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/studio.png
--------------------------------------------------------------------------------
/contributors-conference/theartificial.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/contributors-conference/theartificial.png
--------------------------------------------------------------------------------
/css/f/AvenirNextLTW01-Medium.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/AvenirNextLTW01-Medium.eot
--------------------------------------------------------------------------------
/css/f/AvenirNextLTW01-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/AvenirNextLTW01-Medium.ttf
--------------------------------------------------------------------------------
/css/f/AvenirNextLTW01-Medium.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/AvenirNextLTW01-Medium.woff
--------------------------------------------------------------------------------
/css/f/inconsolata.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/inconsolata.eot
--------------------------------------------------------------------------------
/css/f/inconsolata.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/inconsolata.otf
--------------------------------------------------------------------------------
/css/f/inconsolata.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/inconsolata.ttf
--------------------------------------------------------------------------------
/css/f/inconsolata.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/css/f/inconsolata.woff
--------------------------------------------------------------------------------
/examples/build_examples/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "csv2html.js",
3 | "description": "Convert a CSV file into an HTML file using a simple template.",
4 | "version": "0.0.0",
5 | "repository": {
6 | "url": ""
7 | },
8 | "main": "build.js",
9 | "dependencies": {
10 | "async": "^0.9.0",
11 | "csv": "0.0.10",
12 | "ejs": "0.6.1",
13 | "rimraf": "^2.2.8"
14 | },
15 | "devDependencies": {}
16 | }
17 |
--------------------------------------------------------------------------------
/examples/demos/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/demos/assets/.gitkeep
--------------------------------------------------------------------------------
/examples/demos/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/examples/demos_src/01_Hello_P5/01_shapes.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Simple Shapes
3 | * @description This examples includes a circle, square, triangle, and a flower.
4 | */
5 | function setup() {
6 | // Create the canvas
7 | createCanvas(720, 400);
8 | background(200);
9 |
10 | // Set colors
11 | fill(204, 101, 192, 127);
12 | stroke(127, 63, 120);
13 |
14 | // A rectangle
15 | rect(40, 120, 120, 40);
16 | // An ellipse
17 | ellipse(240, 240, 80, 80);
18 | // A triangle
19 | triangle(300, 100, 320, 100, 310, 80);
20 |
21 | // A design for a simple flower
22 | translate(580, 200);
23 | noStroke();
24 | for (var i = 0; i < 10; i ++) {
25 | ellipse(0, 30, 20, 80);
26 | rotate(PI/5);
27 | }
28 | }
--------------------------------------------------------------------------------
/examples/demos_src/01_Hello_P5/03_interactivity.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Interactivity 2
3 | * @frame 720,425
4 | * @description The circle changes color when you move the slider.
5 | * You will need to include the
6 | * p5.dom library
7 | * for this example to work in your own project.
8 | */
9 |
10 | // A HTML range slider
11 | var slider;
12 |
13 | function setup() {
14 | createCanvas(720, 400);
15 | // hue, saturation, and brightness
16 | colorMode(HSB, 255);
17 | // slider has a range between 0 and 255 with a starting value of 127
18 | slider = createSlider(0, 255, 127);
19 | }
20 |
21 | function draw() {
22 | background(127);
23 | strokeWeight(2);
24 |
25 | // Set the hue according to the slider
26 | stroke(slider.value(), 255, 255);
27 | fill(slider.value(), 255, 255, 127);
28 | ellipse(360, 200, 200, 200);
29 | }
--------------------------------------------------------------------------------
/examples/demos_src/01_Hello_P5/04_animate.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Animation
3 | * @description The circle moves.
4 | */
5 | // Where is the circle
6 | var x, y;
7 |
8 | function setup() {
9 | createCanvas(720, 400);
10 | // Starts in the middle
11 | x = width / 2;
12 | y = height;
13 | }
14 |
15 | function draw() {
16 | background(200);
17 |
18 | // Draw a circle
19 | stroke(50);
20 | fill(100);
21 | ellipse(x, y, 24, 24);
22 |
23 | // Jiggling randomly on the horizontal axis
24 | x = x + random(-1, 1);
25 | // Moving up at a constant speed
26 | y = y - 1;
27 |
28 | // Reset to the bottom
29 | if (y < 0) {
30 | y = height;
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/examples/examples/assets/360video_256crop_v2.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/360video_256crop_v2.mp4
--------------------------------------------------------------------------------
/examples/examples/assets/Damscray_-_Dancing_Tiger_01.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/Damscray_-_Dancing_Tiger_01.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/Damscray_-_Dancing_Tiger_01.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/Damscray_-_Dancing_Tiger_01.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/Damscray_-_Dancing_Tiger_02.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/Damscray_-_Dancing_Tiger_02.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/Damscray_-_Dancing_Tiger_02.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/Damscray_-_Dancing_Tiger_02.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/Damscray_DancingTiger.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/Damscray_DancingTiger.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/Damscray_DancingTiger.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/Damscray_DancingTiger.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/LeagueGothic-Regular.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/LeagueGothic-Regular.otf
--------------------------------------------------------------------------------
/examples/examples/assets/beat.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/beat.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/beat.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/beat.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/beatbox.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/beatbox.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/beatbox.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/beatbox.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/bx-spring.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/bx-spring.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/bx-spring.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/bx-spring.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/cat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/cat.jpg
--------------------------------------------------------------------------------
/examples/examples/assets/concrete-tunnel.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/concrete-tunnel.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/concrete-tunnel.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/concrete-tunnel.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/doorbell.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/doorbell.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/doorbell.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/doorbell.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/drum.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/drum.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/drum.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/drum.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/fingers.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/fingers.mov
--------------------------------------------------------------------------------
/examples/examples/assets/fingers.webm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/fingers.webm
--------------------------------------------------------------------------------
/examples/examples/assets/large-dark-plate.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/large-dark-plate.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/large-dark-plate.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/large-dark-plate.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/lucky_dragons_-_power_melody.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/lucky_dragons_-_power_melody.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/lucky_dragons_-_power_melody.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/lucky_dragons_-_power_melody.ogg
--------------------------------------------------------------------------------
/examples/examples/assets/mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/mask.png
--------------------------------------------------------------------------------
/examples/examples/assets/moonwalk.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/moonwalk.jpg
--------------------------------------------------------------------------------
/examples/examples/assets/particle_texture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/particle_texture.png
--------------------------------------------------------------------------------
/examples/examples/assets/small-plate.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/small-plate.mp3
--------------------------------------------------------------------------------
/examples/examples/assets/small-plate.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/processing/p5.js-website-OLD/7a7cbfe7457030be6c33d4130b3481b00c59e948/examples/examples/assets/small-plate.ogg
--------------------------------------------------------------------------------
/examples/examples/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/01_Width_and_Height.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Width and Height
3 | * @description The 'width' and 'height' variables contain the
4 | * width and height of the display window as defined in the createCanvas()
5 | * function.
6 | */
7 | function setup() {
8 | createCanvas(720, 400);
9 | }
10 |
11 | function draw() {
12 | background(127);
13 | noStroke();
14 | for (var i = 0; i < height; i += 20) {
15 | fill(129, 206, 15);
16 | rect(0, i, width, 10);
17 | fill(255);
18 | rect(i, 0, 10, height);
19 | }
20 | }
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/02_Setup_and_Draw.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Setup and Draw
3 | * @description The code inside the draw() function runs continuously from top
4 | * to bottom until the program is stopped.
5 | */
6 | var y = 100;
7 |
8 | // The statements in the setup() function
9 | // execute once when the program begins
10 | function setup() {
11 | // createCanvas must be the first statement
12 | createCanvas(720, 400);
13 | stroke(255); // Set line drawing color to white
14 | frameRate(30);
15 | }
16 | // The statements in draw() are executed until the
17 | // program is stopped. Each statement is executed in
18 | // sequence and after the last line is read, the first
19 | // line is executed again.
20 | function draw() {
21 | background(0); // Set the background to black
22 | y = y - 1;
23 | if (y < 0) {
24 | y = height;
25 | }
26 | line(0, y, width, y);
27 | }
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/03_No_Loop.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name No Loop
3 | * @description The noLoop() function causes draw() to only execute once.
4 | * Without calling noLoop(), the code inside draw() is run continually.
5 | */
6 | var y;
7 |
8 | // The statements in the setup() function
9 | // execute once when the program begins
10 | function setup()
11 | {
12 | // createCanvas should be the first statement
13 | createCanvas(720, 400);
14 | stroke(255); // Set line drawing color to white
15 | noLoop();
16 |
17 | y = height * 0.5;
18 | }
19 |
20 | // The statements in draw() are executed until the
21 | // program is stopped. Each statement is executed in
22 | // sequence and after the last line is read, the first
23 | // line is executed again.
24 | function draw()
25 | {
26 | background(0); // Set the background to black
27 | y = y - 1;
28 | if (y < 0) { y = height; }
29 | line(0, y, width, y);
30 | }
31 |
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/04_Loop.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Loop
3 | * @description The code inside the draw() function runs continuously from top
4 | * to bottom until the program is stopped.
5 | */
6 | var y = 100;
7 |
8 | // The statements in the setup() function
9 | // execute once when the program begins
10 | function setup() {
11 | createCanvas(720, 400); // Size must be the first statement
12 | stroke(255); // Set line drawing color to white
13 | frameRate(30);
14 | }
15 | // The statements in draw() are executed until the
16 | // program is stopped. Each statement is executed in
17 | // sequence and after the last line is read, the first
18 | // line is executed again.
19 | function draw() {
20 | background(0); // Set the background to black
21 | y = y - 1;
22 | if (y < 0) {
23 | y = height;
24 | }
25 | line(0, y, width, y);
26 | }
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/05_Redraw.js:
--------------------------------------------------------------------------------
1 | /*
2 | *@name Redraw
3 | *@description The redraw() function makes draw() execute once. In this example,
4 | *draw() is executed once every time the mouse is clicked.
5 | */
6 |
7 | var y;
8 |
9 | // The statements in the setup() function
10 | // execute once when the program begins
11 | function setup() {
12 | createCanvas(720, 400);
13 | stroke(255);
14 | noLoop();
15 | y = height * 0.5;
16 | }
17 |
18 | // The statements in draw() are executed until the
19 | // program is stopped. Each statement is executed in
20 | // sequence and after the last line is read, the first
21 | // line is executed again.
22 | function draw() {
23 | background(0);
24 | y = y - 4;
25 | if (y < 0) {
26 | y = height;
27 | }
28 | line(0, y, width, y);
29 | }
30 |
31 | function mousePressed() {
32 | redraw();
33 | }
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/06_Functions.js:
--------------------------------------------------------------------------------
1 | /*
2 | *@name Functions
3 | *@description The drawTarget() function makes it easy to draw many distinct
4 | *targets. Each call to drawTarget() specifies the position, size, and number of
5 | *rings for each target.
6 | */
7 |
8 | function setup() {
9 | createCanvas(720, 400);
10 | background(51);
11 | noStroke();
12 | noLoop();
13 | }
14 |
15 | function draw() {
16 | drawTarget(width*0.25, height*0.4, 200, 4);
17 | drawTarget(width*0.5, height*0.5, 300, 10);
18 | drawTarget(width*0.75, height*0.3, 120, 6);
19 | }
20 |
21 | function drawTarget(xloc, yloc, size, num) {
22 | grayvalues = 255/num;
23 | steps = size/num;
24 | for (i = 0; i < num; i++) {
25 | fill(i*grayvalues);
26 | ellipse(xloc, yloc, size - i*steps, size - i*steps);
27 | }
28 | }
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/07_Recursion.js:
--------------------------------------------------------------------------------
1 | /*
2 | *@name Recursion
3 | *@description A demonstration of recursion, which means functions call themselves.
4 | * Notice how the drawCircle() function calls itself at the end of its block.
5 | * It continues to do this until the variable "level" is equal to 1.
6 | */
7 |
8 | function setup() {
9 | createCanvas(720, 400);
10 | noStroke();
11 | noLoop();
12 | }
13 |
14 | function draw() {
15 | drawCircle(width/2, 280, 6);
16 | }
17 |
18 | function drawCircle(x, radius, level) {
19 | var tt = 126 * level/4.0;
20 | fill(tt);
21 | ellipse(x, height/2, radius*2, radius*2);
22 | if(level > 1) {
23 | level = level - 1;
24 | drawCircle(x - radius/2, radius/2, level);
25 | drawCircle(x + radius/2, radius/2, level);
26 | }
27 | }
--------------------------------------------------------------------------------
/examples/examples_src/00_Structure/08_Create_Graphics.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Create Graphics
3 | * @description Creates and returns a new p5.Renderer object. Use this
4 | * class if you need to draw into an off-screen graphics buffer. The two parameters
5 | * define the width and height in pixels.
6 | */
7 |
8 | var pg;
9 |
10 | function setup(){
11 | createCanvas(710, 400);
12 | pg = createGraphics(400, 250);
13 | }
14 |
15 | function draw(){
16 | fill(0, 12);
17 | rect(0, 0, width, height);
18 | fill(255);
19 | noStroke();
20 | ellipse(mouseX, mouseY, 60, 60);
21 |
22 | pg.background(51);
23 | pg.noFill();
24 | pg.stroke(255);
25 | pg.ellipse(mouseX-150, mouseY-75, 60, 60);
26 |
27 | //Draw the offscreen buffer to the screen with image()
28 | image(pg, 150, 75);
29 | }
--------------------------------------------------------------------------------
/examples/examples_src/01_Form/00_Points_and_Lines.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Points and Lines
3 | * @description Points and lines can be used to draw basic geometry.
4 | * Change the value of the variable 'd' to scale the form. The four
5 | * variables set the positions based on the value of 'd'.
6 | */
7 | function setup() {
8 |
9 | var d = 70;
10 | var p1 = d;
11 | var p2 = p1+d;
12 | var p3 = p2+d;
13 | var p4 = p3+d;
14 |
15 | // Sets the screen to be 720 pixels wide and 400 pixels high
16 | createCanvas(720, 400);
17 | background(0);
18 | noSmooth();
19 |
20 | translate(140, 0);
21 |
22 | // Draw gray box
23 | stroke(153);
24 | line(p3, p3, p2, p3);
25 | line(p2, p3, p2, p2);
26 | line(p2, p2, p3, p2);
27 | line(p3, p2, p3, p3);
28 |
29 | // Draw white points
30 | stroke(255);
31 | point(p1, p1);
32 | point(p1, p3);
33 | point(p2, p4);
34 | point(p3, p1);
35 | point(p4, p2);
36 | point(p4, p4);
37 | }
--------------------------------------------------------------------------------
/examples/examples_src/01_Form/01_Shape_Primitives.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Shape Primitives
3 | * @description The basic shape primitive functions are triangle(),
4 | * rect(), quad(), ellipse(), and arc(). Squares are made with rect()
5 | * and circles are made with ellipse(). Each of these functions requires
6 | * a number of parameters to determine the shape's position and size.
7 | */
8 | function setup() {
9 |
10 | // Sets the screen to be 720 pixels wide and 400 pixels high
11 | createCanvas(720, 400);
12 | background(0);
13 | noStroke();
14 |
15 | fill(204);
16 | triangle(18, 18, 18, 360, 81, 360);
17 |
18 | fill(102);
19 | rect(81, 81, 63, 63);
20 |
21 | fill(204);
22 | quad(189, 18, 216, 18, 216, 360, 144, 360);
23 |
24 | fill(255);
25 | ellipse(252, 144, 72, 72);
26 |
27 | fill(204);
28 | triangle(288, 18, 351, 360, 288, 360);
29 |
30 | fill(255);
31 | arc(479, 300, 280, 280, PI, TWO_PI);
32 | }
--------------------------------------------------------------------------------
/examples/examples_src/01_Form/02_Pie_Chart.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Pie Chart
3 | * @description Uses the arc() function to generate a pie chart from the data
4 | * stored in an array.
5 | */
6 | var angles = [ 30, 10, 45, 35, 60, 38, 75, 67 ];
7 |
8 | function setup() {
9 | createCanvas(720, 400);
10 | noStroke();
11 | noLoop(); // Run once and stop
12 | }
13 |
14 | function draw() {
15 | background(100);
16 | pieChart(300, angles);
17 | }
18 |
19 | function pieChart(diameter, data) {
20 | var lastAngle = 0;
21 | for (var i = 0; i < data.length; i++) {
22 | var gray = map(i, 0, data.length, 0, 255);
23 | fill(gray);
24 | arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
25 | lastAngle += radians(angles[i]);
26 | }
27 | }
--------------------------------------------------------------------------------
/examples/examples_src/01_Form/06_Bezier.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Bezier
3 | * @description The first two parameters for the bezier() function specify the
4 | * first point in the curve and the last two parameters specify the last point.
5 | * The middle parameters set the control points that define the shape of the
6 | * curve.
7 | */
8 | function setup() {
9 | createCanvas(720, 400);
10 | stroke(255);
11 | noFill();
12 | }
13 |
14 | function draw() {
15 | background(0);
16 | for (var i = 0; i < 200; i += 20) {
17 | bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/examples/examples_src/01_Form/07_3D_Primitives.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name 3D Primitives
3 | * @frame 720,400 (optional)
4 | * @description Placing mathematically 3D objects in synthetic space.
5 | * The box() and sphere() functions take at least one parameter to specify their
6 | * size. These shapes are positioned using the translate() function.
7 | */
8 | function setup() {
9 | createCanvas(710, 400, WEBGL);
10 | }
11 |
12 | function draw() {
13 | background(100);
14 | noStroke();
15 |
16 | push();
17 | translate(-300, 200);
18 | rotateY(1.25);
19 | rotateX(-0.9);
20 | box(100);
21 | pop();
22 |
23 | noFill();
24 | stroke(255);
25 | push();
26 | translate(500, height*0.35, -200);
27 | sphere(300);
28 | pop();
29 | }
--------------------------------------------------------------------------------
/examples/examples_src/02_Data/00_Variables.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Variables
3 | * @description Variables are used for storing values. In this example, change
4 | * the values of variables to affect the composition.
5 | */
6 | function setup() {
7 |
8 | createCanvas(720, 400);
9 | background(0);
10 | stroke(153);
11 | strokeWeight(4);
12 | strokeCap(SQUARE);
13 |
14 | var a = 50;
15 | var b = 120;
16 | var c = 180;
17 |
18 | line(a, b, a+c, b);
19 | line(a, b+10, a+c, b+10);
20 | line(a, b+20, a+c, b+20);
21 | line(a, b+30, a+c, b+30);
22 |
23 | a = a + c;
24 | b = height-b;
25 |
26 | line(a, b, a+c, b);
27 | line(a, b+10, a+c, b+10);
28 | line(a, b+20, a+c, b+20);
29 | line(a, b+30, a+c, b+30);
30 |
31 | a = a + c;
32 | b = height-b;
33 |
34 | line(a, b, a+c, b);
35 | line(a, b+10, a+c, b+10);
36 | line(a, b+20, a+c, b+20);
37 | line(a, b+30, a+c, b+30);
38 | }
--------------------------------------------------------------------------------
/examples/examples_src/02_Data/01_True_and_False.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name True and False
3 | * @description A Boolean variable has only two possible values: true or false.
4 | * It is common to use Booleans with control statements to determine the flow
5 | * of a program. In this example, when the boolean value "x" is true, vertical
6 | * black lines are drawn and when the boolean value "x" is false, horizontal
7 | * gray lines are drawn.
8 | */
9 | function setup() {
10 |
11 | createCanvas(720, 400);
12 | background(0);
13 | stroke(255);
14 |
15 | var b = false;
16 | var d = 20;
17 | var middle = width/2;;
18 |
19 | for (var i = d; i <= width; i += d) {
20 |
21 | if (i < middle) {
22 | b = true;
23 | } else {
24 | b = false;
25 | }
26 |
27 | if (b == true) {
28 | // Vertical line
29 | line(i, d, i, height-d);
30 | }
31 |
32 | if (b == false) {
33 | // Horizontal line
34 | line(middle, i - middle + d, width-d, i - middle + d);
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/examples/examples_src/04_Control/00_Iteration.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Iteration
3 | * @description Iteration with a "for" structure to construct repetitive forms.
4 | */
5 | var y;
6 | var num = 14;
7 |
8 | function setup() {
9 |
10 | createCanvas(720, 360);
11 | background(102);
12 | noStroke();
13 |
14 | // Draw white bars
15 | fill(255);
16 | y = 60;
17 | for(var i = 0; i < num/3; i++) {
18 | rect(50, y, 475, 10);
19 | y+=20;
20 | }
21 |
22 | // Gray bars
23 | fill(51);
24 | y = 40;
25 | for(var i = 0; i < num; i++) {
26 | rect(405, y, 30, 10);
27 | y += 20;
28 | }
29 | y = 50;
30 | for(var i = 0; i < num; i++) {
31 | rect(425, y, 30, 10);
32 | y += 20;
33 | }
34 |
35 | // Thin lines
36 | y = 45;
37 | fill(0);
38 | for(var i = 0; i < num-1; i++) {
39 | rect(120, y, 40, 1);
40 | y+= 20;
41 | }
42 | }
--------------------------------------------------------------------------------
/examples/examples_src/04_Control/01_Embedded_Iteration.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Embedded Iteration
3 | * @description Embedding "for" structures allows repetition in two dimensions.
4 | */
5 | function setup() {
6 |
7 | createCanvas(720, 360);
8 | background(0);
9 | noStroke();
10 |
11 | var gridSize = 35;
12 |
13 | for (var x = gridSize; x <= width - gridSize; x += gridSize) {
14 | for (var y = gridSize; y <= height - gridSize; y += gridSize) {
15 | noStroke();
16 | fill(255);
17 | rect(x-1, y-1, 3, 3);
18 | stroke(255, 50);
19 | line(x, y, width/2, height/2);
20 | }
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/examples/examples_src/04_Control/02_Conditionals_1.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Conditionals 1
3 | * @description Conditions are like questions.
4 | * They allow a program to decide to take one action if
5 | * the answer to a question is true or to do another action
6 | * if the answer to the question is false.
7 | * The questions asked within a program are always logical
8 | * or relational statements. For example, if the variable 'i' is
9 | * equal to zero then draw a line.
10 | */
11 | function setup() {
12 |
13 | createCanvas(720, 360);
14 | background(0);
15 |
16 | for(var i = 10; i < width; i += 10) {
17 | // If 'i' divides by 20 with no remainder draw the first line
18 | // else draw the second line
19 | if(i%20 == 0) {
20 | stroke(255);
21 | line(i, 80, i, height/2);
22 | } else {
23 | stroke(153);
24 | line(i, 20, i, 180);
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/examples/examples_src/04_Control/03_Conditionals_2.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Conditionals 2
3 | * @description We extend the language of conditionals from the previous
4 | * example by adding the keyword "else". This allows conditionals
5 | * to ask two or more sequential questions, each with a different
6 | * action.
7 | */
8 | function setup() {
9 |
10 | createCanvas(720, 360);
11 | background(0);
12 |
13 | for(var i = 2; i < width-2; i += 4) {
14 | // If 'i' divides by 20 with no remainder
15 | if((i % 20) == 0) {
16 | stroke(255);
17 | line(i, 80, i, height/2);
18 | // If 'i' divides by 10 with no remainder
19 | } else if ((i % 10) == 0) {
20 | stroke(153);
21 | line(i, 20, i, 180);
22 | // If neither of the above two conditions are met
23 | // then draw this line
24 | } else {
25 | stroke(102);
26 | line(i, height/2, i, height-20);
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/examples/examples_src/05_Image/00_Load_and_Display_Image.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Load and Display Image
3 | * @description Images can be loaded and displayed to the screen at their
4 | * actual size or any other size.
5 | *
To run this example locally, you will need an
6 | * image file, and a running
7 | * local server.
8 |
9 | */
10 | var img; // Declare variable 'img'.
11 |
12 | function setup() {
13 | createCanvas(720, 400);
14 | img = loadImage("assets/moonwalk.jpg"); // Load the image
15 | }
16 |
17 | function draw() {
18 | // Displays the image at its actual size at point (0,0)
19 | image(img, 0, 0);
20 | // Displays the image at point (0, height/2) at half size
21 | image(img, 0, height/2, img.width/2, img.height/2);
22 | }
23 |
--------------------------------------------------------------------------------
/examples/examples_src/05_Image/01_Background_Image.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Background Image
3 | * @description This example presents the fastest way to load a
4 | * background image into Processing. To load an image as the background,
5 | * it must be the same width and height as the program.
6 | *
To run this example locally, you will need an
7 | * image file, and a running
8 | * local server.
9 | */
10 | var bg;
11 | var y = 0;
12 |
13 | function setup() {
14 | // The background image must be the same size as the parameters
15 | // into the createCanvas() method. In this program, the size of
16 | // the image is 720x400 pixels.
17 | bg = loadImage("assets/moonwalk.jpg");
18 | createCanvas(720, 400);
19 | }
20 |
21 | function draw() {
22 | background(bg);
23 |
24 | stroke(226, 204, 0);
25 | line(0, y, width, y);
26 |
27 | y++;
28 | if (y > height) {
29 | y = 0;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/examples/examples_src/05_Image/02_Transparency.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Transparency
3 | * @description Move the pointer left and right across the image to change its
4 | * position. This program overlays one image over another by modifying the
5 | * alpha value of the image with the tint() function.
6 | *
To run this example locally, you will need an
7 | * image file, and a running
8 | * local server.
9 | */
10 | var img;
11 | var offset = 0;
12 | var easing = 0.05;
13 |
14 | function setup() {
15 | createCanvas(720, 400);
16 | img = loadImage("assets/moonwalk.jpg"); // Load an image into the program
17 | }
18 |
19 | function draw() {
20 | image(img, 0, 0); // Display at full opacity
21 | var dx = (mouseX-img.width/2) - offset;
22 | offset += dx * easing;
23 | tint(255, 127); // Display at half opacity
24 | image(img, offset, 0);
25 | }
26 |
--------------------------------------------------------------------------------
/examples/examples_src/05_Image/03_Alpha_Mask.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Alpha Mask
3 | * @description Loads a "mask" for an image to specify the transparency in
4 | * different parts of the image. The two images are blended together using
5 | * the mask() method of p5.Image.
6 | *
To run this example locally, you will need two
7 | * image files, and a running
8 | * local server.
9 | */
10 | var img;
11 | var imgMask;
12 |
13 | function preload() {
14 | img = loadImage("assets/moonwalk.jpg");
15 | imgMask = loadImage("assets/mask.png");
16 | }
17 |
18 | function setup() {
19 | createCanvas(720, 400);
20 | img.mask(imgMask);
21 | imageMode(CENTER);
22 | }
23 |
24 | function draw() {
25 | background(0, 102, 153);
26 | image(img, width/2, height/2);
27 | image(img, mouseX, mouseY);
28 | }
29 |
--------------------------------------------------------------------------------
/examples/examples_src/05_Image/04_Create_Image.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Create Image
3 | * @description The createImage() function provides a fresh buffer of pixels to
4 | * play with. This example creates an image gradient.
5 | */
6 | var img; // Declare variable 'img'.
7 |
8 | function setup() {
9 | createCanvas(720, 400);
10 | img = createImage(230, 230);
11 | img.loadPixels();
12 | for(var x = 0; x < img.width; x++) {
13 | for(var y = 0; y < img.height; y++) {
14 | var a = map(y, 0, img.height, 255, 0);
15 | img.set(x, y, [0, 153, 204, a]);
16 | }
17 | }
18 | img.updatePixels();
19 | }
20 |
21 | function draw() {
22 | background(0);
23 | image(img, 90, 80);
24 | image(img, mouseX-img.width/2, mouseY-img.height/2);
25 | }
--------------------------------------------------------------------------------
/examples/examples_src/07_Color/00_Hue.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Hue
3 | * @description Hue is the color reflected from or transmitted through an
4 | * object and is typically referred to as the name of the color (red, blue,
5 | * yellow, etc.) Move the cursor vertically over each bar to alter its hue.
6 | */
7 | var barWidth = 20;
8 | var lastBar = -1;
9 |
10 | function setup() {
11 | createCanvas(720, 400);
12 | colorMode(HSB, height, height, height);
13 | noStroke();
14 | background(0);
15 | }
16 |
17 | function draw() {
18 | var whichBar = mouseX / barWidth;
19 | if (whichBar !== lastBar) {
20 | var barX = whichBar * barWidth;
21 | fill(mouseY, height, height);
22 | rect(barX, 0, barWidth, height);
23 | lastBar = whichBar;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/examples_src/07_Color/01_Saturation.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Saturation
3 | * @description Saturation is the strength or purity of the color and
4 | * represents the amount of gray in proportion to the hue. A "saturated"
5 | * color is pure and an "unsaturated" color has a large percentage of gray.
6 | * Move the cursor vertically over each bar to alter its saturation.
7 | */
8 | var barWidth = 20;
9 | var lastBar = -1;
10 |
11 | function setup() {
12 | createCanvas(720, 400);
13 | colorMode(HSB, width, height, 100);
14 | noStroke();
15 | }
16 |
17 | function draw() {
18 | var whichBar = mouseX / barWidth;
19 | if (whichBar != lastBar) {
20 | var barX = whichBar * barWidth;
21 | fill(barX, mouseY, 66);
22 | rect(barX, 0, barWidth, height);
23 | lastBar = whichBar;
24 | }
25 | }
--------------------------------------------------------------------------------
/examples/examples_src/07_Color/06_Radial_Gradient.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Radial Gradient
3 | * @description Draws a series of concentric circles to create a gradient
4 | * from one color to another.
5 | */
6 | var dim;
7 |
8 | function setup() {
9 | createCanvas(710, 400);
10 | dim = width/2;
11 | background(0);
12 | colorMode(HSB, 360, 100, 100);
13 | noStroke();
14 | ellipseMode(RADIUS);
15 | frameRate(1);
16 | }
17 |
18 | function draw() {
19 | background(0);
20 | for (var x = 0; x <= width; x+=dim) {
21 | drawGradient(x, height/2);
22 | }
23 | }
24 |
25 | function drawGradient(x, y) {
26 | var radius = dim/2;
27 | var h = random(0, 360);
28 | for (var r = radius; r > 0; --r) {
29 | fill(h, 90, 90);
30 | ellipse(x, y, r, r);
31 | h = (h + 1) % 360;
32 | }
33 | }
--------------------------------------------------------------------------------
/examples/examples_src/08_Math/00_incrementdecrement.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Increment Decrement
3 | * @description Writing "a++" is equivalent to "a = a + 1".
4 | * Writing "a--" is equivalent to "a = a - 1".
5 | */
6 | var a;
7 | var b;
8 | var direction;
9 |
10 | function setup() {
11 | createCanvas(710, 400);
12 | colorMode(RGB, width);
13 | a = 0;
14 | b = width;
15 | direction = true;
16 | frameRate(30);
17 | }
18 |
19 | function draw() {
20 | a++;
21 | if(a > width) {
22 | a = 0;
23 | direction = !direction;
24 | }
25 | if(direction == true){
26 | stroke(a);
27 | } else {
28 | stroke(width-a);
29 | }
30 | line(a, 0, a, height/2);
31 |
32 | b--;
33 | if(b < 0) {
34 | b = width;
35 | }
36 | if(direction == true) {
37 | stroke(width-b);
38 | } else {
39 | stroke(b);
40 | }
41 | line(b, height/2+1, b, height);
42 | }
--------------------------------------------------------------------------------
/examples/examples_src/08_Math/03_distance2d.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Distance 2D
3 | * @description Move the mouse across the image to obscure
4 | * and reveal the matrix. Measures the distance from the mouse
5 | * to each square and sets the size proportionally.
6 | */
7 | var max_distance;
8 |
9 | function setup() {
10 | createCanvas(710, 400);
11 | noStroke();
12 | max_distance = dist(0, 0, width, height);
13 | }
14 |
15 | function draw() {
16 | background(0);
17 |
18 | for(var i = 0; i <= width; i += 20) {
19 | for(var j = 0; j <= height; j += 20) {
20 | var size = dist(mouseX, mouseY, i, j);
21 | size = size/max_distance * 66;
22 | ellipse(i, j, size, size);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/examples/examples_src/08_Math/04_sine.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Sine
3 | * @description Smoothly scaling size with the sin() function.
4 | */
5 | var diameter;
6 | var angle = 0;
7 |
8 | function setup() {
9 | createCanvas(710, 400);
10 | diameter = height - 10;
11 | noStroke();
12 | fill(255, 204, 0);
13 | }
14 |
15 | function draw() {
16 | background(0);
17 |
18 | var d1 = 10 + (sin(angle) * diameter/2) + diameter/2;
19 | var d2 = 10 + (sin(angle + PI/2) * diameter/2) + diameter/2;
20 | var d3 = 10 + (sin(angle + PI) * diameter/2) + diameter/2;
21 |
22 | ellipse(0, height/2, d1, d1);
23 | ellipse(width/2, height/2, d2, d2);
24 | ellipse(width, height/2, d3, d3);
25 |
26 | angle += 0.02;
27 | }
28 |
--------------------------------------------------------------------------------
/examples/examples_src/08_Math/11_doubleRandom.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Double Random
3 | * @frame 720,400 (optional)
4 | * @description Using two random() calls and the point()
5 | * function to create an irregular sawtooth line.
6 | * Original by by Ira Greenberg.
7 | */
8 | var totalPts = 300;
9 | var steps = totalPts + 1;
10 |
11 | function setup() {
12 | createCanvas(710, 400);
13 | stroke(255);
14 | frameRate(1);
15 | }
16 |
17 | function draw() {
18 | background(0);
19 | var rand = 0;
20 | for (var i = 1; i < steps; i++) {
21 | point( (width/steps) * i, (height/2) + random(-rand, rand) );
22 | rand += random(-5, 5);
23 | }
24 | }
--------------------------------------------------------------------------------
/examples/examples_src/08_Math/12_random.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Random
3 | * @description Random numbers create the basis of this image.
4 | * Each time the program is loaded the result is different.
5 | */
6 | function setup() {
7 | createCanvas(710, 400);
8 | background(0);
9 | strokeWeight(20);
10 | frameRate(2);
11 | }
12 |
13 | function draw() {
14 | for (var i = 0; i < width; i++) {
15 | var r = random(255);
16 | stroke(r);
17 | line(i, 0, i, height);
18 | }
19 | }
--------------------------------------------------------------------------------
/examples/examples_src/08_Math/13_noise1D.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Noise1D
3 | * @description Using 1D Perlin Noise to assign location.
4 | */
5 | var xoff = 0.0;
6 | var xincrement = 0.01;
7 |
8 | function setup() {
9 | createCanvas(710, 400);
10 | background(0);
11 | noStroke();
12 | }
13 |
14 | function draw() {
15 | // Create an alpha blended background
16 | fill(0, 10);
17 | rect(0,0,width,height);
18 |
19 | //float n = random(0,width); // Try this line instead of noise
20 |
21 | // Get a noise value based on xoff and scale
22 | // it according to the window's width
23 | var n = noise(xoff)*width;
24 |
25 | // With each cycle, increment xoff
26 | xoff += xincrement;
27 |
28 | // Draw the ellipse at the value produced by perlin noise
29 | fill(200);
30 | ellipse(n,height/2, 64, 64);
31 | }
--------------------------------------------------------------------------------
/examples/examples_src/10_Interaction/20_Follow1.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Follow 1
3 | * @frame 710,400
4 | * @description A line segment is pushed and pulled by the cursor.
5 | * Based on code from Keith Peters.
6 | */
7 | var x = 100,
8 | y = 100,
9 | angle1 = 0.0,
10 | segLength = 50;
11 |
12 |
13 | function setup() {
14 | createCanvas(710, 400);
15 | strokeWeight(20.0);
16 | stroke(255, 100);
17 | }
18 |
19 | function draw() {
20 | background(0);
21 |
22 | dx = mouseX - x;
23 | dy = mouseY - y;
24 | angle1 = atan2(dy, dx);
25 | x = mouseX - (cos(angle1) * segLength);
26 | y = mouseY - (sin(angle1) * segLength);
27 |
28 | segment(x, y, angle1);
29 | ellipse(x, y, 20, 20);
30 | }
31 |
32 | function segment(x, y, a) {
33 | push();
34 | translate(x, y);
35 | rotate(a);
36 | line(0, 0, segLength, 0);
37 | pop();
38 | }
39 |
--------------------------------------------------------------------------------
/examples/examples_src/10_Interaction/21_Follow2.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Follow 2
3 | * @frame 710,400
4 | * @description A two-segmented arm follows the cursor position. The relative
5 | * angle between the segments is calculated with atan2() and the position
6 | * calculated with sin() and cos(). Based on code from Keith Peters.
7 | */
8 | var x = [0,0],
9 | y = [0,0],
10 | segLength = 50;
11 |
12 | function setup() {
13 | createCanvas(710, 400);
14 | strokeWeight(20.0);
15 | stroke(255, 100);
16 | }
17 |
18 | function draw() {
19 | background(0);
20 | dragSegment(0, mouseX, mouseY);
21 | dragSegment(1, x[0], y[0]);
22 | }
23 |
24 | function dragSegment(i, xin, yin) {
25 | var dx = xin - x[i];
26 | var dy = yin - y[i];
27 | var angle = atan2(dy, dx);
28 | x[i] = xin - cos(angle) * segLength;
29 | y[i] = yin - sin(angle) * segLength;
30 | segment(x[i], y[i], angle);
31 | }
32 |
33 | function segment(x, y, a) {
34 | push();
35 | translate(x, y);
36 | rotate(a);
37 | line(0, 0, segLength, 0);
38 | pop();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/examples_src/11_Objects/01_Objects.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Objects
3 | * @description Create a Jitter class, instantiate an object,
4 | * and move it around the screen. Adapted from Getting Started with
5 | * Processing by Casey Reas and Ben Fry.
6 | */
7 | var bug; // Declare object
8 |
9 | function setup() {
10 | createCanvas(710, 400);
11 | // Create object
12 | bug = new Jitter();
13 | }
14 |
15 | function draw() {
16 | background(50, 89, 100);
17 | bug.move();
18 | bug.display();
19 | }
20 |
21 | // Jitter class
22 | function Jitter() {
23 | this.x = random(width);
24 | this.y = random(height);
25 | this.diameter = random(10, 30);
26 | this.speed = 1;
27 |
28 | this.move = function() {
29 | this.x += random(-this.speed, this.speed);
30 | this.y += random(-this.speed, this.speed);
31 | };
32 |
33 | this.display = function() {
34 | ellipse(this.x, this.y, this.diameter, this.diameter);
35 | }
36 | };
37 |
--------------------------------------------------------------------------------
/examples/examples_src/11_Objects/03_Objects_Array.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Array of Objects
3 | * @description Create a Jitter class, instantiate an array of objects
4 | * and move them around the screen.
5 | */
6 | var bugs = []; // array of Jitter objects
7 |
8 | function setup() {
9 | createCanvas(710, 400);
10 | // Create objects
11 | for (var i=0; i<50; i++) {
12 | bugs.push(new Jitter());
13 | }
14 | }
15 |
16 | function draw() {
17 | background(50, 89, 100);
18 | for (var i=0; ip5.dom library
5 | * for this example to work in your own project.
6 | * Move the sliders to control the R, G, B values of the background.
7 | */
8 | var rSlider, gSlider, bSlider;
9 |
10 | function setup() {
11 | // create canvas
12 | createCanvas(710, 400);
13 | textSize(15)
14 | noStroke();
15 |
16 | // create sliders
17 | rSlider = createSlider(0, 255, 100);
18 | rSlider.position(20, 20);
19 | gSlider = createSlider(0, 255, 0);
20 | gSlider.position(20, 50);
21 | bSlider = createSlider(0, 255, 255);
22 | bSlider.position(20, 80);
23 | }
24 |
25 | function draw() {
26 | var r = rSlider.value();
27 | var g = gSlider.value();
28 | var b = bSlider.value();
29 | background(r, g, b);
30 | text("red", 165, 35);
31 | text("green", 165, 65);
32 | text("blue", 165, 95);
33 | }
34 |
--------------------------------------------------------------------------------
/examples/examples_src/16_Dom/11_Capture.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Video Capture
3 | * @frame 710,240
4 | * @description
To run this example locally, you will need the
5 | * p5.dom library
6 | * at least one video file, and a running local server.
7 | * Capture video from the webcam and display
8 | * on the canvas as well with invert filter. Note that by
9 | * default the capture feed shows up, too. You can hide the
10 | * feed by uncommenting the capture.hide() line.
11 | */
12 | var capture;
13 |
14 | function setup() {
15 | createCanvas(390, 240);
16 | capture = createCapture(VIDEO);
17 | capture.size(320, 240);
18 | //capture.hide();
19 | }
20 |
21 | function draw() {
22 | background(255);
23 | image(capture, 0, 0, 320, 240);
24 | filter('INVERT');
25 | }
26 |
--------------------------------------------------------------------------------
/examples/examples_src/20_3D/01_sine_cosine_in_3D.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Sine Cosine in 3D
3 | * @description Sine, cosine and push / pop could be applied in 3D as well.
4 | */
5 | function setup(){
6 | createCanvas(710, 400, WEBGL);
7 | }
8 |
9 | function draw(){
10 | background(250);
11 | rotateY(frameCount * 0.01);
12 |
13 | for(var j = 0; j < 5; j++){
14 | push();
15 | for(var i = 0; i < 80; i++){
16 | translate(sin(frameCount * 0.001 + j) * 100, sin(frameCount * 0.001 + j) * 100, i * 0.1);
17 | rotateZ(frameCount * 0.002);
18 | push();
19 | sphere(8, 6, 4);
20 | pop();
21 | }
22 | pop();
23 | }
24 | }
--------------------------------------------------------------------------------
/examples/examples_src/20_3D/02_multiple_ligthts.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Multiple Lights
3 | * @description All types of lights could be used in one sketch.
4 | */
5 | function setup(){
6 | createCanvas(710, 400, WEBGL);
7 | }
8 |
9 | function draw(){
10 | background(0);
11 |
12 | var locY = (mouseY / height - 0.5) * (-2);
13 | var locX = (mouseX / width - 0.5) * 2;
14 |
15 | ambientLight(50);
16 | directionalLight(200, 0, 0, 0.25, 0.25, 0.25);
17 | pointLight(0, 0, 200, locX, locY, 0);
18 | pointLight(200, 200, 0, -locX, -locY, 0);
19 |
20 | push();
21 | translate(-250, 0, 0);
22 | rotateZ(frameCount * 0.02);
23 | rotateX(frameCount * 0.02);
24 | specularMaterial(250);
25 | box(100, 100, 100);
26 | pop();
27 |
28 | translate(250, 0, 0);
29 | ambientMaterial(250);
30 | sphere(120, 64);
31 | }
--------------------------------------------------------------------------------
/examples/examples_src/20_3D/04_textures.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Textures
3 | * @description Images and videos are supported for texture.
4 | */
5 | // video source: https://vimeo.com/90312869
6 | var img;
7 | var vid;
8 | var theta = 0;
9 |
10 | function setup(){
11 | createCanvas(710, 400, WEBGL);
12 |
13 | img = loadImage("assets/cat.jpg");
14 | vid = createVideo(["assets/360video_256crop_v2.mp4"]);
15 | vid.loop();
16 | vid.hide();
17 | }
18 |
19 | function draw(){
20 | background(250);
21 | translate(-220,0,0);
22 | push();
23 | rotateZ(theta * mouseX * 0.001);
24 | rotateX(theta * mouseX * 0.001);
25 | rotateY(theta * mouseX * 0.001);
26 | //pass image as texture
27 | texture(vid);
28 | sphere(150);
29 | pop();
30 | translate(440,0,0);
31 | push();
32 | rotateZ(theta * 0.1);
33 | rotateX(theta * 0.1);
34 | rotateY(theta * 0.1);
35 | texture(img);
36 | box(100, 100, 100);
37 | pop();
38 | theta += 0.05;
39 | }
--------------------------------------------------------------------------------
/examples/examples_src/20_3D/07_orbit_control.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Orbit Control
3 | * @description Orbit control allows you to drag and move around the world.
4 | */
5 | function setup(){
6 | createCanvas(710, 400, WEBGL);
7 | }
8 |
9 | function draw(){
10 | background(250);
11 | var radius = width * 1.5;
12 |
13 | //drag to move the world.
14 | orbitControl();
15 |
16 | normalMaterial();
17 | translate(0, 0, -600);
18 | for(var i = 0; i <= 12; i++){
19 | for(var j = 0; j <= 12; j++){
20 | push();
21 | var a = j/12 * PI;
22 | var b = i/12 * PI;
23 | translate(sin(2 * a) * radius * sin(b), cos(b) * radius / 2 , cos(2 * a) * radius * sin(b));
24 | if(j%2 === 0){
25 | cone(30, 30);
26 | }else{
27 | box(30, 30, 30);
28 | }
29 | pop();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/examples/examples_src/33_Sound/00_Load_and_Play_Sound.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @name Load and Play Sound
3 | * @description Load sound during preload(). Play a sound when canvas is clicked.
4 | *
To run this example locally, you will need the
5 | * p5.sound library
6 | * a sound file, and a running local server.
7 | */
8 | var song;
9 |
10 | function setup() {
11 | song = loadSound('assets/lucky_dragons_-_power_melody.mp3');
12 | createCanvas(720, 200);
13 | background(255,0,0);
14 | }
15 |
16 | function mousePressed() {
17 | if ( song.isPlaying() ) { // .isPlaying() returns a boolean
18 | song.stop();
19 | background(255,0,0);
20 | } else {
21 | song.play();
22 | background(0,255,0);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/examples_src/33_Sound/12_FFT_Spectrum.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @name Frequency Spectrum
3 | * @description
Visualize the frequency spectrum of live audio input.