An online markdown blog and knowledge repository.
Host: Olivia Guzzardo @OliviaGuzzardo
Presenter/Guest: Daniel Shiffman @shiffman
"Express yourself through code"
Within index.html
:
scetch.js
) in a separate script tag.Using Libraries:
sketch.js
to start coding!root
| Libraries
| \p5.min.js
| \p5.sound.min.js
|
| \index.html
| \jsconfig.json
| \sketch.js
| \style.css
draw()
function.Describe()
enables visual representations of what is happening on-screen.A fairly light-weight brain-dump and "whoops I'm gonna want to remember that" items.
circle
: Set an x,y location and a diameter. Not radius!ellipse
: Set an x,y location and w (width) and h (height) of the ellipse. Skip h
and it will default to same as w
(like Circle()). Negative values are not processed and instead considered an empty parameter. When using WebGL mode, add parameter detail
which is an Integer indicating the count of vertices
to use to build the ellipse (max 50).A light-weight section of notes I felt were important to write-out while learning P5.
background(color)
along with other on-canvas objects, be sure to call background()
first before loading other object, otherwise they will not be visible on screen when the draw()
function is executing.createCanvas(width, height, WEBGL, canvas)
: Only use once within a setup()
function. Width and Height arguments are actually optional, defaults are 100 for both. Only use WEBGL
parameter if browser supports WebGL Mode. canvas
(optional) is an HTMLCanvasElement to use for the sketch.resizeCanvas(widnowWidth, windowHeight, noRedraw)
: Define a new width and height for the canvas. noRedraw
is boolean, defaults to false, indicates whether to delay calling reDraw()
function.preLoad()
: This is a lifecycle event handler. Guarantees these function calls complete before rendering begins: loadImage()
, loadFont()
, loadJSON()
, loadModel()
.Essential Concepts:
p5.Vector
class to perform math on Vector instances.add()
, sub()
to subtract, mult()
to multiply, and div()
to divide.p5.Vector
class also has static functions that return a new vector
instance rather than apply changes to the current instance.Note: Use createVector()
to generate a new instance of the Vector Class.
To make things 'move' on screen:
(0,0)
to have the object sit still.p5.Vector.random2D()
will work).floor(number)
: Concatenates a Number to it nearest lower whole number. Any Number type or function that returns a number type can be set as the parameter.map(value, start1, stop1, start2, stop2, withinBounds)
: Maps a value within range start1 to stop1, into the range start2 to stop2, returning the remapped number. withinBounds
is boolean, defaults to false. When set, it ensures an out-of-bounds value
is mapped to an in-bounds remapped number.noise(x, [y], [z])
: Tunable natural-seeming random number generator using Perlin Noise algorithm. Returns floating-point numbers between 0 and 1. Arguments define the 'point in space' that tune the output.noiseDetail()
: Further adjust the Perlin Noise output using 'octaves' and 'weight' to steer the noise quality.Return to Conted Index
Return to Root README