Skip to content

Instantly share code, notes, and snippets.

@slambert
Created February 7, 2018 15:17
Show Gist options
  • Save slambert/9c3b156808b3f43bb368e71f17d09a46 to your computer and use it in GitHub Desktop.
Save slambert/9c3b156808b3f43bb368e71f17d09a46 to your computer and use it in GitHub Desktop.
Color Palette example sketch includes examples of: boolean variables if/else mousepressed relational operators (> < == !--)
/*
Color Palette example sketch
includes examples of:
boolean variables
if/else
mousepressed
relational operators (> < == !--)
Steve Lambert February 7, 2018
*/
// My Pallette
// Taken from https://color.adobe.com/Aspirin-C-color-theme-251864/edit/?copy=true
color darkBlue = color(34,83,120);
color medBlue = color(22,149,163);
color lightBlue = color(172,240,242);
color offWhite = color(243,255,226);
color orange = color(235,127,0);
boolean iOnTheRightSideOfTheScreen = false;
boolean mouseButtonSwitch = false;
// other variables
float circleWidth = 150;
void setup() {
size(1000, 200);
background(offWhite);
noStroke();
} // end setup
void draw() {
background(offWhite);
if(mouseX >= width/2){
// do this stuff:
iOnTheRightSideOfTheScreen = true;
} else { // if the mouse ISN'T on the right side...
iOnTheRightSideOfTheScreen = false;
}
println("iOnTheRightSideOfTheScreen = " + iOnTheRightSideOfTheScreen);
// change color of this circle based on iOnTheRightSideOfTheScreen (left/right)
if(iOnTheRightSideOfTheScreen == true){
fill(darkBlue);
} else {
fill(orange);
}
// far right ellipse
ellipse(width/5*4, height/2, circleWidth/2, circleWidth/2);
println(circleWidth/2);
// 2nd (from right) circle
// change colors when mousebutton is pressed
if(mouseButtonSwitch == true){
fill(medBlue);
println("true");
} else {
fill(orange);
println("false");
}
println("bingo");
ellipse(width/5*3, height/2, circleWidth, circleWidth);
fill(lightBlue);
ellipse(width/5*2, height/2, circleWidth, circleWidth);
fill(orange);
ellipse(width/5*1, height/2, circleWidth, circleWidth);
}
void mousePressed(){
mouseButtonSwitch = !mouseButtonSwitch;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment