/** * @param left number of digits to the left of the decimal point * @param right number of digits to the right of the decimal point */ static public String[] nf(float nums[], int left, int right) { String formatted[] = new String[nums.length]; for (int i = 0; i < formatted.length; i++) { formatted[i] = nf(nums[i], left, right); } return formatted; }
static public String[] nf(float[] nums) { String[] outgoing = new String[nums.length]; for (int i = 0; i < nums.length; i++) { outgoing[i] = nf(nums[i]); } return outgoing; }
static public String[] nf(int num[], int digits) { String formatted[] = new String[num.length]; for (int i = 0; i < formatted.length; i++) { formatted[i] = nf(num[i], digits); } return formatted; }
/** * number format signed (or space) * Formats a number but leaves a blank space in the front * when it's positive so that it can be properly aligned with * numbers that have a negative sign in front of them. */ static public String nfs(int num, int digits) { return (num < 0) ? nf(num, digits) : (' ' + nf(num, digits)); }
static public String[] nf(float num[], int left, int right) { String formatted[] = new String[num.length]; for (int i = 0; i < formatted.length; i++) { formatted[i] = nf(num[i], left, right); } return formatted; }
/** * ( begin auto-generated from nfp.xml ) * * Utility function for formatting numbers into strings. Similar to * <b>nf()</b> but puts a "+" in front of positive numbers and a "-" in * front of negative numbers. There are two versions, one for formatting * floats and one for formatting ints. The values for the <b>digits</b>, * <b>left</b>, and <b>right</b> parameters should always be positive integers. * * ( end auto-generated ) * @webref data:string_functions * @param num the number to format * @param digits number of digits to pad with zeroes * @see PApplet#nf(float, int, int) * @see PApplet#nfs(float, int, int) * @see PApplet#nfc(float, int) */ static public String nfp(int num, int digits) { return (num < 0) ? nf(num, digits) : ('+' + nf(num, digits)); } /**
/** * ( begin auto-generated from nfs.xml ) * * Utility function for formatting numbers into strings. Similar to * <b>nf()</b> but leaves a blank space in front of positive numbers so * they align with negative numbers in spite of the minus symbol. There are * two versions, one for formatting floats and one for formatting ints. The * values for the <b>digits</b>, <b>left</b>, and <b>right</b> parameters * should always be positive integers. * * ( end auto-generated ) * @webref data:string_functions * @param num the number to format * @param digits number of digits to pad with zeroes * @see PApplet#nf(float, int, int) * @see PApplet#nfp(float, int, int) * @see PApplet#nfc(float, int) */ static public String nfs(int num, int digits) { return (num < 0) ? nf(num, digits) : (' ' + nf(num, digits)); }
/** * ( begin auto-generated from nf.xml ) * * Utility function for formatting numbers into strings. There are two * versions, one for formatting floats and one for formatting ints. The * values for the <b>digits</b>, <b>left</b>, and <b>right</b> parameters * should always be positive integers.<br /><br />As shown in the above * example, <b>nf()</b> is used to add zeros to the left and/or right of a * number. This is typically for aligning a list of numbers. To * <em>remove</em> digits from a floating-point number, use the * <b>int()</b>, <b>ceil()</b>, <b>floor()</b>, or <b>round()</b> * functions. * * ( end auto-generated ) * @webref data:string_functions * @param nums the numbers to format * @param digits number of digits to pad with zero * @see PApplet#nfs(float, int, int) * @see PApplet#nfp(float, int, int) * @see PApplet#nfc(float, int) * @see <a href="https://processing.org/reference/intconvert_.html">int(float)</a> */ static public String[] nf(int nums[], int digits) { String formatted[] = new String[nums.length]; for (int i = 0; i < formatted.length; i++) { formatted[i] = nf(nums[i], digits); } return formatted; }
/** * Check a string for #### signs to see if the frame number should be * inserted. Used for functions like saveFrame() and beginRecord() to * replace the # marks with the frame number. If only one # is used, * it will be ignored, under the assumption that it's probably not * intended to be the frame number. */ public String insertFrame(String what) { int first = what.indexOf('#'); int last = what.lastIndexOf('#'); if ((first != -1) && (last - first > 0)) { String prefix = what.substring(0, first); int count = last - first + 1; String suffix = what.substring(last + 1); return prefix + nf(frameCount, count) + suffix; } return what; // no change }
/** * Check a string for #### signs to see if the frame number should be * inserted. Used for functions like saveFrame() and beginRecord() to * replace the # marks with the frame number. If only one # is used, * it will be ignored, under the assumption that it's probably not * intended to be the frame number. */ protected String insertFrame(String what) { int first = what.indexOf('#'); int last = what.lastIndexOf('#'); if ((first != -1) && (last - first > 0)) { String prefix = what.substring(0, first); int count = last - first + 1; String suffix = what.substring(last + 1); return prefix + nf(frameCount, count) + suffix; } return what; // no change }
/** */ public void saveFrame() { try { g.save(savePath("screen-" + nf(frameCount, 4) + ".tif")); } catch (SecurityException se) { System.err.println("Can't use saveFrame() when running in a browser, " + "unless using a signed applet."); } }
/** * Grab an image of what's currently in the drawing area and save it * as a .tif or .tga file. * <p/> * Best used just before endDraw() at the end of your draw(). * This can only create .tif or .tga images, so if neither extension * is specified it defaults to writing a tiff and adds a .tif suffix. */ public void saveFrame() { try { g.save(savePath("screen-" + nf(frameCount, 4) + ".tif")); } catch (SecurityException se) { System.err.println("Can't use saveFrame() when running in a browser, " + "unless using a signed applet."); } }