xxxxxxxxxx
var points = [];
var currentColor = [];
var R = 0;
var G = 0;
var B = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
}
function draw() {
//draw line of shape and save vector points
if (mouseIsPressed) {
//draw a line
line(mouseX, mouseY, pmouseX, pmouseY);
//create a vector representing the current coordinates
var p = createVector(mouseX, mouseY);
//add it at the end of the points array
points.push(p);
}
}
function mouseReleased() {
currentColor = (R,G,B);
//fill the shape of color with a mix of values of R G and B
fill(currentColor);
}
function keyPressed() {
//assign keys to changing r g and b values of variable currentColor
if (key == "r") {
R = R + 5;
}
if (key == "g"){
G = G + 5;
}
if (key == "b"){
B = B + 5;
}
//if reached the end back to zero
if (currentColor >= 255)
currentColor = 0;
//just creates shape to fill
beginShape();
//go through all points
for (var i = 0; i < points.length; i++) {
thisPoint = points[i];
vertex(thisPoint.x, thisPoint.y);
}
endShape();
//delete all the saved points
points = [];
}
//refereneces: cycle through colors, arrays and saving vector points