//editable variables, you can change these. int pixel = 2; //size of one pixel of the invader. int amountx = 10; //amount of invaders in x of the grid. int amounty = 18; //amount of invaders in y of the grid. int sx = 14; //spacing between invaders in x. int sy = 12; //spacing between invaders in y. //fixed variables, don't change these. int startx = 5; int starty = 5; int chance; int spacingx = 0; int spacingy = 0; int count = 0; int gridcount = 0; int horizontal = 0; int vertical = 0; boolean run = true; //these arrays are used for mirroring the white pixels, only //change if you choose the invader to contain more pixels. //current invader size: x = 10, y = 8 (x is mirrored). int blackx[] = {0, (pixel), (pixel*2), (pixel*3), (pixel*4), (pixel*5)}; int blacky[] = {0, (pixel), (pixel*2), (pixel*3), (pixel*4), (pixel*5), (pixel*6), (pixel*7)}; void setup() { size(600, 800); background(255); noStroke(); } void draw() { if (run == true) { translate(horizontal, vertical); invaders(); } } void invaders() { //this generates the grid of randoms space invaders. //the first line defines the top left beginning point of the grid, it looks //complicated but it merely centers based on the grid of the invaders. translate ((width/2)-((pixel*sx*amountx)/2), ((height/2)-((pixel*sy*amounty)/2))); while (gridcount < 9) { invader(); count = 0; spacingx = 0; spacingy = 0; } if (gridcount > 8) { horizontal += (pixel*sx); gridcount = 0; //horizontal amount of invaders. if (horizontal >= (pixel*sx*amountx)) { vertical += (pixel*sy); horizontal = 0; //vertical amount of invaders. if (vertical >= (pixel*sy*amounty)) { println("Finished."); run = false; } } } } void invader() { //this is where the generation of a single space invader happens. //20 is the approximate white holes in an avarage space invader. while (count < 20) { if (count < 8) { body(); } if (count >= 8 && count < 20) { white(); count += 1; } } gridcount += 1; } void white() { //erases white pixels randomly and symmetrically on top of the black body. //i and j refer to the index of the arrays, which determine the x and y position. int i = (int((random(0, 5)))); int j = (int((random(0, 8)))); for (int x = 0; x < 9; x++) { fill(255); rect(blackx[i], blacky[j], pixel, pixel); rect(((pixel*9)-blackx[i]), (blacky[j]), pixel, pixel); } } void body() { //generates the black body of the space invader. fill(0); rect(spacingx, spacingy, pixel, pixel); if (spacingx < (pixel*9)) { spacingx += pixel; } else { spacingy += pixel; spacingx = 0; count += 1; } }