• fullscreen
• PS1_05.pde
• ```int size= 50;

void setup() {
size(400,400);
smooth();
}

void draw() {

for (int y=0; y <= height; y+= size){
for (int i=0; i <= width; i+= size){

if( (i+y) % 20 ==0) {

fill(211,228,255);
}

else {
fill(0, 0, 0);
}
rect( y, i, 50, 50);
}
}
}
void keyPressed() {
saveFrame("PS1_05image.jpeg");
}
```

### tweaks (0)

This sketch is running as Java applet, exported from Processing.

## Problem Set #1 - Question 05

Draw an 8x8 checker board, using loops and conditionals.

Elto Desukane
17 Mar 2012
Used your program to draw myself some blank 9x9 grids for my knight tours.
http://i43.tinypic.com/dpfnuo.png

//toolkit needed for beep() (see BeepDemo)

int cellsize= 40;
int gridsize = 9;
int fullsize = cellsize*gridsize+1;
int dblsize = 2*(cellsize*gridsize)+cellsize+1;

int savedImageCount=0;

boolean dot1On=true; // 1x1 dot in center
boolean dot2On=false; // 3x3 box in center
boolean dot3On=false; // 5x5 box in center
boolean coordOn=true; // coord num in each cell (TODO...)

PFont fontA;

void setup() {
background(255);
size(dblsize, dblsize);
smooth();
textFont(fontA);
textAlign(LEFT,TOP);
// text("",x,y);
}

void draw() {

for (int r=0; r <= 1; r++) {
int rr=r*(cellsize*(gridsize+1));

for (int c=0; c <= 1; c++) {
int cc=c*(cellsize*(gridsize+1));

for (int y=0; y < gridsize; y++) {
int yy=y*cellsize;
for (int i=0; i < gridsize; i++) {
int ii=i*cellsize;

//fill(211,228,255);
fill(255, 255, 255);
stroke(0, 0, 0);
rect(rr+yy, cc+ii, cellsize, cellsize);
if (dot3On) rect(rr+yy+cellsize/2-2, cc+ii+cellsize/2-2, 4, 4);
if (dot2On) rect(rr+yy+cellsize/2-1, cc+ii+cellsize/2-1, 2, 2);
if (dot1On) point(rr+yy+cellsize/2, cc+ii+cellsize/2);
fill(0,0,0);
if (coordOn) text((i+1)+""+(y+1),rr+yy+2,cc+ii-1);
}
}
}
}
}//draw()

//======================================================================
void keyPressed() {
Toolkit.getDefaultToolkit().beep();
saveFrame("PS1_05image.png");
}

//======================================================================
void mousePressed() {
//to save image on mouse_right_click
boolean mouseRight=(mouseButton==RIGHT);
boolean mouseLeft=(mouseButton==LEFT);
if (mouseRight) {
Toolkit.getDefaultToolkit().beep();
String save_time=nf(year()00, 2)+nf(month(), 2)+nf(day(), 2)+"-"+nf(hour(), 2)+nf(minute(), 2)+nf(second(), 2);
savedImageCount++;
save("mP-"+save_time+".png");
println("SAVED: mP "+save_time+".png");
}
else if (mouseLeft) {
}
}//mousePressed()
You need to login/register to comment.