public static int getComplementar(int original) { float R = Prototype.stage.red(original); float G = Prototype.stage.green(original); float B = Prototype.stage.blue(original); float minRGB = PApplet.min(R, PApplet.min(G, B)); float maxRGB = PApplet.max(R, PApplet.max(G, B)); float minPlusMax = minRGB + maxRGB; return Prototype.stage.color(minPlusMax - R, minPlusMax - G, minPlusMax - B); }
public void computeBounds() { PVector topLeft = points.get(0); PVector bottomRight = points.get(0); for (PVector v : points) { topLeft = new PVector(PApplet.min(topLeft.x, v.x), PApplet.min(topLeft.y, v.y)); bottomRight = new PVector(PApplet.max(bottomRight.x, v.x), PApplet.max(bottomRight.y, v.y)); } // bounds = new Rect(topLeft, bottomRight); }
public void calcCellPositions() { float deltaA = bag.tileSizeX + bag.tileGap; float deltaD = bag.tileSizeZ + bag.tileGap; float deltaH = 1.01f * bag.tileSizeY; float minA = -(nbrAcross - 1) * 0.5f * deltaA; float minD = -(nbrDown - 1) * 0.5f * deltaD; float minH = -0.5f * deltaH; for (int a = 0; a < 2 * nbrAcross; a++) for (int d = 0; d < 2 * nbrDown; d++) for (int h = 0; h < nbrHigh; h++) { cell[a][d][h].x = minA + a * 0.5f * deltaA; cell[a][d][h].z = minD + d * 0.5f * deltaD; cell[a][d][h].y = minH - h * deltaH; } // Calculate table size float tSize = 1.08f * PApplet.max(nbrAcross * deltaA, nbrDown * deltaD); float tHeight = 1.0f; table = new Box(app, tSize, tHeight, tSize); table.pickable(false); table.moveBy(0, 0.51f * tHeight, 0); // Now get camera nearest approach distance to avoid // P3D clipping problems nearestApproach = tSize / 1.1f; }
@Override public float applyFunction(float x, boolean clamp) { // http://en.wikipedia.org/wiki/Gompertz_curve float min_param_a = 0.0f + PConstants.EPSILON; a = PApplet.max(a, min_param_a); float b = -8.0f; float c = 0 - a * 16.0f; float y = PApplet.exp(b * PApplet.exp(c * x)); float maxVal = PApplet.exp((b * PApplet.exp(c))); float minVal = PApplet.exp(b); y = PApplet.map(y, minVal, maxVal, 0, 1); return clamp(y, clamp); }
public void mouseEvent(MouseEvent e) { float maxSide = parent.max(parent.width, parent.height); float mx = e.getX() / maxSide - 1.0f; float my = 1.0f - e.getY() / maxSide; if (e.getAction() == MouseEvent.PRESS) { Mode mode = Mode.NONE; if (e.getButton() == PApplet.LEFT) mode = Mode.ROTATE; else if (e.getButton() == PApplet.RIGHT) mode = Mode.ZOOM; else if (e.getButton() == PApplet.CENTER) mode = Mode.PAN; begin(mode, mx, my); parent.redraw(); } else if (e.getAction() == MouseEvent.DRAG) { move(mx, my); parent.redraw(); } else if (e.getAction() == MouseEvent.RELEASE) end(); }
protected void updateTexelsImpl(int x, int y, int w, int h) { int x2 = x + w; int y2 = y + h; if (!modified) { mx1 = PApplet.max(0, x); mx2 = PApplet.min(width - 1, x2); my1 = PApplet.max(0, y); my2 = PApplet.min(height - 1, y2); modified = true; } else { if (x < mx1) mx1 = PApplet.max(0, x); if (x > mx2) mx2 = PApplet.min(width - 1, x); if (y < my1) my1 = PApplet.max(0, y); if (y > my2) my2 = y; if (x2 < mx1) mx1 = PApplet.max(0, x2); if (x2 > mx2) mx2 = PApplet.min(width - 1, x2); if (y2 < my1) my1 = PApplet.max(0, y2); if (y2 > my2) my2 = PApplet.min(height - 1, y2); } }
public Level(String filename, PixelPie pie) { XML file = pie.app.loadXML(filename); // Get level properties, if any. if (file.getChild("properties") != null) { properties = new StringDict(); for (XML child : file.getChild("properties").getChildren("property")) { properties.set(child.getString("name"), child.getString("value")); } } // Get tile dimensions. tileWidth = file.getInt("tilewidth"); tileHeight = file.getInt("tileheight"); // Get Row and Column count. levelColumns = file.getInt("width"); levelRows = file.getInt("height"); // Get level dimensions. levelWidth = levelColumns * tileWidth; levelHeight = levelRows * tileHeight; // Get tileSets. tileSets = file.getChildren("tileset"); // Get objects. objects = file.getChildren("objectgroup"); // Get scripts. scripts = new HashMap<String, Script>(); for (XML objectType : objects) { String objectName = objectType.getString("name"); // Check type of object. if (objectName.substring(0, 1).equals("(")) { // Break up name into parts. String[] nameParts = PApplet.split(objectName, " "); // If script. if (nameParts[0].equals("(script)")) { // Grab script name. String name = nameParts[1]; // Initialize coordinates array (if any). IntDict scriptCoords = new IntDict(); // Check for objects in script layer. Get coordinates from these objects. if (objectType.getChild("object") != null) { for (XML coordObj : objectType.getChildren("object")) { // Check if object has a name, if not, skip it. if (coordObj.getString("name") == null) { pie.log.printlg("Script coordinate container does not have a name. Ignoring."); continue; } // Figure out object type. int coordType = 0; if (coordObj.hasChildren()) { coordType = (coordObj.getChild("polyline") != null) ? 2 : 1; } // Process coordinates depending on object type. switch (coordType) { // If rectangle, take top-left corner. case 0: scriptCoords.set( coordObj.getString("name"), PixelPie.coordToArray(coordObj.getInt("x"), coordObj.getInt("y"), this)); break; // If ellipse, take center. case 1: scriptCoords.set( coordObj.getString("name"), PixelPie.coordToArray( coordObj.getInt("x") + coordObj.getInt("width") / 2, coordObj.getInt("y") + coordObj.getInt("height") / 2, this)); break; // If poly line, record each point. case 2: String[] coordsArray = PApplet.split(coordObj.getChild("polyline").getString("points"), " "); int startX = Integer.parseInt(objectType.getChild("object").getString("x")); int startY = Integer.parseInt(objectType.getChild("object").getString("y")); for (int i = 0; i < coordsArray.length; i++) { scriptCoords.set( coordObj.getString("name") + "_" + PApplet.nf(i, 2), PixelPie.coordToArray( startX + Integer.parseInt(PApplet.split(coordsArray[i], ",")[0]), startY + Integer.parseInt(PApplet.split(coordsArray[i], ",")[1]), this)); } break; } } } else { scriptCoords = null; } // Get the total amount of frames. int endFrame = 0; for (XML obj : objectType.getChild("properties").getChildren("property")) { endFrame = PApplet.max(endFrame, PixelPie.getScriptFrame(obj.getString("name"))); } // Create the scriptAction container "children". HashMap<String, ScriptAction[]> children = new HashMap<String, ScriptAction[]>(); // Create the script object. Script Script = new Script(endFrame, scriptCoords, children, pie); scripts.put(name, Script); // Create scriptAction temporary container. This one uses a HashMap so we can dynamically // add scriptActions to it. HashMap<String, ArrayList<ScriptAction>> scriptTemp = new HashMap<String, ArrayList<ScriptAction>>(); // Add scriptActions to the temporary container. for (XML obj : objectType.getChild("properties").getChildren("property")) { String frame = PApplet.str(PixelPie.getScriptFrame(obj.getString("name"))); // Create scriptAction object from parameters. String[] actionArray = PApplet.split(obj.getString("value"), "("); String params = actionArray[1].substring(0, actionArray[1].length() - 1); ScriptAction action = null; // try {action = (scriptAction) Class.forName(app.getClass().getName() + "$script_" + // actionArray[0]).getDeclaredConstructors()[0].newInstance(new Object[]{app, params, // Script});} try { action = (ScriptAction) Class.forName(pie.app.getClass().getName() + "$script_" + actionArray[0]) .getDeclaredConstructors()[0] .newInstance(new Object[] {pie.app}); action.setup(params, Script); } catch (Exception e) { pie.log.printlg(e); } // Check whether there is an entry in the scriptTemp array. if (scriptTemp.get(frame) != null) { scriptTemp.get(frame).add(action); } else { // Initiate Arraylist. scriptTemp.put(frame, new ArrayList<ScriptAction>()); scriptTemp.get(frame).add(action); } } // Turn over contents of temporary container to "children" array. for (@SuppressWarnings("rawtypes") Map.Entry entry : scriptTemp.entrySet()) { ScriptAction[] tempActions = new ScriptAction[scriptTemp.get(entry.getKey()).size()]; for (int i = 0; i < scriptTemp.get(entry.getKey()).size(); i++) { tempActions[i] = scriptTemp.get(entry.getKey()).get(i); } children.put(entry.getKey().toString(), tempActions); } } } } // Load level layers. XML[] layers = file.getChildren("layer"); // Count number of background and level layers. for (int i = 0; i < layers.length; i++) { if (layers[i].getString("name").substring(0, 4).equals("(bg)")) { backgroundLayers++; } else { levelLayers++; } } // Initiate arrays. background = new int[backgroundLayers][levelColumns * levelRows]; levelMap = new int[levelLayers][levelColumns * levelRows]; bgScroll = new float[backgroundLayers]; // Process each layer. int currentLayer = 0; int bgCurrentLayer = 0; for (int i = 0; i < layers.length; i++) { // If it's a background layer... if (layers[i].getString("name").substring(0, 4).equals("(bg)")) { // Get properties. HashMap<String, String> prop = new HashMap<String, String>(); for (XML property : layers[i].getChild("properties").getChildren("property")) { prop.put(property.getString("name"), property.getString("value")); } // Process the scroll rate. bgScroll[bgCurrentLayer] = PApplet.constrain(Float.parseFloat(PixelPie.getProp(prop, "scroll")), 0, 1); // Process each background tile. XML[] tiles = layers[i].getChild("data").getChildren("tile"); for (int k = 0; k < tiles.length; k++) { background[bgCurrentLayer][k] = tiles[k].getInt("gid"); } // Increase background layer counter. bgCurrentLayer++; } // Else, load layer as normal. else { // Load each tile. XML[] tiles = layers[i].getChild("data").getChildren("tile"); for (int k = 0; k < tiles.length; k++) { levelMap[currentLayer][k] = tiles[k].getInt("gid"); } currentLayer++; } } }
/** @param theWindow */ void draw(ControlWindow theWindow) { // System.out.println(previousPosition+"\t"+currentPosition+"\t"+position); if (enabled) { if (mode >= Skatolo.WAIT) { previousPosition.set(currentPosition); currentPosition.set(theWindow.getPointerX(), theWindow.getPointerY(), 0); if (controller != null) { if (controller.getControlWindow().equals(theWindow)) { switch (mode) { case (Skatolo.WAIT): if (moved()) { startTime = System.nanoTime(); } if (System.nanoTime() > startTime + (delayInMillis * 1000000)) { position.set(currentPosition); alignH = Skatolo.RIGHT; if (position.x > (controller.getControlWindow().papplet().width - (getWidth() + 20))) { position.sub(new PVector(getWidth(), 0, 0)); alignH = Skatolo.LEFT; } mode = Skatolo.FADEIN; startTime = System.nanoTime(); currentAlpha = 0; } break; case (Skatolo.FADEIN): float t1 = System.nanoTime() - startTime; currentAlpha = (int) PApplet.map(t1, 0, 200 * 1000000, 0, maxAlpha); if (currentAlpha >= 250) { mode = Skatolo.IDLE; currentAlpha = 255; } break; case (Skatolo.IDLE): break; case (Skatolo.FADEOUT): float t2 = System.nanoTime() - startTime; currentAlpha = (int) PApplet.map(t2, 0, 200 * 1000000, maxAlpha, 0); if (currentAlpha <= 0) { mode = Skatolo.DONE; } break; case (Skatolo.DONE): controller = null; mode = Skatolo.INACTIVE; position.set(-1000, -1000, 0); } currentAlpha = PApplet.max(0, PApplet.min(currentAlpha, maxAlpha)); if (mode >= Skatolo.WAIT) { currentAlpha = (mode == Skatolo.WAIT) ? 0 : currentAlpha; theWindow.graphics().pushMatrix(); theWindow.graphics().translate(position.x, position.y); theWindow.graphics().translate(offset.x, offset.y); controllerView.display(theWindow.graphics(), null); // TODO: Warning HERE ! theWindow.graphics().popMatrix(); } if (mode < Skatolo.FADEOUT) { if (moved()) { deactivate(0); } } } } } } }
/** scroll the scrollList remotely. values must range between 0 and 1. */ public ListBox scroll(float theValue) { if ((items.size()) * _myItemHeight > _myBackgroundHeight) { _myScrollbar.setValue(PApplet.abs(1 - PApplet.min(PApplet.max(0, theValue), 1))); } return this; }
/** @param theWindow */ void draw(ControlWindow theWindow) { if (enabled) { if (_myMode >= ControlP5.WAIT) { previousPosition.set(currentPosition); currentPosition.set(theWindow.mouseX, theWindow.mouseY, 0); if (_myController != null) { if (_myController.getControlWindow().equals(theWindow)) { switch (_myMode) { case (ControlP5.WAIT): if (moved()) { startTime = System.nanoTime(); } if (System.nanoTime() > startTime + (_myDelayInMillis * 1000000)) { position.set(currentPosition); _myAlignH = ControlP5.RIGHT; if (position.x > (_myController.getControlWindow().papplet().width - (getWidth() + 20))) { position.sub(new PVector(getWidth(), 0, 0)); _myAlignH = ControlP5.LEFT; } _myMode = ControlP5.FADEIN; startTime = System.nanoTime(); _myAlpha = 0; } break; case (ControlP5.FADEIN): float t1 = System.nanoTime() - startTime; _myAlpha = (int) PApplet.map(t1, 0, 200 * 1000000, 0, _myMaxAlpha); if (_myAlpha >= 250) { _myMode = ControlP5.IDLE; _myAlpha = 255; } break; case (ControlP5.IDLE): break; case (ControlP5.FADEOUT): float t2 = System.nanoTime() - startTime; _myAlpha = (int) PApplet.map(t2, 0, 200 * 1000000, _myMaxAlpha, 0); if (_myAlpha <= 0) { _myMode = ControlP5.DONE; } break; case (ControlP5.DONE): _myController = null; _myMode = ControlP5.INACTIVE; position.set(-1000, -1000, 0); } _myAlpha = PApplet.max(0, PApplet.min(_myAlpha, _myMaxAlpha)); if (_myMode >= ControlP5.WAIT) { _myAlpha = (_myMode == ControlP5.WAIT) ? 0 : _myAlpha; theWindow.papplet().pushMatrix(); theWindow.papplet().translate(position.x, position.y); theWindow.papplet().translate(offset.x, offset.y); _myView.display(theWindow.papplet(), null); theWindow.papplet().popMatrix(); } if (_myMode < ControlP5.FADEOUT) { if (moved()) { deactivate(0); } } } } } } }