public void run() { while (running) { if (!paused) { if (mode == 0) { for (double i = 0; i < 3.14f; i = i + 0.1f) { for (int j = 0; j < 12; j++) { double osc = Math.sin(i) * 127; int value = (int) osc; MIDILight(j, value); } delay(30); } for (double i = 3.14f; i >= 0; i = i - 0.1f) { for (int j = 0; j < 12; j++) { double osc = Math.sin(i) * 127; int value = (int) osc; MIDILight(j, value); } delay(30); } } else if (mode == 1) { for (int j = 0; j < 12; j++) { MIDILight(j, 127); } mode = 1000; } else if (mode == 2) { for (int j = 0; j < 12; j++) { MIDILight(j, 0); } mode = 1000; } else if (mode == 3) { int controller = (int) random(12); int randomValue = (int) random(127); MIDILight(controller, randomValue); delay(30); } else if (mode == 4) { for (int i = 0; i < 64; i++) { for (int j = 0; j < 12; j++) { MIDILight(j, i * 2); } delay(20); } for (int i = 63; i >= 0; i--) { for (int j = 0; j < 12; j++) { MIDILight(j, i * 2); } delay(20); } } else { delay(10); // FIX THIS. WITHOUT THIS THE CPU USE GOES THROUGH THE ROOF. NEED A WAY // TO SLEEP THIS THREAD WHEN IT'S NOT IN USE. } } } System.out.println(id + " thread is done!"); }
private void drawShooter() { stroke(255); double x2 = width / 2 - 75 * (Math.cos(radians((float) angledegrees))); // calculates point to draw line from double y2 = 75 * (Math.sin( radians( (float) angledegrees))); // calculates y co-ord to draw line from using trig // fucntions line( width / 2, height - (15 * height / 480), (float) x2, height - (15 * height / 480) - (float) y2); // draws line if (angledegrees == 170 || angledegrees == 10) { // stop ball being shot horizontally. HAHA WE DIDN'T FORGET!!! increase = increase * -1; // sets shooter to rotate in opposite direction } if (canfire) { // checks if can fire angledegrees += increase; // increases only when true. This stops the animation whil ball is moving } }
private void calcCam(boolean is3D) { if (rotVector.mag() != 0 || panVector.mag() != 0 || camDist != prevCamDist) { prevCamDist = camDist; camRot += rotVector.x; if ((camPitch + rotVector.y) < 0.99 && (camPitch + rotVector.y) > 0.01) camPitch += rotVector.y; if (is3D) { PVector camPan = new PVector( (panVector.x * (float) Math.sin(Math.PI * 0.5 + (Math.PI * camRot))) + (panVector.y * (float) Math.sin(Math.PI * 1.0 + (Math.PI * camRot))), (panVector.y * (float) Math.cos(Math.PI * 1.0 + (Math.PI * camRot))) + (panVector.x * (float) Math.cos(Math.PI * 0.5 + (Math.PI * camRot)))); camPan.mult(0.05f * PVector.dist(camPos, camCenter)); camCenter.x += camPan.x; camCenter.y += camPan.y; camPan.x = 0; camPan.y = 0; } else { camCenter.x -= 0.05f * (camPos.z - camCenter.z) * panVector.x; camCenter.y += 0.05f * (camPos.z - camCenter.z) * panVector.y; } panVector.x = 0; panVector.y = 0; rotVector.x = 0; rotVector.y = 0; camPos.x = camCenter.x - camDist * (float) Math.sin(Math.PI * camRot) * (float) Math.sin(Math.PI * camPitch); camPos.y = camCenter.y - camDist * (float) Math.cos(Math.PI * camRot) * (float) Math.sin(Math.PI * camPitch); camPos.z = camCenter.z - camDist * (float) Math.cos(Math.PI * camPitch); } }