SHARE
TWEET

invaders

xeromino Oct 24th, 2013 644 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int sz = 15;
  2. int step = sz/5; // = 4
  3. int padding = int(sz/2);
  4. int mx,my;
  5. ArrayList invaders;
  6.  
  7. void setup() {
  8.   mx = int(900/(sz+padding));
  9.   my = int(600/(sz+padding));
  10.   size(padding+mx*(sz+padding), padding+my*(sz+padding));
  11.   background(255);
  12.   stroke(0);
  13.  
  14.   invaders = new ArrayList();
  15.  
  16.   for (float x=padding; x<width-2*padding; x += (sz+padding)) {
  17.     for (float y=padding; y<height-2*padding; y += (sz+padding)) {
  18.       Invader invader = new Invader(x, y);
  19.       invaders.add(invader);
  20.     }
  21.   }
  22.   for (int i=0; i<invaders.size();i++) {
  23.     Invader inv = (Invader) invaders.get(i);
  24.     inv.display();
  25.   }
  26. }
  27.  
  28. void draw() {
  29. }
  30.  
  31. void keyPressed() {
  32.   save(random(1234)+".gif");
  33. }
  34. void mouseClicked() {
  35.   setup();
  36. }
  37.  
  38. class Invader {
  39.   float x, y;
  40.   int c, m ;
  41.   int[][] col = new int[sz][sz];
  42.  
  43.   Invader(float _x, float _y) {
  44.     x = _x;
  45.     y = _y;
  46.     //c = 155;
  47.    
  48.     for (int j=0;j<sz;j+=step) {
  49.       m = 1;
  50.       for (int i=0;i<sz/2;i+=step) {
  51.         c = (random(1) > .5)? 255:0; //black or white?
  52.         col[j][i]= c;
  53.         col[j][i+(sz-step)/m] = c;
  54.         m++;
  55.       }
  56.     }
  57.   }
  58.  
  59.   void display() {
  60.     fill(c);
  61.     stroke(c);
  62.     for (int j=0;j<sz; j+=step) {
  63.       for (int i=0;i<sz; i+= step) {
  64.         fill(col[j][i]);
  65.         noStroke();
  66.         rect(x+i, y+j, step, step);
  67.       }
  68.     }
  69.   }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top