// Robin Edwards, 2012 // Script for making friendly moving squares // Please plagiarise at will (he'll appreciate the change from being shot at). ArrayList effects; Effect [] bgrd; char[] letters = {'a','A','b','B','c','C','d','D','e','E', 'f','F','g','G','h','H','i','I','j','J','k','K','l','L', 'm','M','n','N','o','O','p','P','q','Q','r','R','s','S', 't','T','u','U','v','V','w','W','x','X','y','Y','z','Z', '0','1','2','3','4','5','6','7','8','9'}; // 62 long PImage img; int side = 125; int x_side, y_side, init; PVector[] dirs = { // direction vectors new PVector(1, 0), new PVector(-1, 0), new PVector(0, 1), new PVector(0, -1) }; int vi; // vector randomiser float scaler; // tailor res for mobile and high-res devices PVector m, pv; void setup() { size(window.innerWidth, window.innerHeight); //size(1000, 500); background(44); x_side = width/side; y_side = height/side; img = loadImage("rectangles_background.png"); for(int i=0; i=0; i--) { effects.get(i).move(); if (effects.get(i).dead) effects.remove(i); } // mouse chaser m = new PVector(mouseX, mouseY); for(int i=0; iwidth || p.x<0 || p.y<0 || p.y>height) dead = true; else { transp -= 1; c = color(red(c), green(c), blue(c), transp); if (random(-1, 50) < 0) changeCourse(); } } else { // background tiles if (random(-1, 100) < 0) changeCourse(); if (p.x<10 || p.x>width-10 || p.y<10 || p.y>height-10) v.mult(-1); } p.add(v); } void changeCourse() { if (v.y == 0) vi = int(random(2, 4)); // horizontal movers else vi = int(random(0, 2)); // vertical movers v = new PVector(dirs[vi].x, dirs[vi].y); v.mult(speed); } } void keyPressed(){ if(key=='r') setup(); } window.onresize = function(event) { size(window.innerWidth, window.innerHeight-3); }