Skip to content

Instantly share code, notes, and snippets.

View claytical's full-sized avatar

Clay Ewing claytical

View GitHub Profile
@claytical
claytical / sketch.js
Created October 20, 2015 17:19
Resizing a Canvas
var canvas;
var middle;
var paddingAmount;
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
canvas.parent('middle_panel');
middle = select('#middle_panel');
resizeCanvas(middle.width, middle.height);
}
@claytical
claytical / sketch.js
Last active November 3, 2015 16:27
Loading a sound file in p5js
var ferambie;
function preload() {
ferambie = loadSound('ferambie.mp3');
}
function setup() {
// uncomment this line to make the canvas the full size of the window
createCanvas(windowWidth, windowHeight);
// the volume is a number between 0 and 1
ferambie.setVolume(0.5);
@claytical
claytical / sketch.js
Created November 3, 2015 14:30
p5js using mic input
var mic;
var micOn;
function setup() {
// uncomment this line to make the canvas the full size of the window
createCanvas(windowWidth, windowHeight);
// the volume is a number between 0 and 1
mic = new p5.AudioIn();
micOn = false;
}
@claytical
claytical / sketch.js
Created November 3, 2015 14:47
Record and Playback Audio in p5js
var mic;
var micOn;
var recorder;
var recording;
var soundFile;
function setup() {
// uncomment this line to make the canvas the full size of the window
createCanvas(windowWidth, windowHeight);
// the volume is a number between 0 and 1
var x;
var y;
var adjustedX;
var adjustedY;
var angle = 0;
var diameter;
function setup() {
createCanvas(windowWidth,windowHeight);
x = width/2;
@claytical
claytical / sketch.js
Created November 17, 2015 16:18
Simple p5.play Example
var sprite;
var angle;
var speed;
function setup() {
createCanvas(windowWidth,windowHeight);
sprite = createSprite(width/2, height/2, 50, 50);
speed = 1;
angle = 270;
}
@claytical
claytical / sketch.js
Created November 17, 2015 16:25
Simple p5.play collision
var player;
var enemy;
var angle;
var speed;
function setup() {
createCanvas(windowWidth,windowHeight);
player = createSprite(0, 0, 50, 50);
enemy = createSprite(width/2, height/2, 100, 100);
@claytical
claytical / sketch.js
Created November 17, 2015 16:29
Simple Circle Collision
var balls = [];
function setup() {
createCanvas(windowWidth,windowHeight);
x = width/2;
y = height/2;
}
function draw() {
background(255,255,255);
@claytical
claytical / sketch.js
Created November 17, 2015 17:10
Simple Bouncing Ball
var balls = [];
var gravity = .1;
function setup() {
createCanvas(windowWidth,windowHeight);
}
function draw() {
background(255,255,255);
@claytical
claytical / sketch.js
Created January 20, 2016 16:33
Global and Local Variables
/* variables declared outside of functions are
are called "global" as they can be referred to
anywhere. */
var g_variable = 50;
function setup() {
createCanvas(400,400);
/* variables declared inside of a function are
only available in that specific function.