//Owen Fox
//olf@andrew.cmu.edu
//Section C
//Project week 9
var face0;
var x = 0;
var y = 0;
var r1 = 128;
var r2 = 255;
var g1 = 0;
var g2 = 230;
var b1 = 0;
var b2 = 230;
function preload() {
//loads image of roommate's face
var img0url = "http://i.imgur.com/xoW2D1C.png";
face0 = loadImage(img0url);
}
function setup() {
createCanvas(410, 804);
background(0);
face0.loadPixels();
}
function draw() {
customPixel(x,y,face0,r1,g1,b1,r2,g2,b2);
x = x + 10;
//resets x to 0 after each line
if (x > width) {
x = 0;
y = y + 10;
}
//when the progression reaches the bottom of the page, restarts and chooses a new random color pallete
if (y > height) {
clear();
background(0);
x = 0;
y = 0;
r1 = random(0,100);
g1 = random(0,100);
b1 = random(0,100);
r2 = random(101,255);
g2 = random(101,255);
b2 = random(101,255);
}
}
function customPixel(px,py,img,redstart,redstop,greenstart,greenstop,bluestart,bluestop) {
//based on example code
this.px = px;
this.py = py;
//gets the color of a given pixel of the image, then creates variables for each rgb value
var theColorAtLocationXY = img.get(px, py);
var r = theColorAtLocationXY[0];
var g = theColorAtLocationXY[1];
var b = theColorAtLocationXY[2];
//maps natural colors to a monochromatic color pallete, or any colors assigned to the function
red = map(r,0,255,redstart,redstop);
green = map(g,0,255,greenstart,greenstop);
blue = map(b,0,255,bluestart,bluestop);
//draws each circle
noStroke();
fill(red,green,blue);
ellipse(px, py, 10, 10);
}
draws a series of colored circles based on a picture taken of my roommate. When the circle progression gets to the bottom the program restarts, this time with a new set of colors.