Skip to content

Instantly share code, notes, and snippets.

@yuskesuzki
Created July 16, 2014 09:54
Show Gist options
  • Save yuskesuzki/3b754cf7daca19ba9225 to your computer and use it in GitHub Desktop.
Save yuskesuzki/3b754cf7daca19ba9225 to your computer and use it in GitHub Desktop.
Processing sample
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;
int boxsize = 45;
final int boxsizeinit = 10;
final int boxsizemax = 120;
void setup() {
size(940, 235);
noStroke();
fill(255, 128);
}
// マウスクリックで四角のサイズを大きくする
void mouseClicked() {
boxsize+=10;
if(boxsizemax<boxsize) {
boxsize = boxsizeinit;
}
}
void draw() {
background();
for(int x=0; x<(width/boxsize); x++) {
for(int y=0; y<(height/boxsize); y++) {
count = x-y;
fillRainbowColor(count);
rect((boxsize*x), (boxsize*y) ,boxsize-1, boxsize-1);
}
}
}
// 引数に対応する虹色のいずれかで塗りつぶす
void fillRainbowColor(int count)
{
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