Skip to content

Latest commit

 

History

History
108 lines (70 loc) · 5.71 KB

basicExamples.md

File metadata and controls

108 lines (70 loc) · 5.71 KB

#Basic p5js Examples

By Evelyn Eastmond

###1: Basic Drawing

Example 1-1 - basic drawing

###2: Setup/Draw, Scope

Example 2-1 - setup and draw (no graphical output, check the console
Example 2-2 - variables and scope

###3: Mouse Interaction

Example 3-1 - change background on mouse pressed
Example 3-2 - change background on mouse released
Example 3-3 - add rect on mouse released
Example 3-4 - mouse dragged vs mouse moved
Example 3-5 - fill dependent on mouse pressed
Example 3-6 - fill dependent on mouse button
Example 3-7 - movement relative to mouse position

###4: Keyboard Interaction

Example 4-1 - set position based on keyCode
Example 4-2 - set fill based on key 'a', 'b' or 'c'
Example 4-3 - keyIsPressed vs keyPressed()
Example 4-4 - draw line if key pressed

###5: For Loops

Example 5-1 - draw 4 lines
Example 5-2 - draw 4 lines again! with a for loop
Example 5-3 - draw many ellipses with nested for loops

###6: Conditionals (if] and Logic Operators

Example 6-1 - check mouse location (halves)
Example 6-2 - check mouse location (thirds)
Example 6-3 - check mouse location using OR
Example 6-4 - check mouse location (box)

###7: Drawing Web Images (some image links may not work)

Example 7-1 - render a web image following the mouse
Example 7-2 - render a web image as a background
Example 7-3 - render two web images, one very large

###8: Drawing Text

Example 8-1 - render text and set font, fill/stroke, size, style
Example 8-2 - render text using a Google Font

###9: Motion

Example 9-1 - looping motion
Example 9-2 - slowly going back and forth
Example 9-3 - bouncing color
Example 9-4 - bouncing size
Example 9-5 - bouncing size using sine
Example 9-6 - tweening
Example 9-7 - random motion

###10: Transforms

Transforms diagram - translate, rotate, scale
Example 10-1 - translate
Example 10-2 - translate accumulating with motion
Example 10-3 - scale
Example 10-4 - rotate
Example 10-5 - order of operations, rotate shape around center
Example 10-6 - push(] and pop(] transform

###11 : Map, constrain, distance

Example 11-1 - mousex and mousey
Example 11-2 - map and constrain
Example 11-3 - distance

###12: Functions

Example 12-1 - using functions to avoid repetition and help reuse code
Example 12-2 - functions with parameters
Example 12-3 - functions that return useful values

###13: Arrays

Example 13-1 - simple array example
Example 13-2 - simple array example (alternate initialization using push)
Example 13-3 - simple array example (alternate single line initialization)
Example 13-4 - using a for loop to initialize
Example 13-5 - using a for loop to draw (line height)
Example 13-6 - using a for loop to draw (strokeWeight)
Example 13-7 - use case: dealing with many moving parts
Example 13-8 - using multiple arrays