int WIDTH = 400; int HEIGHT = 200; int LENGTH = 10; int NUMBLADES = 30000; Blade b[] = new Blade[NUMBLADES]; int blend(int org, int col, int alpha) { // org is original colour // col is colour to add // alpha is a value between 0 and 255, // where 0 makes 'col' completely opaque int r1=(org&0x0000ff); int g1=(org&0x00ff00); int b1=(org&0xff0000); int r2=(col&0x0000ff); int g2=(col&0x00ff00); int b2=(col&0xff0000); int r3=(((alpha*(r1-r2)) >>8 )+r2)&0x000000ff; int g3=(((alpha*(g1-g2)) >>8 )+g2)&0x0000ff00; int b3=(((alpha*(b1-b2)) >>8 )+b2)&0x00ff0000; return (r3)|(g3)|(b3); } void drawline(int x0, int y0, int x1, int y1, int pix, int buffer[]) { if(x0 < 0 || x0 >= WIDTH || y0 < 0 || y0 >= HEIGHT || x1 < 0 || x1 >= WIDTH || y1 < 0 || y1 >= HEIGHT) return; int alp=32; int dy = y1 - y0; int dx = x1 - x0; int stepx, stepy; if (dy < 0) { dy = -dy; stepy = -WIDTH; } else { stepy = WIDTH; } if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } dy <<= 1; dx <<= 1; y0 *= WIDTH; y1 *= WIDTH; if (dx > dy) { int fraction = dy - (dx >> 1); while (x0 != x1) { if (fraction >= 0) { y0 += stepy; fraction -= dx; } x0 += stepx; fraction += dy; buffer[x0+y0] = blend(pix, buffer[x0+y0], alp); } } else { int fraction = dx - (dy >> 1); while (y0 != y1) { if (fraction >= 0) { x0 += stepx; fraction -= dy; } y0 += stepy; fraction += dx; buffer[x0+y0] = blend(pix, buffer[x0+y0], alp); } } } class Blade { float x, y, rot = 1, len; Blade(float xIn, float yIn, float rotIn, float lenIn) { x = xIn; y = yIn; rot = rotIn; len = lenIn; } void draw() { drawline((int)x, (int)y, (int)(x+len*sin(rot)), (int)(y+len*cos(rot)),0xff000000, pixels); } void update() { rot += 0.08; } } void setup() { size(400,200); background(#ffffff); for(int i = 0; i < NUMBLADES; i++) { b[i] = new Blade(random(WIDTH), random(HEIGHT), random(TWO_PI), random(LENGTH)); } } void loop() { for(int i = 0; i < NUMBLADES; i++) { b[i].update(); b[i].draw(); } }