Processing is a java-like scripting language that is simple but yet powerful that can be used to do computer animations and graphics (images). Some simple examples of using Processing can be found at link: https://helloacm.com/processing/. Today, here is another simple example that uses this scripting language to draw a chess board. We put noLoop to disable animations (draw over and over again), thus it is straightforward to paint in the draw() function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // https://helloacm.com final int WIDTH = 500; final int HEIGHT = 500; final int BLOCKX = WIDTH / 8; final int BLOCKY = HEIGHT / 8; void setup() { size(WIDTH, HEIGHT); noLoop(); } void draw() { for (int i = 0; i < 8; i ++) { for (int j = 0; j < 8; j ++) { if ((i + j + 1) % 2 == 0) { fill(255, 255, 255); // white } else { fill(0, 0, 0); // black } rect(i * BLOCKX, j * BLOCKY, (i + 1) * BLOCKX, (j + 1) * BLOCKY); } } } |
// https://helloacm.com final int WIDTH = 500; final int HEIGHT = 500; final int BLOCKX = WIDTH / 8; final int BLOCKY = HEIGHT / 8; void setup() { size(WIDTH, HEIGHT); noLoop(); } void draw() { for (int i = 0; i < 8; i ++) { for (int j = 0; j < 8; j ++) { if ((i + j + 1) % 2 == 0) { fill(255, 255, 255); // white } else { fill(0, 0, 0); // black } rect(i * BLOCKX, j * BLOCKY, (i + 1) * BLOCKX, (j + 1) * BLOCKY); } } }
Previously, we have shown different programming languages [1][2][3][4] to do such similar things… painting a chess board is one of the interesting beginner’s tasks.
To see this image using ProcessingJS in the browser, please visit https://helloacm.com/processing/chessboard/
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Learning Processing - Simple Random Colour Bars
Next Post: Using DOMDocument in PHP to Process output HTML