diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index 78c520cf6..b01074ded 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -1116,12 +1116,12 @@ public class JSONObject { } - public JSONObject setJSONObject(String key, String value) { + public JSONObject setJSONObject(String key, JSONObject value) { return put(key, value); } - public JSONObject setJSONArray(String key, String value) { + public JSONObject setJSONArray(String key, JSONArray value) { return put(key, value); } diff --git a/core/src/processing/opengl/FontTexture.java b/core/src/processing/opengl/FontTexture.java index 1421bb4e3..c14367e15 100644 --- a/core/src/processing/opengl/FontTexture.java +++ b/core/src/processing/opengl/FontTexture.java @@ -77,6 +77,13 @@ class FontTexture implements PConstants { } + protected void dispose() { + for (int i = 0; i < textures.length; i++) { + textures[i].dispose(); + } + } + + protected void initTexture(PGraphicsOpenGL pg, PFont font, int w, int h) { maxTexWidth = w; maxTexHeight = h; diff --git a/core/src/processing/opengl/FrameBuffer.java b/core/src/processing/opengl/FrameBuffer.java index 2b899a12b..9c192386f 100644 --- a/core/src/processing/opengl/FrameBuffer.java +++ b/core/src/processing/opengl/FrameBuffer.java @@ -338,7 +338,7 @@ public class FrameBuffer implements PConstants { protected void allocate() { - release(); // Just in the case this object is being re-allocated. + dispose(); // Just in the case this object is being re-allocated. context = pgl.getCurrentContext(); @@ -367,7 +367,7 @@ public class FrameBuffer implements PConstants { } - protected void release() { + protected void dispose() { if (screenFb) return; if (glFbo != 0) { diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index dbc6bf611..e05de8eed 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -957,7 +957,7 @@ public class PGL { backTexAttach.minFilter, backTexAttach.magFilter, backTexAttach.wrapS, backTexAttach.wrapT); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.colorBuffer(true); pg.setCache(pg, tex); return tex; } else { @@ -967,7 +967,7 @@ public class PGL { fboWidth, fboHeight, NEAREST, NEAREST, CLAMP_TO_EDGE, CLAMP_TO_EDGE); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.colorBuffer(true); pg.setCache(pg, tex); return tex; } @@ -983,7 +983,7 @@ public class PGL { frontTexAttach.minFilter, frontTexAttach.magFilter, frontTexAttach.wrapS, frontTexAttach.wrapT); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.colorBuffer(true); return tex; } else { Texture tex = new Texture(); @@ -992,7 +992,7 @@ public class PGL { fboWidth, fboHeight, NEAREST, NEAREST, CLAMP_TO_EDGE, CLAMP_TO_EDGE); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.colorBuffer(true); return tex; } } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 5732f8803..18c8b12b0 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -651,10 +651,10 @@ public class PGraphicsOpenGL extends PGraphics { deleteDefaultShaders(); } else { if (offscreenFramebuffer != null) { - offscreenFramebuffer.release(); + offscreenFramebuffer.dispose(); } if (multisampleFramebuffer != null) { - multisampleFramebuffer.release(); + multisampleFramebuffer.dispose(); } } @@ -667,19 +667,20 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void finalize() throws Throwable { try { + PApplet.println("finalize surface"); + deletePolyBuffers(); deleteLineBuffers(); deletePointBuffers(); deleteSurfaceTextures(); if (!primarySurface) { - PApplet.println("finalize offscreen surface"); if (offscreenFramebuffer != null) { - offscreenFramebuffer.release(); + offscreenFramebuffer.dispose(); offscreenFramebuffer = null; } if (multisampleFramebuffer != null) { - multisampleFramebuffer.release(); + multisampleFramebuffer.dispose(); multisampleFramebuffer = null; } } @@ -796,7 +797,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glTextureObjects.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " texture objects, " + glTextureObjects.size() + " remaining"); + PApplet.println("Deleted " + finalized.size() + " texture objects, " + glTextureObjects.size() + " remaining"); } protected static void removeTextureObject(int id, int context) { @@ -861,7 +862,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glVertexBuffers.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " vertex buffer objects, " + glVertexBuffers.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " vertex buffer objects, " + glVertexBuffers.size() + " remaining"); } protected static void removeVertexBufferObject(int id, int context) { @@ -928,7 +929,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glFrameBuffers.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " framebuffer objects, " + glFrameBuffers.size() + " remaining"); + PApplet.println("Deleted " + finalized.size() + " framebuffer objects, " + glFrameBuffers.size() + " remaining"); } protected static void removeFrameBufferObject(int id, int context) { @@ -993,7 +994,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glRenderBuffers.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " renderbuffer objects, " + glRenderBuffers.size() + " remaining"); + PApplet.println("Deleted " + finalized.size() + " renderbuffer objects, " + glRenderBuffers.size() + " remaining"); } protected static void removeRenderBufferObject(int id, int context) { @@ -1054,7 +1055,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslPrograms.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL program objects, " + glslPrograms.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " GLSL program objects, " + glslPrograms.size() + " remaining"); } protected static void removeGLSLProgramObject(int id, int context) { @@ -1116,7 +1117,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslVertexShaders.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL vertex shader objects, " + glslVertexShaders.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " GLSL vertex shader objects, " + glslVertexShaders.size() + " remaining"); } protected static void removeGLSLVertShaderObject(int id, int context) { @@ -1178,7 +1179,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslFragmentShaders.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL fragment shader objects, " + glslFragmentShaders.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " GLSL fragment shader objects, " + glslFragmentShaders.size() + " remaining"); } protected static void removeGLSLFragShaderObject(int id, int context) { @@ -5301,13 +5302,13 @@ public class PGraphicsOpenGL extends PGraphics { sampling, mipmap); texture = new Texture(width, height, params); texture.invertedY(true); - texture.colorBufferOf(this); + texture.colorBuffer(true); pgPrimary.setCache(this, texture); if (!primarySurface) { ptexture = new Texture(width, height, params); ptexture.invertedY(true); - ptexture.colorBufferOf(this); + ptexture.colorBuffer(true); } } } @@ -5723,7 +5724,7 @@ public class PGraphicsOpenGL extends PGraphics { protected Texture addTexture(PImage img) { Texture.Parameters params = new Texture.Parameters(ARGB, textureSampling, - getHint(ENABLE_TEXTURE_MIPMAPS),textureWrap); + getHint(ENABLE_TEXTURE_MIPMAPS), textureWrap); return addTexture(img, params); } @@ -5736,14 +5737,14 @@ public class PGraphicsOpenGL extends PGraphics { if (img.parent == null) { img.parent = parent; } - Texture tex = new Texture(/*img.parent,*/ img.width, img.height, params); + Texture tex = new Texture(img.width, img.height, params); pgPrimary.setCache(img, tex); return tex; } protected void checkTexture(Texture tex) { - if (!tex.isColorBuffer() && + if (!tex.colorBuffer() && tex.usingMipmaps == hints[DISABLE_TEXTURE_MIPMAPS]) { if (hints[DISABLE_TEXTURE_MIPMAPS]) { tex.usingMipmaps(false, textureSampling); @@ -5790,15 +5791,15 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteSurfaceTextures() { if (texture != null) { - texture.release(); + texture.dispose(); } if (ptexture != null) { - ptexture.release(); + ptexture.dispose(); } if (filterTexture != null) { - filterTexture.release(); + filterTexture.dispose(); } } @@ -5889,10 +5890,10 @@ public class PGraphicsOpenGL extends PGraphics { // is changed), we make sure that all the OpenGL resources associated // to the surface are released by calling delete(). if (offscreenFramebuffer != null) { - offscreenFramebuffer.release(); + offscreenFramebuffer.dispose(); } if (multisampleFramebuffer != null) { - multisampleFramebuffer.release(); + multisampleFramebuffer.dispose(); } boolean packed = depthBits == 24 && stencilBits == 8 && diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index ff460079c..10306e53f 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -882,7 +882,7 @@ public class PShader { protected void loadUniforms() { } - protected void release() { + protected void dispose() { if (glVertex != 0) { PGraphicsOpenGL.deleteGLSLVertShaderObject(glVertex, context); glVertex = 0; diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index fe8f82de0..c792ff185 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -3436,7 +3436,7 @@ public class PShapeOpenGL extends PShape { // Deletion methods - protected void release() { + protected void dispose() { deletePolyBuffers(); deleteLineBuffers(); deletePointBuffers(); diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 227663660..6a26121ec 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -80,7 +80,8 @@ public class Texture implements PConstants { protected PGL pgl; // The interface between Processing and OpenGL. protected int context; // The context that created this texture. - protected PGraphicsOpenGL pgDraw; // The main renderer is the color buffer of. + protected boolean colorBuffer; // true if it is the color attachment of + // FrameBuffer object. protected boolean usingMipmaps; protected boolean usingRepeat; @@ -113,7 +114,7 @@ public class Texture implements PConstants { pgl = PGraphicsOpenGL.pgl; context = pgl.createEmptyContext(); - pgDraw = null; + colorBuffer = false; glName = 0; } @@ -141,7 +142,7 @@ public class Texture implements PConstants { pgl = PGraphicsOpenGL.pgl; context = pgl.createEmptyContext(); - pgDraw = null; + colorBuffer = false; glName = 0; @@ -152,6 +153,7 @@ public class Texture implements PConstants { @Override protected void finalize() throws Throwable { try { + PApplet.println("finalize texture"); if (glName != 0) { PGraphicsOpenGL.finalizeTextureObject(glName, context); } @@ -237,7 +239,7 @@ public class Texture implements PConstants { public void resize(int wide, int high) { // Marking the texture object as finalized so it is deleted // when creating the new texture. - release(); + dispose(); // Creating new texture with the appropriate size. Texture tex = new Texture(wide, high, getParameters()); @@ -1174,7 +1176,7 @@ public class Texture implements PConstants { * Allocates the opengl texture object. */ protected void allocate() { - release(); // Just in the case this object is being re-allocated. + dispose(); // Just in the case this object is being re-allocated. boolean enabledTex = false; if (!pgl.texturingIsEnabled(glTarget)) { @@ -1216,7 +1218,7 @@ public class Texture implements PConstants { /** * Marks the texture object for deletion. */ - protected void release() { + protected void dispose() { if (glName != 0) { PGraphicsOpenGL.finalizeTextureObject(glName, context); glName = 0; @@ -1240,13 +1242,13 @@ public class Texture implements PConstants { } - public void colorBufferOf(PGraphicsOpenGL pgDraw) { - this.pgDraw = pgDraw; + public void colorBuffer(boolean value) { + colorBuffer = value; } - protected boolean isColorBuffer() { - return pgDraw != null; + public boolean colorBuffer() { + return colorBuffer; } @@ -1330,7 +1332,7 @@ public class Texture implements PConstants { protected void copyObject(Texture src) { // The OpenGL texture of this object is replaced with the one from the // source object, so we delete the former to avoid resource wasting. - release(); + dispose(); width = src.width; height = src.height; diff --git a/java/examples/Basics/Image/BackgroundImage/BackgroundImage.pde b/java/examples/Basics/Image/BackgroundImage/BackgroundImage.pde index 7d2f6a6d6..9f872777d 100644 --- a/java/examples/Basics/Image/BackgroundImage/BackgroundImage.pde +++ b/java/examples/Basics/Image/BackgroundImage/BackgroundImage.pde @@ -16,7 +16,7 @@ void setup() { size(640, 360); // The background image must be the same size as the parameters // into the size() method. In this program, the size of the image - // is 650 x 360 pixels. + // is 640 x 360 pixels. bg = loadImage("moonwalk.jpg"); } diff --git a/java/examples/Topics/Advanced Data/LoadSaveJSON/LoadSaveJSON.pde b/java/examples/Topics/Advanced Data/LoadSaveJSON/LoadSaveJSON.pde index 9c8700608..83badb3c8 100644 --- a/java/examples/Topics/Advanced Data/LoadSaveJSON/LoadSaveJSON.pde +++ b/java/examples/Topics/Advanced Data/LoadSaveJSON/LoadSaveJSON.pde @@ -48,19 +48,14 @@ void draw() { b.rollover(mouseX, mouseY); } // - // textAlign(LEFT); - // fill(0); - // text("Click to add bubbles.", 10, height-10); + textAlign(LEFT); + fill(0); + text("Click to add bubbles.", 10, height-10); } - - -void loadData() { + void loadData() { // Load JSON file - String jsonString = join(loadStrings("data.json"), "\n"); - //println(jsonString); - - json = JSONObject.parse(jsonString); - println(json); + // Temporary full path until path problem resolved. + json = loadJSONObject("/Users/shiffman/Desktop/LoadSaveJSON/data/data.json"); JSONArray bubbleData = json.getJSONArray("bubbles"); @@ -68,53 +63,50 @@ void loadData() { bubbles = new Bubble[bubbleData.size()]; for (int i = 0; i < bubbleData.size(); i++) { - /*JSONObject bubble = bubbleData.getJSONObject(i); + // Get each object in the array + JSONObject bubble = bubbleData.getObject(i); + // Get a position object JSONObject position = bubble.getJSONObject("position"); + // Get x,y from position int x = position.getInt("x"); int y = position.getInt("y"); - - float diameter = (float)bubble.getDouble("diameter"); + + // Get diamter and label + float diameter = bubble.getFloat("diameter"); String label = bubble.getString("label"); - bubbles[i] = new Bubble(x, y, diameter, label);*/ + // Put object in array + bubbles[i] = new Bubble(x, y, diameter, label); } } -// Still need to work on adding and deleting + void mousePressed() { + // Create a new JSON bubble object + JSONObject newBubble = new JSONObject(); -void mousePressed() { + // Create a new JSON position object + JSONObject position = new JSONObject(); + position.setInt("x", mouseX); + position.setInt("y", mouseY); - // Create a new XML bubble element - // XML bubble = xml.addChild("bubble"); - // - // // Set the poisition element - // XML position = bubble.addChild("position"); - // // Here we can set attributes as integers directly - // position.setInt("x",mouseX); - // position.setInt("y",mouseY); - // - // // Set the diameter element - // XML diameter = bubble.addChild("diameter"); - // // Here for a node's content, we have to convert to a String - // diameter.setContent("" + random(40,80)); - // - // // Set a label - // XML label = bubble.addChild("label"); - // label.setContent("New label"); - // - // - // // Here we are removing the oldest bubble if there are more than 10 - // XML[] children = xml.getChildren("bubble"); - // // If the XML file has more than 10 bubble elements - // if (children.length > 10) { - // // Delete the first one - // xml.removeChild(children[0]); - // } - // - // // Save a new XML file - // saveXML(xml,"data/data.xml"); - // - // // reload the new data - // loadData(); + // Add position to bubble + newBubble.setJSONObject("position", position); + + // Add diamater and label to bubble + newBubble.setFloat("diameter", random(40, 80)); + newBubble.setString("label", "New label"); + + // Append the new JSON bubble object to the array + JSONArray bubbleData = json.getJSONArray("bubbles"); + bubbleData.append(newBubble); + + if (bubbleData.size() > 10) { + bubbleData.removeIndex(0); + } + + println(json); + // Not implemented yet + //saveJSONObject(json,"data.json"); + //loadData(); } diff --git a/java/examples/Topics/Drawing/ScribblePlotter/ScribblePlotter.pde b/java/examples/Topics/Drawing/ScribblePlotter/ScribblePlotter.pde deleted file mode 100644 index a18c0b11b..000000000 --- a/java/examples/Topics/Drawing/ScribblePlotter/ScribblePlotter.pde +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Scribble Plotter - * by Ira Greenberg. - * - * Using 2-dimensional arrays, record end points - * and replot scribbles between points. - */ - -int SCRIBBLE = 0; -int HATCHING = 1; - -void setup(){ - size(640, 360); - background(0); - - // Create arrays to hold x, y coords - float[]x = new float[4]; - float[]y = new float[4]; - // create a convenient 2-dimensional - // array to hold x, y arrays - float[][]xy = {x, y}; - - // Record points - // X positions - xy[0][0] = 125; - xy[0][1] = 475; - xy[0][2] = 475; - xy[0][3] = 125; - - // Y positions - xy[1][0] = 100; - xy[1][1] = 100; - xy[1][2] = 260; - xy[1][3] = 260; - - // Call plotting function - makeRect(xy); -} - -void makeRect(float[][]pts){ - stroke(255); - - // Scribble variables, that get passed as arguments to the scribble function - int steps = 100; - float scribVal = 3.0; - for (int i = 0; i < pts[0].length; i++){ - // Plots vertices - strokeWeight(5); - point(pts[0][i], pts[1][i]); - - // Call scribble function - strokeWeight(.5); - if (i > 0){ - scribble(pts[0][i], pts[1][i], pts[0][i-1], pts[1][i-1], steps, scribVal, SCRIBBLE); - } - if (i == pts[0].length-1){ - // Show some hatching between last 2 points - scribble(pts[0][i], pts[1][i], pts[0][0], pts[1][0], steps, scribVal*2, HATCHING); - } - } -} - -/* - Scribble function plots lines between end points, - determined by steps and scribVal arguments. - two styles are available: SCRIBBLE and HATCHING, which - are interestingly only dependent on parentheses - placement in the line() function calls. -*/ - -void scribble(float x1, float y1, float x2, float y2, int steps, float scribVal, int style){ - - float xStep = (x2-x1)/steps; - float yStep = (y2-y1)/steps; - for (int i = 0; i < steps; i++){ - if(style == SCRIBBLE){ - if (i < steps-1){ - line(x1, y1, x1+=xStep+random(-scribVal, scribVal), y1+=yStep+random(-scribVal, scribVal)); - } - else { - // extra line needed to attach line back to point- not necessary in HATCHING style - line(x1, y1, x2, y2); - } - } - else if (style == HATCHING){ - line(x1, y1, (x1+=xStep)+random(-scribVal, scribVal), (y1+=yStep)+random(-scribVal, scribVal)); - } - } -} - diff --git a/java/examples/Topics/Motion/Puff/Puff.pde b/java/examples/Topics/Motion/Puff/Puff.pde deleted file mode 100644 index 034ee6d21..000000000 --- a/java/examples/Topics/Motion/Puff/Puff.pde +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Puff - * by Ira Greenberg. - * - * Series of ellipses simulating a multi-segmented - * organism, utilizing a follow the leader algorithm. - * Collision detection occurs on the organism's head, - * controlling overall direction, and on the individual - * body segments, controlling body shape and jitter. - */ - - -// For puff head -float headX; -float headY; -float speedX = .7; -float speedY = .9; - -// For puff body -int cells = 1000; -float[] px= new float[cells]; -float[] py= new float[cells]; -float[] radiiX = new float[cells]; -float[] radiiY = new float[cells]; -float[] angle = new float[cells]; -float[] frequency = new float[cells]; -float[] cellRadius = new float[cells]; - -void setup(){ - - size(640, 360); - - // Begin in the center - headX = width/2; - headY = height/2; - - // Fill body arrays - for (int i = 0; i < cells; i++){ - radiiX[i] = random(-7, 7); - radiiY[i] = random(-4, 4); - frequency[i]= random(-9, 9); - cellRadius[i] = random(16, 30); - } - frameRate(30); -} - -void draw(){ - background(0); - noStroke(); - fill(255, 255, 255, 5); - - // Follow the leader - for (int i = 0; i < cells; i++){ - if (i == 0){ - px[i] = headX + sin(radians(angle[i]))*radiiX[i]; - py[i] = headY + cos(radians(angle[i]))*radiiY[i]; - } - else{ - px[i] = px[i-1] + cos(radians(angle[i]))*radiiX[i]; - py[i] = py[i-1] + sin(radians(angle[i]))*radiiY[i]; - - // Check collision of body - if ((px[i] >= width-cellRadius[i]/2) || (px[i] <= cellRadius[i]/2)){ - radiiX[i]*=-1; - cellRadius[i] = random(1, 40); - frequency[i]= random(-13, 13); - } - if ((py[i] >= height-cellRadius[i]/2) || (py[i] <= cellRadius[i]/2)){ - radiiY[i]*=-1; - cellRadius[i] = random(1, 40); - frequency[i]= random(-9, 9); - } - } - // Draw puff - ellipse(px[i], py[i], cellRadius[i], cellRadius[i]); - // Set speed of body - angle[i] += frequency[i]; - } - - // Set velocity of head - headX += speedX; - headY += speedY; - - // Check boundary collision of head - if ((headX >= width-cellRadius[0]/2) || (headX <=cellRadius[0]/2)){ - speedX*=-1; - } - if ((headY >= height-cellRadius[0]/2) || (headY <= cellRadius[0]/2)){ - speedY*=-1; - } -} - diff --git a/java/examples/Topics/Simulate/Flocking/Boid.pde b/java/examples/Topics/Simulate/Flocking/Boid.pde index 4d2a5677a..a7f425451 100644 --- a/java/examples/Topics/Simulate/Flocking/Boid.pde +++ b/java/examples/Topics/Simulate/Flocking/Boid.pde @@ -9,10 +9,17 @@ class Boid { float maxforce; // Maximum steering force float maxspeed; // Maximum speed - Boid(float x, float y) { - acceleration = new PVector(0,0); - velocity = PVector.random2D(); - location = new PVector(x,y); + Boid(float x, float y) { + acceleration = new PVector(0, 0); + + // This is a new PVector method not yet implemented in JS + // velocity = PVector.random2D(); + + // Leaving the code temporarily this way so that this example runs in JS + float angle = random(TWO_PI); + velocity = new PVector(cos(angle), sin(angle)); + + location = new PVector(x, y); r = 2.0; maxspeed = 2; maxforce = 0.03; @@ -59,22 +66,30 @@ class Boid { // A method that calculates and applies a steering force towards a target // STEER = DESIRED MINUS VELOCITY PVector seek(PVector target) { - PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target + PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target // Scale to maximum speed - desired.setMag(maxspeed); + desired.normalize(); + desired.mult(maxspeed); + + // Above two lines of code below could be condensed with new PVector setMag() method + // Not using this method until Processing.js catches up + // desired.setMag(maxspeed); + // Steering = Desired minus Velocity - PVector steer = PVector.sub(desired,velocity); + PVector steer = PVector.sub(desired, velocity); steer.limit(maxforce); // Limit to maximum steering force return steer; } void render() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading() + radians(90); - fill(200,100); + float theta = velocity.heading2D() + radians(90); + // heading2D() above is now heading() but leaving old syntax until Processing.js catches up + + fill(200, 100); stroke(255); pushMatrix(); - translate(location.x,location.y); + translate(location.x, location.y); rotate(theta); beginShape(TRIANGLES); vertex(0, -r*2); @@ -96,15 +111,15 @@ class Boid { // Method checks for nearby boids and steers away PVector separate (ArrayList boids) { float desiredseparation = 25.0f; - PVector steer = new PVector(0,0,0); + PVector steer = new PVector(0, 0, 0); int count = 0; // For every boid in the system, check if it's too close for (Boid other : boids) { - float d = PVector.dist(location,other.location); + float d = PVector.dist(location, other.location); // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) if ((d > 0) && (d < desiredseparation)) { // Calculate vector pointing away from neighbor - PVector diff = PVector.sub(location,other.location); + PVector diff = PVector.sub(location, other.location); diff.normalize(); diff.div(d); // Weight by distance steer.add(diff); @@ -118,8 +133,13 @@ class Boid { // As long as the vector is greater than 0 if (steer.mag() > 0) { + // First two lines of code below could be condensed with new PVector setMag() method + // Not using this method until Processing.js catches up + // steer.setMag(maxspeed); + // Implement Reynolds: Steering = Desired - Velocity - steer.setMag(maxspeed); + steer.normalize(); + steer.mult(maxspeed); steer.sub(velocity); steer.limit(maxforce); } @@ -130,10 +150,10 @@ class Boid { // For every nearby boid in the system, calculate the average velocity PVector align (ArrayList boids) { float neighbordist = 50; - PVector sum = new PVector(0,0); + PVector sum = new PVector(0, 0); int count = 0; for (Boid other : boids) { - float d = PVector.dist(location,other.location); + float d = PVector.dist(location, other.location); if ((d > 0) && (d < neighbordist)) { sum.add(other.velocity); count++; @@ -141,12 +161,19 @@ class Boid { } if (count > 0) { sum.div((float)count); - sum.setMag(maxspeed); - PVector steer = PVector.sub(sum,velocity); + // First two lines of code below could be condensed with new PVector setMag() method + // Not using this method until Processing.js catches up + // sum.setMag(maxspeed); + + // Implement Reynolds: Steering = Desired - Velocity + sum.normalize(); + sum.mult(maxspeed); + PVector steer = PVector.sub(sum, velocity); steer.limit(maxforce); return steer; - } else { - return new PVector(0,0); + } + else { + return new PVector(0, 0); } } @@ -154,10 +181,10 @@ class Boid { // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location PVector cohesion (ArrayList boids) { float neighbordist = 50; - PVector sum = new PVector(0,0); // Start with empty vector to accumulate all locations + PVector sum = new PVector(0, 0); // Start with empty vector to accumulate all locations int count = 0; for (Boid other : boids) { - float d = PVector.dist(location,other.location); + float d = PVector.dist(location, other.location); if ((d > 0) && (d < neighbordist)) { sum.add(other.location); // Add location count++; @@ -166,10 +193,10 @@ class Boid { if (count > 0) { sum.div(count); return seek(sum); // Steer towards the location - } else { - return new PVector(0,0); + } + else { + return new PVector(0, 0); } } } - diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index d79e828ec..78dbac406 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -792,7 +792,7 @@ public class PGL extends processing.opengl.PGL { fboWidth, fboHeight, NEAREST, NEAREST, CLAMP_TO_EDGE, CLAMP_TO_EDGE); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.colorBuffer(true); pg.setCache(pg, tex); return tex; } @@ -805,7 +805,7 @@ public class PGL extends processing.opengl.PGL { fboWidth, fboHeight, NEAREST, NEAREST, CLAMP_TO_EDGE, CLAMP_TO_EDGE); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.colorBuffer(true); return tex; } diff --git a/java/libraries/net/src/processing/net/Server.java b/java/libraries/net/src/processing/net/Server.java index 60fb5f160..12b73a71b 100644 --- a/java/libraries/net/src/processing/net/Server.java +++ b/java/libraries/net/src/processing/net/Server.java @@ -31,16 +31,16 @@ import java.lang.reflect.*; import java.net.*; /** - * ( begin auto-generated from Server.xml ) - * - * A server sends and receives data to and from its associated clients - * (other programs connected to it). When a server is started, it begins - * listening for connections on the port specified by the port - * parameter. Computers have many ports for transferring data and some are - * commonly used so be sure to not select one of these. For example, web - * servers usually use port 80 and POP mail uses port 110. - * - * ( end auto-generated ) + * ( begin auto-generated from Server.xml ) + * + * A server sends and receives data to and from its associated clients + * (other programs connected to it). When a server is started, it begins + * listening for connections on the port specified by the port + * parameter. Computers have many ports for transferring data and some are + * commonly used so be sure to not select one of these. For example, web + * servers usually use port 80 and POP mail uses port 110. + * + * ( end auto-generated ) * @webref net * @usage application * @brief The server class is used to create server objects which send and receives data to and from its associated clients (other programs connected to it). @@ -104,8 +104,7 @@ public class Server implements Runnable { * Disconnect a particular client. * * ( end auto-generated ) - * - * ( end auto-generated ) + * @brief Disconnect a particular client. * @webref server:server * @param client the client to disconnect */ @@ -169,8 +168,7 @@ public class Server implements Runnable { * Returns the next client in line with a new message. * * ( end auto-generated ) - * - * ( end auto-generated ) + * @brief Returns the next client in line with a new message. * @webref server * @usage application */ @@ -198,12 +196,11 @@ public class Server implements Runnable { * Disconnects all clients and stops the server. * * ( end auto-generated ) - * *

Advanced

- *

* Use this to shut down the server if you finish using it while your applet * is still running. Otherwise, it will be automatically be shut down by the * host PApplet using dispose(), which is identical. + * @brief Disconnects all clients and stops the server. * @webref server * @usage application */ @@ -273,7 +270,6 @@ public class Server implements Runnable { * Server object. * * ( end auto-generated ) - * * @webref server * @brief Writes data to all connected clients * @param data data to write