/* CALCULATE COORDINATES: Determine new x-y coords given a start x-y and a distance and direction */ public static void calcCoords(int index, int x, int y, double dist, double dirn) { while (dirn < 0.0) dirn = 360.0 + dirn; while (dirn > 360.0) dirn = dirn - 360.0; // System.out.println("dirn = " + dirn); // North-East if (dirn <= 90.0) { xValues[index] = x + (int) (Math.sin(Math.toRadians(dirn)) * dist); yValues[index] = y - (int) (Math.cos(Math.toRadians(dirn)) * dist); return; } // South-East if (dirn <= 180.0) { xValues[index] = x + (int) (Math.cos(Math.toRadians(dirn - 90)) * dist); yValues[index] = y + (int) (Math.sin(Math.toRadians(dirn - 90)) * dist); return; } // South-West if (dirn <= 90.0) { xValues[index] = x - (int) (Math.sin(Math.toRadians(dirn - 180)) * dist); yValues[index] = y + (int) (Math.cos(Math.toRadians(dirn - 180)) * dist); } // Nort-West else { xValues[index] = x - (int) (Math.cos(Math.toRadians(dirn - 270)) * dist); yValues[index] = y - (int) (Math.sin(Math.toRadians(dirn - 270)) * dist); } }
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!"); }
public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) { if (lineWidth == 1) g.drawLine(x1, y1, x2, y2); else { double angle; double halfWidth = ((double) lineWidth) / 2.0; double deltaX = (double) (x2 - x1); double deltaY = (double) (y2 - y1); if (x1 == x2) angle = Math.PI; else angle = Math.atan(deltaY / deltaX) + Math.PI / 2; int xOffset = (int) (halfWidth * Math.cos(angle)); int yOffset = (int) (halfWidth * Math.sin(angle)); int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset}; int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1}; g.fillPolygon(xCorners, yCorners, 4); } }
/** Rotate theta degrees around the y axis */ void yrot(double theta) { theta *= (pi / 180); double ct = Math.cos(theta); double st = Math.sin(theta); double Nxx = (xx * ct + zx * st); double Nxy = (xy * ct + zy * st); double Nxz = (xz * ct + zz * st); double Nxo = (xo * ct + zo * st); double Nzx = (zx * ct - xx * st); double Nzy = (zy * ct - xy * st); double Nzz = (zz * ct - xz * st); double Nzo = (zo * ct - xo * st); xo = Nxo; xx = Nxx; xy = Nxy; xz = Nxz; zo = Nzo; zx = Nzx; zy = Nzy; zz = Nzz; }
/** Rotate theta degrees about the z axis */ void zrot(double theta) { theta *= pi / 180; double ct = Math.cos(theta); double st = Math.sin(theta); double Nyx = (yx * ct + xx * st); double Nyy = (yy * ct + xy * st); double Nyz = (yz * ct + xz * st); double Nyo = (yo * ct + xo * st); double Nxx = (xx * ct - yx * st); double Nxy = (xy * ct - yy * st); double Nxz = (xz * ct - yz * st); double Nxo = (xo * ct - yo * st); yo = Nyo; yx = Nyx; yy = Nyy; yz = Nyz; xo = Nxo; xx = Nxx; xy = Nxy; xz = Nxz; }
/** Rotate theta degrees about the x axis */ void xrot(double theta) { theta *= (pi / 180); double ct = Math.cos(theta); double st = Math.sin(theta); double Nyx = (yx * ct + zx * st); double Nyy = (yy * ct + zy * st); double Nyz = (yz * ct + zz * st); double Nyo = (yo * ct + zo * st); double Nzx = (zx * ct - yx * st); double Nzy = (zy * ct - yy * st); double Nzz = (zz * ct - yz * st); double Nzo = (zo * ct - yo * st); yo = Nyo; yx = Nyx; yy = Nyy; yz = Nyz; zo = Nzo; zx = Nzx; zy = Nzy; zz = Nzz; }
private int xCor(int len, double dir) { return (int) (len * Math.sin(dir)); }