hello,
I made a test with 6 different patterns with two tile sizes: 30x60 and 3x30.
How it works
The principle is always to have two loops that are within each other.
One is for the x-value (the columns) the other for y (the rows).
Thus you lay out the tiles.
Via asking if ((x%2) == 0) you can check whether a row is even or not (modulo is zero).
Depending on that, different tiles are chosen (either row or column or both).
Change the pattern
you can change the pattern in use via comment and uncomment.
Greetings, Chrisir
- // idea: http://forum.processing.org/topic/total-newbie-floor-tile-patterns
- //
- // ---------------------------------------------------------------
- //
- void setup()
- {
- // init
- size(800, 600);
- } // func
- //
- //
- void draw()
- {
- background(255);
- // chose one
- // pattern1();
- // pattern2();
- // pattern3();
- // pattern4();
- // pattern5();
- pattern6();
- } // func
- //
- // =====================================================================
- void pattern1() {
- // all big tiles
- for (int x=0; x < 10; x++) {
- for (int y=0; y < 30; y++) {
- rect (x*30, y*60, 30, 60);
- }
- }
- }
- void pattern2() {
- // big tile, 2 small ones, big tile
- for (int x=0; x < 10; x++) {
- for (int y=0; y < 30; y++) {
- if (x % 2 == 0)
- {
- // do 2 small tiles
- for (int k=0; k < 2; k++) {
- fill (k*200, 255, 255);
- rect (x*30, y*60+k*30, 30, 30);
- }
- }
- else
- {
- fill (0, 0, 255);
- rect (x*30, y*60, 30, 60);
- }
- }
- }
- }
- void pattern3() {
- // big tile, 2 small ones, big tile
- // but this time alternate rows
- for (int i=0; i < 30; i++) {
- for (int j=0; j < 30; j++) {
- // if row (aka y) is even
- if (j % 2 == 0) {
- // now check column
- if (i % 2 == 0)
- {
- for (int k=0; k < 2; k++) {
- fill (k*200, 255, 255);
- rect (i*30, j*60+k*30, 30, 30);
- }
- }
- else
- {
- fill (0, 0, 255);
- rect (i*30, j*60, 30, 60);
- }
- }
- // if row (aka y) is NOT even
- else
- {
- // now check column
- if (i % 2 == 0)
- {
- fill (0, 0, 255);
- rect (i*30, j*60, 30, 60);
- }
- else
- {
- for (int k=0; k < 2; k++) {
- //fill (0, 255, 255);
- fill (200, 255, k*255);
- rect (i*30, j*60+k*30, 30, 30);
- }
- }
- }
- }
- }
- }
- void pattern4() {
- // all small tiles
- for (int x=0; x < 10; x++) {
- for (int y=0; y < 30; y++) {
- rect (x*30, y*30, 30, 30);
- }
- }
- }
- void pattern5() {
- // small tiles and big ones (big ones are lying)
- boolean bigOne=false;
- for (int y=0; y < 30; y++) {
- for (int x=0; x < 11; x++) {
- if (!bigOne) {
- // small one
- rect (x*30, y*30, 30, 30);
- bigOne=true;
- }
- else
- {
- rect (x*30, y*30, 60, 30);
- x++;
- bigOne=false;
- }
- }
- }
- }
- void pattern6() {
- // small tiles and big ones (big ones are lying)
- // alternates in rows
- boolean bigOne=false;
- for (int y=0; y < 30; y++) {
- //
- for (int x=0; x < 34; x++) {
- if (!bigOne) {
- // small one
- fill(255, 2, 2);
- rect (x*30, y*30, 30, 30);
- bigOne=true;
- }
- else
- {
- // big
- fill(2, 2, 255);
- rect (x*30, y*30, 60, 30);
- x++;
- bigOne=false;
- }
- }
- } // for
- } // func
- // =====================================================================