// // Construct2.java // Construct2 // // Created by Fredrik Olofsson on Fri Aug 01 2003. // Copyright (c) 2003 Fredrik Olofsson Musikproduktion. All rights reserved. // A simple Java applet // // 040920 ported to processing //--------------------------------------------------------------------------------------------------- Date d= new Date(); Random r= new Random(d.getTime()); int c; int i, step_X, step_Y; int x= 10; int y= 10; int dx= 1; int dy= 1; int v= 1; int m= 1; int col= 4; int row= 3; int mov_X= 95; int mov_Y= 95; int max_X; int max_Y; void setup() { size(640, 480); framerate(30); max_X= width; max_Y= height; background(255); nytt(); } void draw() { if(r.nextInt()%1881==0 || mousePressed) { //slumpa nytt background(255); //rensa skŠrmen repaint(); nytt(); //nya vŠrden } stroke(c, 55, 66); i++; drawFO(); //rita punkt(er) x= x + (dx * step_X); //flytta position x if (x < 1) //om vŠnster kant dx= Math.abs(r.nextInt() % 2); //vŠnd eller stŒ still i x-led else if (x > (max_X / col)) //om hšger kant dx= 0 - Math.abs(r.nextInt() % 2); //vŠnd eller stŒ still i x-led y= y + (dy * step_Y); //flytta position y if (y < 1) //om švre kanten dy= Math.abs(r.nextInt() % 2); //vŠnd eller stŒ still i y-led else if (y > (max_Y / row)) //om nedre kanten dy= 0 - Math.abs(r.nextInt() % 2); //vŠnd eller stŒ still i y-led switch (v) { case 1: variant1(); break; case 2: variant2(); break; case 3: variant3(); break; case 4: variant4(); break; case 5: variant5(); break; case 6: variant6(); break; } } //--------------------------------------------------------------------------------------------------- void variant1() { //1. slumpa riktningar individuellt if (Math.abs(r.nextInt() % 100) >= mov_X) slumpaRiktningX(); if (Math.abs(r.nextInt() % 100) >= mov_Y) slumpaRiktningY(); } void variant2() { //2. slumpa alltid riktningar tillsammans slumpaRiktningXY(); } void variant3() { //3. slumpa riktningar individuellt if (Math.abs(r.nextInt() % 100) >= mov_X) if (dx == 0 && x >= 1) //dra Œt vŠnster dx= -1; else dx= 0; if (Math.abs(r.nextInt() % 100) >= mov_Y) if (dy == 0 && y >= 1) //dra uppŒt dy= -1; else dy= 0; } void variant4() { //4. slumpa riktningar individuellt if (Math.abs(r.nextInt() % 100) >= mov_X) if (dx == 0 && x >= 1) //dra Œt vŠnster dx= -1; else dx= 0; if (Math.abs(r.nextInt() % 100) >= mov_Y) if (dy == 0 && y <= max_Y / row) //dra nedŒt dy= 1; else dy= 0; } void variant5() { //5. slumpa riktningar individuellt if (Math.abs(r.nextInt() % 100) >= mov_X) if (dx == 0 && x <= max_X / col) //dra Œt hšger dx= 1; else dx= 0; if (Math.abs(r.nextInt() % 100) >= mov_Y) if (dy == 0 && y >= 1) //dra uppŒt dy= -1; else dy= 0; } void variant6() { //6. slumpa riktningar individuellt if (Math.abs(r.nextInt() % 100) >= mov_X) if (dx == 0 && x <= max_X / col) //dra Œt hšger dx= 1; else dx= 0; if (Math.abs(r.nextInt() % 100) >= mov_Y) if (dy == 0 && y <= max_Y / row) //dra nedŒt dy= 1; else dy= 0; } //--------------------------------------------------------------------------------------------------- void nytt() { v= Math.abs(r.nextInt() % 6) + 1; m= Math.abs(r.nextInt() % 16) + 1; col= Math.abs(r.nextInt() % 12) + 1; row= Math.abs(r.nextInt() % 7) + 1; step_X= 1; //step_X= Math.abs(r.nextInt() % 2) + 1; step_Y= 1; //step_Y= Math.abs(r.nextInt() % 2) + 1; slumpaRiktningXY(); c= Math.abs(r.nextInt() % 255); } void slumpaRiktningXY() { while ((dx==0) && (dy==0)) { //kolla att inte bŒda riktningar blir 0 dx= r.nextInt() % 2; dy= r.nextInt() % 2; } } void slumpaRiktningX() { dx= r.nextInt() % 2; } void slumpaRiktningY() { dy= r.nextInt() % 2; } //--------------------------------------------------------------------------------------------------- void drawFO() { int i, j, iCol, jRow; for (i= 0; i < col; i++) { for (j = 0; j < row; j++) { iCol= Math.round((max_X / col) * i); jRow= Math.round((max_Y / row) * j); switch (m) { //kolla mapping case 1: mapping1(i, j, iCol, jRow); break; case 2: mapping2(i, j, iCol, jRow); break; case 3: mapping3(i, j, iCol, jRow); break; case 4: mapping4(i, j, iCol, jRow); break; case 5: mapping5(i, j, iCol, jRow); break; case 6: mapping6(i, j, iCol, jRow); break; case 7: mapping7(i, j, iCol, jRow); break; case 8: mapping8(i, j, iCol, jRow); break; case 9: mapping9(i, j, iCol, jRow); break; case 10: mapping10(i, j, iCol, jRow); break; case 11: mapping11(i, j, iCol, jRow); break; case 12: mapping12(i, j, iCol, jRow); break; case 13: mapping13(i, j, iCol, jRow); break; case 14: mapping14(i, j, iCol, jRow); break; case 15: mapping15(i, j, iCol, jRow); break; case 16: mapping16(i, j, iCol, jRow); break; } } } } //--------------------------------------------------------------------------------------------------- void mapping1(int i, int j, int iCol, int jRow) { //no flip point(x + iCol, y + jRow); } void mapping2(int i, int j, int iCol, int jRow) { //flip all x point(mirrorX(x) + iCol, y + jRow); } void mapping3(int i, int j, int iCol, int jRow) { //flip all y point(x + iCol, mirrorY(y) + jRow); } void mapping4(int i, int j, int iCol, int jRow) { //flip all xy point(mirrorX(x) + iCol, mirrorY(y) + jRow); } //-- void mapping5(int i, int j, int iCol, int jRow) { //flip odd col x if (i % 2 == 1) point(mirrorX(x) + iCol, y + jRow); else point(x + iCol, y + jRow); } void mapping6(int i, int j, int iCol, int jRow) { //flip odd col y if (i % 2 == 1) point(x + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } void mapping7(int i, int j, int iCol, int jRow) { //flip odd col xy if (i % 2 == 1) point(mirrorX(x) + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } //-- void mapping8(int i, int j, int iCol, int jRow) { //flip odd row x if (j % 2 == 1) point(mirrorX(x) + iCol, y + jRow); else point(x + iCol, y + jRow); } void mapping9(int i, int j, int iCol, int jRow) { //flip odd row y if (j % 2 == 1) point(x + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } void mapping10(int i, int j, int iCol, int jRow) { //flip odd row xy if (j % 2 == 1) point(mirrorX(x) + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } //-- void mapping11(int i, int j, int iCol, int jRow) { //flip odd col & even row x, flip even col & odd row x if (i % 2 == 1 && j % 2 == 0) point(mirrorX(x) + iCol, y + jRow); else if (i % 2 == 0 && j % 2 == 1) point(mirrorX(x) + iCol, y + jRow); else point(x + iCol, y + jRow); } void mapping12(int i, int j, int iCol, int jRow) { //flip odd col & even row y, flip even col & odd row y if (i % 2 == 1 && j % 2 == 0) point(x + iCol, mirrorY(y) + jRow); else if (i % 2 == 0 && j % 2 == 1) point(x + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } void mapping13(int i, int j, int iCol, int jRow) { //flip odd col & even row xy, flip even col & odd row xy if (i % 2 == 1 && j % 2 == 0) point(mirrorX(x) + iCol, mirrorY(y) + jRow); else if (i % 2 == 0 && j % 2 == 1) point(mirrorX(x) + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } //-- void mapping14(int i, int j, int iCol, int jRow) { //flip even col & even row x, flip odd col & odd row x if (i % 2 == 0 && j % 2 == 0) point(mirrorX(x) + iCol, y + jRow); else if (i % 2 == 1 && j % 2 == 1) point(mirrorX(x) + iCol, y + jRow); else point(x + iCol, y + jRow); } void mapping15(int i, int j, int iCol, int jRow) { //flip even col & even row y, flip odd col & odd row y if (i % 2 == 0 && j % 2 == 0) point(x + iCol, mirrorY(y) + jRow); else if (i % 2 == 1 && j % 2 == 1) point(x + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } void mapping16(int i, int j, int iCol, int jRow) { //flip even col & even row xy, flip odd col & odd row xy if (i % 2 == 0 && j % 2 == 0) point(mirrorX(x) + iCol, mirrorY(y) + jRow); else if (i % 2 == 1 && j % 2 == 1) point(mirrorX(x) + iCol, mirrorY(y) + jRow); else point(x + iCol, y + jRow); } //--------------------------------------------------------------------------------------------------- int mirrorX(int ox) { return Math.round((max_X / col) - ox); } int mirrorY(int oy) { return Math.round((max_Y / row) - oy); }