Skip to content

Instantly share code, notes, and snippets.

@lmccart
Created October 4, 2018 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmccart/3aaaa4a8a4145046ea1dfe30c59cb69e to your computer and use it in GitHub Desktop.
Save lmccart/3aaaa4a8a4145046ea1dfe30c59cb69e to your computer and use it in GitHub Desktop.
generated score p5.js
/////////////////////////////////////////////////////////////////////////////////
///// INTRO P5 / ABSTRACT SCORE (20 mins)
// editor.p5js.org
createCanvas(w, h);
setup() and draw();
background('name');
background(r, g, b);
// draw and style ellipse
ellipse(x, y, w, h);
fill()
stroke();
strokeWeight(weight);
// introduce random
random(min, max);
noLoop();
// introduce other shapes
rect(x, y, w, h);
line(x1, y1, x2, y2);
triangle(x1, y1, x2, y2, x3, y3);
// text
text('word', x, y);
/////////////////////////////////////////////////////////////////////////////////
///// RANDOM TEXT / ARRAYS (20 mins)
var instructions = [
'Text like you mean it',
'Rely heavily on humor',
'Use your words',
'Take photos of the fun, unique activities you do',
'Limit the selfies',
'Watch your mouth',
'Don’t be creepy',
'Keep a firm grasp on reality',
'Say goodnight',
'Act on mutual interest',
'Reaffirm your admiration after an enjoyable date',
'Follow up sensual encounters'
];
function setup() {
createCanvas(windowWidth, windowHeight);
textSize(40);
fill('brown');
textAlign(CENTER);
}
function draw() {
background(255, 255, 245, 5);
}
// draw instruct, place in draw
function drawInstruct() {} // random location
// set interval
setInterval(drawInstruct, 1000);
// get random instruct
function drawInstruct() {
var instruct = getRandom();
text(instruct, random(width), random(height));
}
function getRandom() {
var n = floor(random(0, instructions.length));
return instructions[n];
}
// take out interval, add mousePressed
function mousePressed() {
background(255, 255, 245, 50);
var instruct = getRandom();
text(instruct, mouseX, mouseY);
}
/////////////////////////////////////////////////////////////////////////////////
///// RANDOM WORDNIK: SCORE (20 mins)
// wordnik base. file > duplicate
// random score
function setup() {
createCanvas(windowWidth, windowHeight);
print(data);
textSize(30);
stroke(255);
fill(255);
textAlign(CENTER);
background(0);
// handle data
for (var i in data) {
var word = data[i].word;
console.log(word);
text(word, random(width, random(height));
}
}
// draw line
var x = 0;
var y = 0;
for (var i in data) {
var word = data[i].word;
console.log(word);
var newX = random(width);
var newY = random(height);
text(word, newX, newY);
line(x, y, newX, newY);
x = newX;
y = newY;
}
var x = 0;
var y = 0;
/////////////////////////////////////////////////////////////////////////////////
///// RANDOM WORDNIK: CLICK
function mousePressed() {
loadJSON(getVerbsURL, handleResult);
}
function handleResult(data) {
background('cyan');
var word = data[0].word;
text(word, width/2, height/2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment