Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Generative Art with p5.js

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Generative Art with p5.js

Avatar for Vanessa Yuen

Vanessa Yuen

August 25, 2016
Tweet

More Decks by Vanessa Yuen

Other Decks in Programming

Transcript

  1. @vanessayuenn Generative Art is... Art that is generated by a

    process (not necessarily code) somewhat autonomously Thx Wikipedia ❤
  2. @vanessayuenn Art can be generated by... shapes & geometry Art

    from sasj.tumblr.com Done with Hexels & Processing.
  3. @vanessayuenn Art can be generated by... sound By Emily Xie;

    done with Processing. full vid: https://vimeo.com/179713914
  4. @vanessayuenn Processing? p5????? Processing is an open source programming language

    developed with an aim to make programming more accessible to non-programmers, especially visual artists. Thx Wikipedia ❤
  5. @vanessayuenn The Canvas function setup() { createCanvas(600, 400); } width:

    600px height: 400px x = 0; y = 0 x = 0; y = 400 x = 600; y = 0
  6. @vanessayuenn width: 600px height: 400px x = 0; y =

    0 x = 0; y = 400 x = 600; y = 0 The Canvas function draw() { rect(100, 200, 150, 50); } (100,200) W 150 H 50
  7. @vanessayuenn Line & Shapes rect(x, y, w, h); ellipse(x, y,

    w, h); line(x1, y1, x2, y2); triangle(x1, y1, x2, y2, x3, y3); ... AND MOAR! Go here http://p5js.org/reference/
  8. @vanessayuenn Draw a few shapes on the canvas to start

    with Want a challenge? Try something like this Hint: 1. use loops 2. 'height' & 'width' are reserved words in p5 for canvas H & W)
  9. @vanessayuenn Let's add some colors! var c = color('Pink'); var

    c = color('#FFC0CB'); var c = color(255, 192, 203);
  10. @vanessayuenn Let's add some colors! var c = color('Pink'); var

    c = color('#FFC0CB'); var c = color(255, 192, 203); var c = color(255, 192, 203, 75); R B G alpha [0 - 255]
  11. @vanessayuenn Let's add some colors! var c = color('Pink'); var

    c = color('#FFC0CB'); var c = color(255, 192, 203); var c = color(255, 192, 203, 75); // 1 value = grayscale var gray = color(100);
  12. @vanessayuenn Let's add some colors! var c = color(106, 90,

    205, 120); background(c); stroke(c); fill(c); noStroke(); noFill();
  13. @vanessayuenn Let's add some colors! var c = color(106, 90,

    205, 120); background(c); stroke(c); fill(c); fill(106, 90, 205, 120); var arr = [106, 90, 205, 120]; fill(arr);
  14. @vanessayuenn Let's add some colors! var c = color(106, 90,

    205, 120); background(c); stroke(c); fill(c); fill(106, 90, 205, 120); var arr = [106, 90, 205, 120]; fill(arr); // set colors BEFORE drawing shapes stroke(50); fill(106, 90, 205, 120); rect(100, 200, 150, 50);
  15. @vanessayuenn Let's add some colors! var c = color(106, 90,

    205, 125); background(c); stroke(c); fill(c); function draw() { var c = color(100); stroke(c); c = color(106, 90, 205); fill(c); ellipse(300, 300, 50); }
  16. @vanessayuenn Add colors to your shapes (& background)! Want a

    challenge? Make them different colors (hint: define a color palette array) var palette = [ [85,98,112], [199,244,100], [255,107,107] ]; fill(palette[0]);
  17. @vanessayuenn Give it some MOVES function setup() { } function

    draw() { } runs once loops FOREVER p5's default frame rate: 60fps draw() gets executed 60 times per second
  18. @vanessayuenn Give it some MOVES function setup() { } function

    draw() { } runs once loops FOREVER mouseX mouseY p5 exposes current mouse position as :
  19. @vanessayuenn Give it some MOVES function setup() { } function

    draw() { } function mousePressed() { ellipse(mouseX, mouseY, 50, 50); } runs once loops FOREVER only when mouse is pressed More events http://p5js.org/reference/#Events
  20. @vanessayuenn Make a drawing program! Want a challenge? Have the

    "brush" do a spray can/splatter effect (hint: use ) random()
  21. @vanessayuenn Some useful functions // random returns a float random(min,

    max); round(random(0,20)); // same as Math.round()
  22. @vanessayuenn Some useful functions // random returns a float random(min,

    max); round(random(0,20)); // same as Math.round() dist(x1, y1, x2, y2); // distance between (x1,y1) and (x2,y2)
  23. @vanessayuenn Some useful functions // random returns a float random(min,

    max); round(random(0,20)); // same as Math.round() dist(x1, y1, x2, y2); // distance between (x1,y1) and (x2,y2) map(value, min1, max1, min2, max2);
  24. @vanessayuenn Some useful functions // random returns a float random(min,

    max); round(random(0,20)); // same as Math.round() dist(x1, y1, x2, y2); // distance between (x1,y1) and (x2,y2) map(value, min1, max1, min2, max2); map value from [range1] to [range2] ☝ ☝ ☝
  25. @vanessayuenn Some useful functions // random returns a float random(min,

    max); round(random(0,20)); // same as Math.round() dist(x1, y1, x2, y2); // distance between (x1,y1) and (x2,y2) map(mouseX, 0, 600, 0, 255); map value from [range1] to [range2] ☝ ☝ ☝
  26. @vanessayuenn More Resources ✨ NYU's Integrated Digital Media course on

    Creative Coding: http://creative-coding.decontextualize.com/ ✨ Daniel Shiffman's youtube tutorials: https://www.youtube.com/user/shiffman/ ✨ Book: Nature of Code by Daniel Shiffman ✨ p5 Education Resources Page https://github.com/processing/p5.js/wiki/Education