int xSize = 500; int ySize = 400; int xMid = xSize/2; int yMid = ySize/2; int border = 400; int totalMoths = 350; Camera camera; Moth[] moth; BImage wing; BImage wingAlpha; BImage glow; float counter = 0.0; void setup(){ size(xSize, ySize); ellipseMode(CENTER_DIAMETER); rectMode(CENTER_DIAMETER); colorMode(RGB,360); imageMode(CORNER); textureMode(IMAGE_SPACE); wing = loadImage("wing.gif"); wingAlpha = loadImage("wingAlpha.gif"); wing.alpha(wingAlpha.pixels); glow = new BImage(50,40); camera = new Camera(350.0, 60.0); // create camera (distance, lensAngle) moth = new Moth[totalMoths]; for (int i=0; i border || abs(y) > border || mousePressed){ r = R; outOfBounds = true; } else { if (outOfBounds){ r = random(0.0, TWO_PI); outOfBounds = false; } } xv = cos(r) * speed; yv = sin(r) * speed; zv = sin(counter) * 4.0; wingAngle = sin(counter*flapSpeed) * (HALF_PI - .3) - .1; //a = findAngle(x,y,x-xv,y-yv); //r = radians(a); } void findPosition(){ x += xv; y += yv; z += zv; xt = 0; yt = 0; zt = 0; } void render(){ push(); translate(x,y,z); rotateZ(r + HALF_PI); renderBody(); push(); rotateY(wingAngle); renderLargeWing(); pop(); push(); rotateY(PI - wingAngle); renderLargeWing(); pop(); pop(); } void renderBody(){ } void renderLargeWing(){ noStroke(); imageMode(CORNER); tint(150 - abs(wingAngle)*150.0, 360 - abs(wingAngle)*50.0); image(wing,0,0,wingWidth,wingLength); noTint(); } void renderSmallWing(){ beginShape(QUADS); noStroke(); //fill(0,wingAngle*50.0,255 - (wingAngle*50.0)); fill(0,0,360); vertex(0, 3, 0); vertex(wingWidth * .5, wingLength*.6, 0); vertex(wingWidth * .6, wingLength,0); vertex(0,wingLength * .8,0); endShape(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// ^^^^^^^^^^ //////////////////////////////////////////////////////////////////////////////////////////////////////////// MOTH CLASS //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// CAMERA CLASS //////////////////////////////////////////////////////////////////////////////////////////////////////////// vvvvvvvvvvvv class Camera{ // camera variables float xPos, yPos; float rotationVar; float elevation; float azimuth; float twist; float distance; float lensAngle; int toggleVar; boolean elevationAuto; boolean azimuthAuto; float elevationSpeed; float azimuthSpeed; Camera (float sentDistance, float sentLensAngle){ distance = sentDistance; lensAngle = sentLensAngle; toggleVar = 0; azimuth = 1.24; elevation = HALF_PI; } void exist(){ checkAuto(); setCamera(); } void increase(){ azimuth += .05; elevation = HALF_PI + (sin(azimuth) * .1); } void decrease(){ azimuth -= .05; elevation = HALF_PI + (sin(azimuth) * .1); } void setRotateSpeed(float aug){ azimuthAuto = true; azimuthSpeed += aug; elevationAuto = true; elevationSpeed = HALF_PI + (sin(azimuth/10.0) * .1); } void resetAutoRotate(){ azimuthAuto = false; elevationAuto = false; azimuthSpeed = 0.0; elevationSpeed = 0.0; } void checkAuto(){ if (azimuthAuto){ azimuth += azimuthSpeed; } if (elevationAuto){ elevation = HALF_PI + (sin(azimuth/3.0) * .8); } } void setCamera(){ beginCamera(); perspective(lensAngle, (float)xSize / (float)ySize, 1.0f, 200); //translate(cos(counter/100.0) * 3.0, sin(counter/50.0) * 1.5, -distance); translate(0,0,-distance); rotateX(elevation); rotateZ(-azimuth); endCamera(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// ^^^^^^^^^^^^ //////////////////////////////////////////////////////////////////////////////////////////////////////////// CAMERA CLASS //////////////////////////////////////////////////////////////////////////////////////////////////////////// float findDistance(float x1, float y1, float z1, float x2, float y2, float z2){ float xd = x1 - x2; float yd = y1 - y2; float zd = z1 - z2; float td = sqrt(xd * xd + yd * yd + zd * zd); return td; } float findAngle(float x1, float y1, float x2, float y2){ float xd = x1 - x2; float yd = y1 - y2; float t = atan2(yd,xd); float a = (180 + (-(180 * t) / PI)); return a; } // create alpha for a bitmap by analyzing brightness (code by Ryan Alexander of Motion Theory) void brightToAlpha(BImage b){ b.format = RGBA; for(int i=0; i < b.pixels.length; i++) { b.pixels[i] = color(360,360,360,360 - brightness(b.pixels[i])); } }