Created
October 21, 2015 15:49
-
-
Save danaabs/75e25593733cf4f3903a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Unsolicited relationship advice from a purported relative at a distant family reunion | |
//have a set of preloaded images, each time 'clear' button is pressed, image refreshed | |
var d = 0; | |
var input; | |
var adviceButton; | |
var n ; | |
var comments = []; | |
var particleList = []; | |
function setup() { | |
var canvas = createCanvas(1500, 300); | |
canvas.position(0, 650); | |
for (var i = 0; i < 700; i++) { | |
particleList[i] = { | |
x: random(0, width), | |
y: random(0, height), | |
display: function() { | |
fill(random(0, 255), 0, (0,100)); | |
noStroke(); | |
ellipse(this.x, this.y, 5, 5); | |
}, | |
move: function() { | |
this.x += random(-1, 1); | |
this.y += random(-1, 1); | |
}, | |
}; | |
} | |
var img = createImg('https://s-media-cache-ak0.pinimg.com/originals/2a/60/f8/2a60f874312f3ecf48f622d177a446ca.jpg'); | |
img.size(400, 600); | |
img.position(100, 0); | |
input = createInput('your name, darling?'); | |
input.position(600, 300); | |
adviceButton = createButton('Introduce Yourself'); | |
adviceButton.style("color", "#8B008B"); | |
adviceButton.position(750, 300); | |
adviceButton.mousePressed(askReddit); | |
var clearButton = createButton('clear'); | |
clearButton.position(500, 600); | |
clearButton.mousePressed(clearAll); | |
//page title info | |
var myTitle = createP("unsolicited relationship advice from a purported relative at a distant family reunion"); | |
myTitle.position(550, 50); | |
myTitle.style("font-size", "24px"); | |
myTitle.style("font-family", "Courier"); | |
myTitle.style("text-align", "center"); | |
myTitle.style("color", "#8B008B"); | |
} | |
function askReddit() { | |
var url = 'http://www.reddit.com/r/relationships/new.json?sort=popular'; | |
loadJSON(url, getReddit); | |
d = d + 1; | |
if (d > 24) { | |
d = 0; | |
} | |
noLoop(); | |
} | |
function clearAll() { | |
for (var i = 0; i < comments.length; i++) { | |
comments[i].remove(); | |
} | |
// img2 = createImg('https://tentninja.files.wordpress.com/2014/06/crazy-lady1.jpg'); | |
// img2.size(400, 600); | |
// img2.position(100,0); | |
} | |
function getReddit(data) { | |
var redditData; | |
var redditUrl; | |
//console.log(data); | |
var total = data.data.children.length; | |
print(total); | |
//question title information | |
redditData = data.data.children[10].data.title; | |
//url to question | |
redditUrl = data.data.children[d].data.permalink; | |
//console.log(redditData); | |
console.log(redditUrl); | |
var commentUrl = 'https://www.reddit.com' + redditUrl + '.json?'; //sort=top'; | |
print(commentUrl); | |
loadJSON(commentUrl, getRedditComment); | |
} | |
function getRedditComment(data) { | |
var comment; | |
var AuntMillieSays = ["(Just wags finger)", "No.", "..."] | |
// print(data[1].data.children[0}) | |
if (data[1].data.children.length >= 1) { | |
var commentTop; | |
commentTop = data[1].data.children[0].data.body; | |
// commentTop = commentTop.replace(/him|her|he/gi, "Dana"); | |
comment = createP(input.value() + " , " + commentTop); | |
comment.style("font-size", "18px"); | |
comment.style("font-family", "Helvetica") | |
comment.style("text-align", "center"); | |
comment.position(550, 360); | |
} else { | |
if (data[1].data.children.length < 1) { | |
comment = createP(AuntMillieSays[0]); | |
comment.style("font-size", "18px"); | |
comment.style("font-family", "Helvetica") | |
comment.style("text-align", "center"); | |
comment.position(650, 380); | |
} | |
} | |
comments.push(comment); | |
} | |
function draw() { | |
background(255); | |
for (var i = 0; i < particleList.length; i++) { | |
particleList[i].display(); | |
particleList[i].move(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment