I tried the createReader() reference example, with no file positions.txt
I thought the try/catch would work, but I get a runtime error: Null Pointer Exception
Can this be fixed?
Maybe the error should be catched earlier at the
reader = createReader("positions.txt");
instruction instead? But how to do that?
positions.txt does not exist or could not be read
processing.app.debug.RunnerException: NullPointerException
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.NullPointerException
at sketch_mar10c.draw(sketch_mar10c.java:30)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
BufferedReader reader; String line;
void setup() { // Open the file from the createWriter() example reader = createReader("positions.txt"); }
void draw() { try { line = reader.readLine(); // <<<<<<<<<<< ERROR } catch (IOException e) { e.printStackTrace(); line = null; } if (line == null) { // Stop reading because of an error or file is empty noLoop(); } else { String[] pieces = split(line, TAB); int x = int(pieces[0]); int y = int(pieces[1]); point(x, y); } }
Exception in thread "output reader" java.lang.OutOfMemoryError: Java heap space
at java.lang.String.toCharArray(String.java:2725)
at processing.app.BufferedStyledDocument.appendString(EditorConsole.java:418)
at processing.app.EditorConsole.appendText(EditorConsole.java:269)
at processing.app.EditorConsole.message(EditorConsole.java:251)
at processing.app.EditorConsole.write(EditorConsole.java:227)
at
void showRec(int x, int y, int sizx, int sizy, float rot, int weight) { stroke(color(25,125,225,150)); fill(color(225,125,25,255)); strokeWeight(weight); rectMode(CENTER); pushMatrix(); translate(x,y); rotate(rot); rect(0,0,sizx,sizy); popMatrix(); rectMode(CORNER); }
It's not really a problem, but maybe someone has a better way.
I have a class taking in an array.
To be versatile, I want the array to possibly be int[] or long[] or float[].
So I made it with 3 similar constructors, with input of type int[] or long[] or float[].
Now I can not assign this incoming array to a single variable a, since it could be of 3 types.
So I assign it to a_int or a_long or a_float.
Fine.
But then each and every other method to deal with this array has to be tripled, with a dispatching method to call the right one. So I start to feel it would be simpler to just have 3 different methods from the start.
Any comment?
class graphA { int arraytype; // (0,1,2 = int,long,float) int[] a_int; long[] a_long; float[] a_float;
graphA(int[] a) { arraytype=0; a_int=a; } graphA(long[] a) { arraytype=1; a_long=a; } graphA(float[] a) { arraytype=2; a_float=a; }
void showA() { switch(arraytype) { case 0: showA(a_int); break; case 1: showA(a_long); break; case 2: showA(a_float); break; } } void showA(int[] a) { } void showA(long[] a) { } void showA(float[] a) { } }
static int[][] rotateCW(int[][] mat) { final int mlen1 = mat.length; final int mlen2 = mat[0].length; int[][] ret = new int[mlen2][mlen1]; for (int r = 0; r < mlen1; r++) { for (int c = 0; c < mlen2; c++) { ret[c][mlen1-1-r] = mat[r][c]; } } return ret; }
void draw() { // Run the walker object w.walk(); w.render(); }
class Walker { int x,y;
Walker() { x = width/2; y = height/2; }
void render() { stroke(255,100); point(x,y); }
// Randomly move up, down, left, right, or stay in one place void walk() { int vx = int(random(5))-1; int vy = int(random(5))-1; x += vx; y += vy; x = constrain(x,0,width-1); y = constrain(y,0,height-1); } }
How come the "Copy code" in the Forum posts always gives blank lines between each 2 lines?
line1
line2
line3
becomes
line1
line2
line3
It's a bit annoying for a long code, specially my monitor has height=768, much less if you substract the banners and the menu bars and the taskbar and the scrollbar and...
I have a problem finding the closest neighbors of a point.
The function getLinked( int index ) takes an index and returns those indexes which are linked to it in the Delaunay diagram. From there I can easily find which of those neighbors is the closest.
The problem I have is that sometimes the point itself is listed among it's neighbors.
In that case, a point linked to 2 others will have getLinked() return an array of length 3, which gives a minimum distance of 0, since the point itself is among it's neighbors.
What it does is: "Saves one PDF document of many frames drawn to the screen. Starts the file when the mouse is pressed and end the file when the mouse is released."
When I run it, it save the final image (when the mouse is released) as a 1-page pdf containing one image.