using the buttons "r," "g", and "b" will raise the values of the fill color in RGB color mode by 5 for each letter respectively. 1 , 2, and 3 are hotkeys for R G and B respectively to add 10 to the value. Pressing 0 resets all values to 0. Double clicking clears the background. Draw shapes using the mouse. release mouse when done with one shape. Press "f" to fill the drawn shape. value of current color will print in console when value is adjusted
A fork of 2/11 by Fraser Kim
xxxxxxxxxx
var points = [];
let R = 0;
let G = 0;
let B = 0;
var currentColor = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
colorMode(RGB);
var currentColor = [R,G,B];
}
//draw line of shape and save vector points
function draw() {
if (mouseIsPressed) {
var fast = dist(pmouseX,pmouseY,mouseX,mouseY);
fast = constrain(fast,0,10);
strokeWeight (fast/2);
line(pmouseX,pmouseY,mouseX,mouseY);
//draw a line
//create a vector for the current coordinates
var p = createVector(mouseX, mouseY);
//add it at the end of the points array
points.push(p);
}
}
//if mouse is double clicked, erase
function doubleClicked() {
{
background(255);
}
}
function keyPressed() {
//when keys r,g,and b are pressed, add '5' to values R, G, and B respectively
if (key=="r"){
R = (R + 5);
}
//faster key to add to R value
if (key == "1"){
R = (R + 10);
}
if (key == "g"){
G = (G + 5);
}
//faster key to add to G value
if (key == "2"){
G = (G+ 10);
}
if (key == "b"){
B = (B + 5);
}
//faster key to add to B value
if (key == "3"){
B = (B + 10);
}
//reset all color values when 0 is pressed
if (key == 0){
R = (0);
G = (0);
B = (0);
}
//if the colors max out past 255, reset to 0
if (R > 255){
R = (R-255);
}
if (G > 255){
G = (G-255);
}
if (B > 255){
B = (B-255);
}
let currentColor = [R,G,B];
if (key == "p");{
print(currentColor);
}
//just creates shape to fill
beginShape();
//go through all points drawn
for (var i = 0; i < points.length; i++) {
thisPoint = points[i];
vertex(thisPoint.x, thisPoint.y);
//shape is not filled unless 'f' is pressed
if (key == "f"){
fill(currentColor);
}
else {
noFill();
}
}
endShape();
//delete all the saved points
points = [];
}
//refereneces: cycle through colors, arrays and saving vector points