Skip to content

Instantly share code, notes, and snippets.

@yuskesuzki
Created July 24, 2014 16:20
Show Gist options
  • Save yuskesuzki/a132628b27551f33d269 to your computer and use it in GitHub Desktop.
Save yuskesuzki/a132628b27551f33d269 to your computer and use it in GitHub Desktop.
final int RED = 0;
final int ORANGE = 1;
final int YELLOW = 2;
final int GREEN = 3;
final int BLUE = 4;
final int INDIGOBLUE = 5;
final int PURPLE = 6;
int COLORMAX = PURPLE;
float dr = 0.0;
void setup() {
size(400, 400);
smooth();
rectMode(CENTER);
}
void draw() {
if (mousePressed == true){
noCursor();
noStroke();
translate(width / 2, height / 2);
pushMatrix();
for(int i=RED; i<COLORMAX; i++) {
fillRainbowColor(i);
rotate(radians(dr));
rect(mouseX, 0+(i*5), 35, 5);
}
popMatrix();
} else {
background(255);
cursor();
}
dr += 8.0;
}
// 引数に対応する虹色のいずれかで塗りつぶす
void fillRainbowColor(int count)
{
int check = count % (COLORMAX+1);
switch(check) {
case RED:
fill(237, 26, 61);
break;
case ORANGE:
fill(255, 183, 76);
break;
case YELLOW:
fill(255, 212, 0);
break;
case GREEN:
fill(0, 128, 0);
break;
case BLUE:
fill(0, 103, 191);
break;
case INDIGOBLUE:
fill(35, 71, 148);
break;
case PURPLE:
fill(167, 87, 168);
break;
default:
fillRainbowColor((COLORMAX+1)+check);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment