Skip to content

Instantly share code, notes, and snippets.

@VoQn
Created January 27, 2009 14:29
Show Gist options
  • Save VoQn/53360 to your computer and use it in GitHub Desktop.
Save VoQn/53360 to your computer and use it in GitHub Desktop.
市松模様を出力するprocessing sketch
// Checkers
// bult with Processing
// Jan 27 2009
// by VoQn
color[] colors = new color[ 4];
Checker checker;
void setup(){
size(400,800);
colorMode(HSB,360,100,100,100);
smooth();
noLoop();
// Setup Color Array
colors[0] = color(0,30,20);
colors[1] = color(0,20,10);
colors[2] = color(10,30,10);
colors[3] = color(10,20,20);
// Test Perameter
float X = float(width/40);
float Y = float(height/40);
float Width = float(width*38/40);
float Height = float(height*38/40);
int Xnum = 15;
int Ynum = 31;
float marginX = 2;
float marginY = 2;
checker = new Checker(X, Y, Width, Height, Xnum, Ynum, marginX, marginY);
}
void draw(){
background(0,0,0);
checker.drawRects();
checker.drawEllipses();
}
// generate checker class
class Checker {
float x,y;
float dx,dy;
float selWidth, selHeight;
float chWidth, chHeight;
float marginX,marginY;
int numXLine,numYLine;
int selCount = 0;
Checker(float _x, float _y, float _width, float _height, int numx, int numy, float marginx, float marginy){
chWidth = _width;
chHeight = _height;
numXLine = numx;
numYLine = numy;
marginX = marginx;
marginY = marginy;
selWidth = (chWidth + marginX*(numXLine-1)) / numXLine; // chWidth = selWidth * numXLine + marginX*(numXLine-1);
selHeight = (chHeight + marginY*(numYLine-1)) / numYLine; // chHeight = selHeight * numYLine + marginY*(numYLine-1);
dx = selWidth + marginX;
dy = selHeight + marginY;
x = _x;
y = _y;
}
int fix(int num){
if(num%2 == 1){
return num;
}
else{
return num+1;
}
}
void drawRects(){
float tmpX, tmpY;
tmpX = x + selWidth/2;
tmpY = y + selHeight/2;
selCount = 0;
while(tmpY-marginY < y+chHeight){
noStroke();
if(selCount%2 == 0){
fill(colors[0]);
}
else {
fill(colors[1]);
}
rectMode(CENTER);
rect(tmpX,tmpY,selWidth,selHeight);
tmpX += dx;
if(tmpX-marginX > X+chWidth){
tmpX = x + selWidth/2;
tmpY += dy;
}
selCount += 1;
}
}
void drawEllipses(){
float tmpX, tmpY;
tmpX = x + selWidth/2;
tmpY = y + selHeight/2;
selCount = 0;
while(tmpY-marginY < y+chHeight){
noStroke();
if(selCount%2 == 0){
fill(colors[2]);
}
else {
fill(colors[3]);
}
ellipseMode(CENTER);
ellipse(tmpX,tmpY,selWidth*99/100,selHeight*99/100);
tmpX += dx;
if(tmpX > x+chWidth){
tmpX = x + selWidth/2;
tmpY += dy;
}
selCount += 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment