From 4d3fc9fdc365a7cfdc55179859d6d94d974253a3 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Fri, 5 Apr 2013 12:13:38 -0600 Subject: [PATCH 1/5] Adding header comment to set user expectation that max memory may need increased (otherwise the program tends to crash). References processing/processing_web#45 --- .../CubicGridRetained/CubicGridRetained.pde | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/java/examples/Demos/Performance/CubicGridRetained/CubicGridRetained.pde b/java/examples/Demos/Performance/CubicGridRetained/CubicGridRetained.pde index 1e833810b..70906fbde 100644 --- a/java/examples/Demos/Performance/CubicGridRetained/CubicGridRetained.pde +++ b/java/examples/Demos/Performance/CubicGridRetained/CubicGridRetained.pde @@ -1,3 +1,8 @@ +/* CubicGridRetained + * + * You may need to increase the maximum available memory in the + * Processing preferences menu. +*/ float boxSize = 20; float margin = boxSize*2; float depth = 400; @@ -14,16 +19,16 @@ void setup() { frameRate(60); noSmooth(); noStroke(); - + grid = createShape(GROUP); - - // Build grid using multiple translations + + // Build grid using multiple translations for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){ for (float j =- height+margin; j <= height-margin; j += boxSize){ for (float k =- width+margin; k <= width-margin; k += boxSize){ - // Base fill color on counter values, abs function + // Base fill color on counter values, abs function // ensures values stay within legal range - boxFill = color(abs(i), abs(j), abs(k), 50); + boxFill = color(abs(i), abs(j), abs(k), 50); PShape cube = createShape(BOX, boxSize, boxSize, boxSize); cube.setFill(boxFill); cube.translate(k, j, i); @@ -35,9 +40,9 @@ void setup() { void draw() { background(255); - + hint(DISABLE_DEPTH_TEST); - + // Center and spin grid pushMatrix(); translate(width/2, height/2, -depth); @@ -46,17 +51,17 @@ void draw() { shape(grid); popMatrix(); - + hint(ENABLE_DEPTH_TEST); - + fcount += 1; int m = millis(); if (m - lastm > 1000 * fint) { frate = float(fcount) / fint; fcount = 0; lastm = m; - println("fps: " + frate); - } + println("fps: " + frate); + } fill(0); text("fps: " + frate, 10, 20); } From e42b4dcb3c7419e0f239b0349dd9ddfd193cfaa2 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Fri, 5 Apr 2013 11:59:37 -0600 Subject: [PATCH 2/5] Improving header comment to set user expectation. Cleaning up setOffset() such that it has one job: setting the offset. References processing/processing_web#45 --- .../Topics/File IO/TileImages/TileImages.pde | 22 +++++++++---------- .../Topics/File IO/TileImages/TileImages.pde | 13 ++++++----- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/android/examples/Topics/File IO/TileImages/TileImages.pde b/android/examples/Topics/File IO/TileImages/TileImages.pde index 7b266570c..d577e275e 100644 --- a/android/examples/Topics/File IO/TileImages/TileImages.pde +++ b/android/examples/Topics/File IO/TileImages/TileImages.pde @@ -1,7 +1,7 @@ /** * Tile Images - * - * Draws an image larger than the screen by tiling it into small sections. + * + * Draws an image larger than the screen, and saves the image as six tiles. * The scaleValue variable sets amount of scaling: 1 is 100%, 2 is 200%, etc. */ @@ -9,31 +9,29 @@ int scaleValue = 3; // Multiplication factor int xoffset = 0; // x-axis offset int yoffset = 0; // y-axis offset -void setup() -{ +void setup() { size(600, 600); stroke(0, 100); } -void draw() -{ +void draw() { + background(204); scale(scaleValue); - translate(xoffset *(-width / scaleValue), yoffset *(-height / scaleValue)); + translate(xoffset * (-width / scaleValue), yoffset * (-height / scaleValue)); line(10, 150, 500, 50); line(0, 600, 600, 0); + save("lines-" + yoffset + "-" + xoffset + ".png"); setOffset(); } -void setOffset() -{ - save("lines-" + xoffset + "-" + yoffset + ".jpg"); +void setOffset() { xoffset++; if (xoffset == scaleValue) { xoffset = 0; yoffset++; if (yoffset == scaleValue) { + println("Tiles saved."); exit(); } } - background(204); -} +} \ No newline at end of file diff --git a/java/examples/Topics/File IO/TileImages/TileImages.pde b/java/examples/Topics/File IO/TileImages/TileImages.pde index 00af7c634..d577e275e 100644 --- a/java/examples/Topics/File IO/TileImages/TileImages.pde +++ b/java/examples/Topics/File IO/TileImages/TileImages.pde @@ -1,7 +1,7 @@ /** * Tile Images - * - * Draws an image larger than the screen by tiling it into small sections. + * + * Draws an image larger than the screen, and saves the image as six tiles. * The scaleValue variable sets amount of scaling: 1 is 100%, 2 is 200%, etc. */ @@ -15,22 +15,23 @@ void setup() { } void draw() { + background(204); scale(scaleValue); - translate(xoffset *(-width / scaleValue), yoffset *(-height / scaleValue)); + translate(xoffset * (-width / scaleValue), yoffset * (-height / scaleValue)); line(10, 150, 500, 50); line(0, 600, 600, 0); + save("lines-" + yoffset + "-" + xoffset + ".png"); setOffset(); } void setOffset() { - save("lines-" + xoffset + "-" + yoffset + ".png"); xoffset++; if (xoffset == scaleValue) { xoffset = 0; yoffset++; if (yoffset == scaleValue) { + println("Tiles saved."); exit(); } } - background(204); -} +} \ No newline at end of file From ab1b20a9e4ee6c55f8a66309173531aae34e88df Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Fri, 5 Apr 2013 12:33:15 -0600 Subject: [PATCH 3/5] Replacing deprecated CENTER_RADIUS constant with RADIUS. References processing/processing_web#45 --- .../Illustrations/page_278/page_278.pde | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/java/examples/Books/Processing Handbook/Illustrations/page_278/page_278.pde b/java/examples/Books/Processing Handbook/Illustrations/page_278/page_278.pde index 46869d576..fbe77b1b6 100755 --- a/java/examples/Books/Processing Handbook/Illustrations/page_278/page_278.pde +++ b/java/examples/Books/Processing Handbook/Illustrations/page_278/page_278.pde @@ -9,10 +9,10 @@ void setup() { //size(200, 200); smooth(); noStroke(); - ellipseMode(CENTER_RADIUS); + ellipseMode(RADIUS); randomSeed(0); for(int i=0; i Date: Fri, 5 Apr 2013 12:35:37 -0600 Subject: [PATCH 4/5] Adding pdf library imports so the examples work. References processing/processing_web#45 --- .../Illustrations/page_290/page_290.pde | 11 ++++++----- .../Illustrations/page_300/page_300.pde | 13 +++++++------ .../Illustrations/page_420/page_420.pde | 9 +++++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/java/examples/Books/Processing Handbook/Illustrations/page_290/page_290.pde b/java/examples/Books/Processing Handbook/Illustrations/page_290/page_290.pde index 6840533b2..1234f6316 100755 --- a/java/examples/Books/Processing Handbook/Illustrations/page_290/page_290.pde +++ b/java/examples/Books/Processing Handbook/Illustrations/page_290/page_290.pde @@ -1,6 +1,7 @@ // Based on code 32-07 (p. 297) +import processing.pdf.*; float inc = 0.0; @@ -12,11 +13,11 @@ void setup() { } void draw() { - + if(record) { beginRecord(PDF, "page_290.pdf"); } - + stroke(0, 143); randomSeed(0); background(255); @@ -33,12 +34,12 @@ void draw() { tail(i, 300, int(random(5, 12)), angle*random(1.0, 1.3)); tail(i, 400, int(random(5, 12)), -angle*random(1.0, 1.3)); } - + if(record) { endRecord(); - record = false; + record = false; } - + } void mousePressed() { diff --git a/java/examples/Books/Processing Handbook/Illustrations/page_300/page_300.pde b/java/examples/Books/Processing Handbook/Illustrations/page_300/page_300.pde index f24c0ecf0..f223d90e7 100755 --- a/java/examples/Books/Processing Handbook/Illustrations/page_300/page_300.pde +++ b/java/examples/Books/Processing Handbook/Illustrations/page_300/page_300.pde @@ -1,6 +1,7 @@ // Based on code 33-14 (p. 307) +import processing.pdf.*; float inc = 0.0; @@ -17,7 +18,7 @@ void setup() { size(180, 666); smooth(); noFill(); - strokeWeight(0.25); + strokeWeight(0.25); y = new float[height]; x = new float[height]; @@ -32,9 +33,9 @@ void draw() { background(255); // Shift the values to the right - for (int i = y.length-1; i > 0; i--) { + for (int i = y.length-1; i > 0; i--) { y[i] = y[i-1]; - } + } // Add new values to the beginning my += (mouseX-my) * 0.1; y[0] = my; @@ -46,9 +47,9 @@ void draw() { endShape(); // Shift the values to the right - for (int i = x.length-1; i > 0; i--) { + for (int i = x.length-1; i > 0; i--) { x[i] = x[i-1]; - } + } // Add new values to the beginning mx += (mouseY-mx) * 0.1; x[0] = mx; @@ -62,7 +63,7 @@ void draw() { if(record) { endRecord(); - record = false; + record = false; } } diff --git a/java/examples/Books/Processing Handbook/Illustrations/page_420/page_420.pde b/java/examples/Books/Processing Handbook/Illustrations/page_420/page_420.pde index 3010bc637..ecdc57fd3 100755 --- a/java/examples/Books/Processing Handbook/Illustrations/page_420/page_420.pde +++ b/java/examples/Books/Processing Handbook/Illustrations/page_420/page_420.pde @@ -1,9 +1,10 @@ // Based on code 45-04 (p. 424) +import processing.pdf.*; void setup() { - size(513, 666); + size(513, 666); } void draw() { @@ -11,17 +12,17 @@ void draw() { point(mouseX, mouseY); println("hi"); } -} +} void mousePressed() { - beginRecord(PDF, "page_420.pdf"); + beginRecord(PDF, "page_420.pdf"); background(255); stroke(0); strokeCap(ROUND); } void mouseReleased() { - endRecord(); + endRecord(); } From c233bb4a80eca4a0c1ea2bdaf395e0d084a14883 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Fri, 5 Apr 2013 13:05:06 -0600 Subject: [PATCH 5/5] Fixing incorrect characters in the example that looked like subtraction operators but weren't. References processing/processing_web#45 --- .../Processing Handbook/Extensions/Mobile/Ex_01/Ex_01.pde | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/examples/Books/Processing Handbook/Extensions/Mobile/Ex_01/Ex_01.pde b/java/examples/Books/Processing Handbook/Extensions/Mobile/Ex_01/Ex_01.pde index 2e1c732d9..160fa2647 100755 --- a/java/examples/Books/Processing Handbook/Extensions/Mobile/Ex_01/Ex_01.pde +++ b/java/examples/Books/Processing Handbook/Extensions/Mobile/Ex_01/Ex_01.pde @@ -5,6 +5,6 @@ PImage img = loadImage("sprite.png"); // The coordinates (0, 0) refer to the top-left corder of the screen image(img, 0, 0); // The following coordinate calculations will center the image in the screen -image(img, (width – img.width) / 2, (height – img.height) / 2); +image(img, (width - img.width) / 2, (height - img.height) / 2); // Finally, the next line will position the image in the bottom-right corner -image(img, width – img.width, height – img.height); \ No newline at end of file +image(img, width - img.width, height - img.height); \ No newline at end of file