// Getting Processing to work on the planetarium dome. // D. Parson, Summer 2014 /* NOT NEEDED IN 2.X See http://wiki.processing.org/w/Window_Size_and_Full_Screen public void init() { frame.removeNotify(); frame.setUndecorated(true); frame.addNotify(); super.init(); } */ private PFont pfont ; void setup() { size(displayWidth, displayHeight); background(0); pfont = createFont( "Courier", 40); // use a fixed-width font!!! textFont(pfont); textAlign(CENTER); println("DISPLAY WIDTH IS " + displayWidth + ", HEIGHT IS " + displayHeight + " PIXELS."); } boolean sketchFullScreen() { return true; // Also from Preferences "Run sketches on display 2" for dome. } // My 0 degrees West Room marker says 270 // My 90 degrees North Room marker says 0 // My 180 degrees East Room marker says 90 // My 270 degrees South Room marker says 180 int [][] colors = { {128, 128, 128}, {255, 0, 0}, {255, 255, 0}, {0, 255, 0}, {0, 255, 255}, {0, 0, 255}, {255, 0, 255}, {255, 255, 255} }; int colorix = 0 ; int timeix = 0 ; // Draw ellipses out from the center, changing the color every // 10 redraws. Innermost ellipse has alpha=255, alpha scales // dow as bigger ellipses draw atop the smaller ones. void draw() { int numcircles = colors.length ; ellipseMode(CENTER); // default, X,Y gives center point for (int i = 0 ; i < numcircles ; i++) { int width = displayWidth * (i+1) / numcircles ; int height = displayHeight * (i+1) / numcircles ; int myX = (displayWidth/2) ; int myY = (displayHeight/2) ; int mycolor = (colorix + i) % numcircles ; mycolor = colorix ; // an experiment int alpha = (numcircles - i) * 255 / numcircles ; fill(colors[mycolor][0], colors[mycolor][1], colors[mycolor][2], alpha); mycolor = (mycolor + colors.length/2) % colors.length; stroke(colors[mycolor][0], colors[mycolor][1], colors[mycolor][2], 255); strokeWeight((numcircles - i) * 4); ellipse(myX, myY, height, height); } timeix += 1 ; if (timeix >= 10) { colorix = (colorix+1) % numcircles ; timeix = 0; } stroke(0,0,0); fill(0,0,0); float [] fpair = polarToCartesian(.4, 0.0); int [] ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); text("0 deg West",0,0); popMatrix(); fpair = polarToCartesian(.4, PI/2.0); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(PI/2.0); text("CS 90 deg North",0,0); popMatrix(); fpair = polarToCartesian(.4, PI); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(PI); text("180 deg East",0,0); popMatrix(); fpair = polarToCartesian(.4, 1.5 * PI); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(PI * 1.5); text("270 deg South",0,0); popMatrix(); fpair = polarToCartesian(.4, PI/4.0); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(PI/4.0); text("RRS",0,0); popMatrix(); fpair = polarToCartesian(.4, PI-PI/4.0); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(PI-PI/4.0); text("LRS",0,0); popMatrix(); fpair = polarToCartesian(.4, PI+PI/4.0); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(PI+PI/4.0); text("LFS",0,0); popMatrix(); fpair = polarToCartesian(.4, 0-PI/2.0+PI/4.0); ipair = cartesianToPhysical(fpair[0], fpair[1]); pushMatrix(); translate(ipair[0], ipair[1]); rotate(0-PI/2.0+PI/4.0); text("RFS",0,0); popMatrix(); } /** * cartesianToPhysical maps a location in the Cartesian coordinate * space -1.0, -1.0 through 1.0, 1.0 to the physical space * 0, 0 through width-1, height-1. If either input coordinate * lies outside of the -1.0..1.0 range, cartesianToPhysical returns * a pair of coordinates -1, -1 that signify clipping; the calling * code must test for this return value and not attempt to plot it. **/ int [] cartesianToPhysical(float cartesianX, float cartesianY) { int [] result = new int[2]; if (cartesianX < -1.0 || cartesianX > 1.0 || cartesianY < -1.0 || cartesianY > 1.0) { result[0] = result[1] = -1 ; return result ; } result[0] = (int)(Math.round(((cartesianX + 1.0) / 2.0) * width)); if (result[0] == width) { result[0] = width - 1 ; } result[1] = height - (int)(Math.round(((cartesianY + 1.0) / 2.0) * height)); // Physical requires Y == 0 to be at the top. if (result[1] == height) { result[1] = height - 1; } return result ; } /** * physicalToCartesian maps a location in the physical display coordinate * space 0, 0 through width-1, height-1 to the Cartesian space * -1.0, -1.0 through 1.0, 1.0. If either input coordinate * lies outside of the 0, 0 through width-1, height-1 range, cartesianToPhysical returns * a pair of coordinates -2.0, -2.0 that signify clipping; the calling * code must test for this return value and not attempt to plot it. **/ float [] physicalToCartesian(int physX, int physY) { float [] result = new float[2]; if (physX == width) { physX = width - 1 ; // same as cartesian 1.0 } if (physY == height) { physY = height - 1 ; // same as cartesian 1.0 } if (physX < 0 || physX >= width || physY < 0 || physY >= height) { result[0] = result[1] = -2.0 ; return result ; } result[0] = ((float)(physX) / (float) width * 2.0) - 1.0 ; result[1] = ((float)(physY) / (float) height * 2.0) - 1.0 ; return result ; } /** * cartesianToPolar maps a location in the Cartesian coordinate * space -1.0, -1.0 through 1.0, 1.0 to the unit circle centered * at 0,0 with a radius of 1.0. The return value stores the * polar radius in [0] and the angle in radians in [1]. * If either input coordinate * lies outside of the -1.0..1.0 range, cartesianToPolar returns * the corresponding results, and the calling code must check to * determine whether the returned radius exceeds 1.0, requiring * clipping. **/ float [] cartesianToPolar(float cartesianX, float cartesianY) { float [] result = new float[2]; float radius = (float) Math.sqrt(cartesianX * cartesianX + cartesianY * cartesianY); float angleInRadians = (float) Math.atan2(cartesianY, cartesianX); result[0] = radius ; result[1] = angleInRadians ; return result ; } /** * cartesianToPolar maps a location in the polar coordinate unit * circle 0.0, angle=0.0 upto 1.0, angle=2 * PI to the Cartesian * coordinates cenetered at 0.0,0.0. The returned result, with * Cartesian X in [0] and Y in [1], may lie outside the range * of -1.0, -1.0 through 1.0, 1.0. The caller must verify that * the return values are not outside the clipping boundary. **/ float [] polarToCartesian(float radius, float angleInRadians) { float [] result = new float[2]; result[0] = (float)(radius * Math.cos(angleInRadians)); result[1] = (float)(radius * Math.sin(angleInRadians)); return result ; }