/** * Called in init(). Do not call manually except if you know what yeu do. */ protected void initGraphics() { this.graphics = (PGraphicsOpenGL) parent.createGraphics((int) (frameWidth * quality), (int) (frameHeight * quality), PApplet.OPENGL); }
public String read() { if (!enabled) return ""; writer.flush(); String[] lines = PApplet.loadStrings(file); String concat = ""; for (String line: lines) { concat += line + "\n"; } return concat; }
/** * @nowebref */ static public void saveStrings(File file, String data[]) { saveStrings(createOutput(file), data); }
static public String[] loadStrings(File file) { InputStream is = createInput(file); if (is != null) return loadStrings(is); return null; }
public void snap() { if (getCount() == 0) return; float x0 = visX0.getTarget(); float x1 = visX1.getTarget(); int i0 = PApplet.constrain(PApplet.round(x0 / itemWidth), 0, getCount() - 1); int i1 = PApplet.constrain(PApplet.round(x1 / itemWidth), 0, getCount() - 1); if (PApplet.abs(i0 * itemWidth - x0) < SNAP_THRESHOLD) { visX0.setTarget(i0 * itemWidth); } else if (PApplet.abs(i1 * itemWidth - x1) < SNAP_THRESHOLD) { visX1.setTarget(i1 * itemWidth); } }
lensFilter = parent.loadShader( ARDisplay.class.getResource("distortFrag.glsl").toString(), ARDisplay.class.getResource("distortVert.glsl").toString()); mapImg = parent.createImage((int) (quality * frameWidth), (int) (quality * frameHeight), PApplet.RGB); mapImg.loadPixels(); parent.colorMode(PApplet.RGB, 1.0f); int k = 0; for (int y = 0; y < mapImg.height; y++) { float g = ((float) out[1] - y) / mag + 0.5f;// / frameHeight; mapImg.pixels[k++] = parent.color(r, g, parent.random(1f)); parent.colorMode(PApplet.RGB, 255);
/** * ( begin auto-generated from beginRecord.xml ) * * Opens a new file and all subsequent drawing functions are echoed to this * file as well as the display window. The <b>beginRecord()</b> function * requires two parameters, the first is the renderer and the second is the * file name. This function is always used with <b>endRecord()</b> to stop * the recording process and close the file. * <br /> <br /> * Note that beginRecord() will only pick up any settings that happen after * it has been called. For instance, if you call textFont() before * beginRecord(), then that font will not be set for the file that you're * recording to. * * ( end auto-generated ) * * @webref output:files * @param renderer PDF or SVG * @param filename filename for output * @see PApplet#endRecord() */ public PGraphics beginRecord(String renderer, String filename) { filename = insertFrame(filename); PGraphics rec = createGraphics(width, height, renderer, filename); beginRecord(rec); return rec; }
public static boolean isRed(PGraphics g, int incomingPix, int baseline, float threshold) { int r1 = incomingPix >> 16 & 255; int r2 = baseline >> 16 & 255; return abs(r1 - r2) < threshold; }
String[] lines = PApplet.loadStrings(cfgFile); if (0 < lines.length) { miraFolder = new File(lines[0]); PApplet.saveStrings(cfgFile, new String[] {miraFolder.getAbsolutePath()});
/** * @nowebref */ static public void saveStrings(OutputStream output, String[] data) { PrintWriter writer = createWriter(output); for (int i = 0; i < data.length; i++) { writer.println(data[i]); } writer.flush(); writer.close(); }
String getColLabel() { if (view != null && (viewTask == null || viewTask.isDone())) { float x0 = x.get() - visX0.get() + padding; float y0 = y.get() + padding; float w0 = w - 2 * padding; float h0 = h.get() - 2 * padding; double valx = PApplet.constrain((mouseX - x0) / w0, 0, 1); double valy = PApplet.constrain((mouseY - y0) / h0, 0, 1); return view.getLabelX(valx, valy); } return ""; }
PApplet applet = new PApplet(); PGraphics g = applet.createGraphics(200, 400, PApplet.JAVA2D) // same params as size() g.beginDraw(); g.ellipse // ... etc, your drawing goes here g.endDraw(); g.save("filename.png");
public PGraphicsOpenGL getGraphics() { if(this.isDrawingOnDisplay){ return (PGraphicsOpenGL) parent.getGraphics(); } if (thisGraphics == null) { thisGraphics = (PGraphicsOpenGL) parent.createGraphics( this.getRenderingSizeX(), this.getRenderingSizeY(), PApplet.P3D); } return thisGraphics; }
filename = insertFrame(filename); PGraphics rec = createGraphics(width, height, renderer, filename); g.beginRaw(rec); return rec;
static public void saveFile(String str, File file) throws IOException { File temp = File.createTempFile(file.getName(), null, file.getParentFile()); try { // fix from cjwant to prevent symlinks from being destroyed. File canon = file.getCanonicalFile(); file = canon; } catch(IOException e) { throw new IOException("Could not resolve canonical representation of " + file.getAbsolutePath()); } PApplet.saveStrings(temp, new String[] { str }); if(file.exists()) { boolean result = file.delete(); if (!result) { throw new IOException("Could not remove old version of " + file.getAbsolutePath()); } } boolean result = temp.renameTo(file); if(!result) throw new IOException("Could not replace " + file.getAbsolutePath()); }
public void saveStrings(String filename, String strings[]) { saveStrings(saveFile(filename), strings); }
/** * Works if the source is IPLImage ?. * * @param context * @return */ public PImage getPImageCopy(PApplet context) { PImage out = context.createImage(this.width, this.height, RGB); ImageUtils.IplImageToPImage(currentImage, this.format == PixelFormat.RGB, out); return out; }
/** * Convenience method so that PApplet.main("YourSketch") launches a sketch, * rather than having to wrap it into a single element String array. * @param mainClass name of the class to load (with package if any) */ static public void main(final String mainClass) { main(mainClass, null); }