diff --git a/java/examples/Basics/Arrays/Array/Array.pde b/java/examples/Basics/Arrays/Array/Array.pde index a981fa470..dd84f41e8 100644 --- a/java/examples/Basics/Arrays/Array/Array.pde +++ b/java/examples/Basics/Arrays/Array/Array.pde @@ -10,26 +10,35 @@ * separate ways on the screen. */ -size(200, 200); -float[] coswave = new float[width]; +float[] coswave; -for (int i = 0; i < width; i++) { - float amount = map(i, 0, width, 0, PI); - coswave[i] = abs(cos(amount)); +void setup() { + size(640, 360); + coswave = new float[width]; + for (int i = 0; i < width; i++) { + float amount = map(i, 0, width, 0, PI); + coswave[i] = abs(cos(amount)); + } + noLoop(); } -for (int i = 0; i < width; i++) { - stroke(coswave[i]*255); - line(i, 0, i, height/3); +void draw() { + + for (int i = 0; i < width; i++) { + stroke(coswave[i]*255); + line(i, 0, i, height/3); + } + + for (int i = 0; i < width; i++) { + stroke(coswave[i]*255 / 4); + line(i, height/3, i, height/3*2); + } + + for (int i = 0; i < width; i++) { + stroke(255 - coswave[i]*255); + line(i, height/3*2, i, height); + } + } -for (int i = 0; i < width; i++) { - stroke(coswave[i]*255 / 4); - line(i, height/3, i, height/3*2); -} - -for (int i = 0; i < width; i++) { - stroke(255 - coswave[i]*255); - line(i, height/3*2, i, height); -} diff --git a/java/examples/Basics/Arrays/Array2D/Array2D.pde b/java/examples/Basics/Arrays/Array2D/Array2D.pde index 3a97587e7..6739bfdaa 100644 --- a/java/examples/Basics/Arrays/Array2D/Array2D.pde +++ b/java/examples/Basics/Arrays/Array2D/Array2D.pde @@ -6,27 +6,32 @@ * 2D arrays are useful for storing images. In this example, each dot * is colored in relation to its distance from the center of the image. */ - + float[][] distances; float maxDistance; +int spacer = 10; -size(200, 200); -background(0); -maxDistance = dist(width/2, height/2, width, height); -distances = new float[width][height]; -for(int i=0; i= big || x <= 0) { - xdir *= -1; - x = x + (1 * xdir); - y = y + (1 * ydir); + x = x + (speed * xDirection); + if (x >= unit || x <= 0) { + xDirection *= -1; + x = x + (1 * xDirection); + y = y + (1 * yDirection); } - if (y >= big || y <= 0) { - ydir *= -1; - y = y + (1 * ydir); + if (y >= unit || y <= 0) { + yDirection *= -1; + y = y + (1 * yDirection); } } // Custom method for drawing the object void draw() { - stroke(second() * 4); - point(mx+x-1, my+y-1); + fill(255); + ellipse(xOffset + x, yOffset + y, 6, 6); } } diff --git a/java/examples/Basics/Color/Hue/Hue.pde b/java/examples/Basics/Color/Hue/Hue.pde index b22ffb535..d2d0c28ed 100644 --- a/java/examples/Basics/Color/Hue/Hue.pde +++ b/java/examples/Basics/Color/Hue/Hue.pde @@ -6,26 +6,25 @@ * Move the cursor vertically over each bar to alter its hue. */ -int barWidth = 5; -int[] hue; +int barWidth = 20; +int lastBar = -1; void setup() { - size(200, 200); - colorMode(HSB, 360, height, height); - hue = new int[width/barWidth]; + size(640, 360); + colorMode(HSB, height, height, height); noStroke(); + background(0); } void draw() { - int j = 0; - for (int i=0; i<=(width-barWidth); i+=barWidth) { - if ((mouseX > i) && (mouseX < i+barWidth)) { - hue[j] = mouseY; - } - fill(hue[j], height/1.2, height/1.2); - rect(i, 0, barWidth, height); - j++; + int whichBar = mouseX / barWidth; + if (whichBar != lastBar) { + int barX = whichBar * barWidth; + fill(mouseY, height, height); + rect(barX, 0, barWidth, height); + lastBar = whichBar; } } + diff --git a/java/examples/Basics/Color/Saturation/Saturation.pde b/java/examples/Basics/Color/Saturation/Saturation.pde index 84137147e..c7a0c3c73 100644 --- a/java/examples/Basics/Color/Saturation/Saturation.pde +++ b/java/examples/Basics/Color/Saturation/Saturation.pde @@ -7,12 +7,12 @@ * Move the cursor vertically over each bar to alter its saturation. */ -int barWidth = 5; +int barWidth = 20; int lastBar = -1; void setup() { - size(200, 200); + size(640, 360); colorMode(HSB, width, height, 100); noStroke(); } diff --git a/java/examples/Basics/Control/Conditionals1/Conditionals1.pde b/java/examples/Basics/Control/Conditionals1/Conditionals1.pde index 8ea0ee3f5..7789f1f95 100644 --- a/java/examples/Basics/Control/Conditionals1/Conditionals1.pde +++ b/java/examples/Basics/Control/Conditionals1/Conditionals1.pde @@ -10,15 +10,15 @@ * equal to zero then draw a line. */ -size(200, 200); +size(640, 360); background(0); -for(int i=10; i 0){ - for(int j = margin; j < width-margin; j+= box_space){ - fill(255-box_size*10); - rect(j, i, box_size, box_size); - } - box_size = box_size - 0.6; + +int gridSize = 40; + +for (int x = gridSize; x <= width - gridSize; x += gridSize) { + for (int y = gridSize; y <= height - gridSize; y += gridSize) { + noStroke(); + fill(255); + rect(x-1, y-1, 3, 3); + stroke(255, 50); + line(x, y, width/2, height/2); } } - diff --git a/java/examples/Basics/Control/Iteration/Iteration.pde b/java/examples/Basics/Control/Iteration/Iteration.pde index 722806122..635f473e3 100644 --- a/java/examples/Basics/Control/Iteration/Iteration.pde +++ b/java/examples/Basics/Control/Iteration/Iteration.pde @@ -1,45 +1,41 @@ /** * Iteration. * - * Iteration with a "for" structure constructs repetitive forms. + * Iteration with a "for" structure to construct repetitive forms. */ -int k; -int xpos1 = 100; -int xpos2 = 118; -int count = 0; -int timey = 0; -int num = 12; +int y; +int num = 14; -size(200, 200); +size(640, 360); background(102); noStroke(); // Draw gray bars fill(255); -k=60; -for(int i=0; i < num/3; i++) { - rect(25, k, 155, 5); - k+=10; +y = 60; +for(int i = 0; i < num/3; i++) { + rect(50, y, 475, 10); + y+=20; } -// Black bars +// Gray bars fill(51); -k = 40; -for(int i=0; i < num; i++) { - rect(105, k, 30, 5); - k += 10; -} -k = 15; +y = 40; for(int i = 0; i < num; i++) { - rect(125, k, 30, 5); - k +=10; + rect(405, y, 30, 10); + y += 20; +} +y = 50; +for(int i = 0; i < num; i++) { + rect(425, y, 30, 10); + y += 20; } // Thin lines -k = 42; +y = 45; fill(0); -for(int i=0; i < num-1; i++) { - rect(36, k, 20, 1); - k+=10; +for(int i = 0; i < num-1; i++) { + rect(120, y, 40, 1); + y+= 20; } diff --git a/java/examples/Basics/Control/LogicalOperators/LogicalOperators.pde b/java/examples/Basics/Control/LogicalOperators/LogicalOperators.pde index d9329c004..eb6ed3df5 100644 --- a/java/examples/Basics/Control/LogicalOperators/LogicalOperators.pde +++ b/java/examples/Basics/Control/LogicalOperators/LogicalOperators.pde @@ -1,41 +1,41 @@ /** - * Logical Operators. + * Logical testerators. * * The logical operators for AND (&&) and OR (||) are used to * combine simple relational statements into more complex expressions. * The NOT (!) operator is used to negate a boolean statement. */ -size(200, 200); +size(640, 360); background(126); -boolean op = false; +boolean test = false; -for(int i=5; i<=195; i+=5) { +for(int i = 5; i <= height; i += 5) { // Logical AND stroke(0); if((i > 35) && (i < 100)) { - line(5, i, 95, i); - op = false; + line(width/4, i, width/2, i); + test = false; } // Logical OR stroke(76); if((i <= 35) || (i >= 100)) { - line(105, i, 195, i); - op = true; + line(width/2, i, width, i); + test = true; } // Testing if a boolean value is "true" - // The expression "if(op)" is equivalent to "if(op == true)" - if(op) { + // The expression "if(test)" is equivalent to "if(test == true)" + if(test) { stroke(0); - point(width/2, i); + point(width/3, i); } // Testing if a boolean value is "false" - // The expression "if(!op)" is equivalent to "if(op == false)" - if(!op) { + // The expression "if(!test)" is equivalent to "if(test == false)" + if(!test) { stroke(255); point(width/4, i); } diff --git a/java/examples/Basics/Form/Bezier/Bezier.pde b/java/examples/Basics/Form/Bezier/Bezier.pde index e0b53db21..13235b7d7 100644 --- a/java/examples/Basics/Form/Bezier/Bezier.pde +++ b/java/examples/Basics/Form/Bezier/Bezier.pde @@ -7,12 +7,12 @@ * that define the shape of the curve. */ -size(200, 200); +size(640, 360); background(0); stroke(255); noFill(); smooth(); -for(int i = 0; i < 100; i += 20) { - bezier(90-(i/2.0), 20+i, 210, 10, 220, 150, 120-(i/8.0), 150+(i/4.0)); +for(int i = 0; i < 200; i += 20) { + bezier(180-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0)); } diff --git a/java/examples/Basics/Form/BezierEllipse/BezierEllipse.pde b/java/examples/Basics/Form/BezierEllipse/BezierEllipse.pde index 7db555f8c..b739f60bc 100644 --- a/java/examples/Basics/Form/BezierEllipse/BezierEllipse.pde +++ b/java/examples/Basics/Form/BezierEllipse/BezierEllipse.pde @@ -18,7 +18,7 @@ color controlPtCol = #222222; color anchorPtCol = #BBBBBB; void setup(){ - size(200, 200); + size(640, 360); smooth(); setEllipse(pts, 65, 65); frameRate(1); @@ -30,12 +30,12 @@ void draw(){ setEllipse(int(random(3, 12)), random(-100, 150), random(-100, 150)); } -// draw ellipse with anchor/control points +// Draw ellipse with anchor/control points void drawEllipse(){ strokeWeight(1.125); stroke(255); noFill(); - // create ellipse + // Create ellipse for (int i=0; i0){ @@ -62,18 +62,18 @@ void drawEllipse(){ for ( int i=0; i< pts; i++){ fill(controlPtCol); noStroke(); - //control handles + // Control handles ellipse(cx[i], cy[i], 4, 4); ellipse(cx2[i], cy2[i], 4, 4); fill(anchorPtCol); stroke(0); - //anchor points + // Anchor points rect(px[i], py[i], 5, 5); } } -// fill up arrays with ellipse coordinate data +// Fill arrays with ellipse coordinate data void setEllipse(int points, float radius, float controlRadius){ pts = points; px = new float[points]; @@ -97,7 +97,7 @@ void setEllipse(int points, float radius, float controlRadius){ cy2[i] = height/2+sin(radians(angle+controlAngle2))* controlRadius/cos(radians(controlAngle1)); - //increment angle so trig functions keep chugging along + // Increment angle so trig functions keep chugging along angle+=360.0/points; } } diff --git a/java/examples/Basics/Form/PieChart/PieChart.pde b/java/examples/Basics/Form/PieChart/PieChart.pde index b1a3622d6..1e16cbc78 100644 --- a/java/examples/Basics/Form/PieChart/PieChart.pde +++ b/java/examples/Basics/Form/PieChart/PieChart.pde @@ -5,19 +5,27 @@ * Uses the arc() function to generate a pie chart from the data * stored in an array. */ - -size(200, 200); -background(100); -smooth(); -noStroke(); -float diameter = min(width, height) * 0.75; -int[] angs = {30, 10, 45, 35, 60, 38, 75, 67}; -float lastAng = 0; -for (int i = 0; i < angs.length; i++){ - fill(angs[i] * 3.0); - arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(angs[i])); - lastAng += radians(angs[i]); +float diameter; +int[] angles = { 30, 10, 45, 35, 60, 38, 75, 67 }; +float lastAngle = 0; + +void setup() { + size(640, 360); + background(100); + smooth(); + noStroke(); + diameter = min(width, height) * 0.75; + noLoop(); // Run once and stop +} + + +void draw() { + for (int i = 0; i < angles.length; i++) { + fill(angles[i] * 3.0); + arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i])); + lastAngle += radians(angles[i]); + } } diff --git a/java/examples/Basics/Form/PointsLines/PointsLines.pde b/java/examples/Basics/Form/PointsLines/PointsLines.pde index 6c504f165..ce36e725d 100644 --- a/java/examples/Basics/Form/PointsLines/PointsLines.pde +++ b/java/examples/Basics/Form/PointsLines/PointsLines.pde @@ -6,14 +6,15 @@ * The four variables set the positions based on the value of 'd'. */ -int d = 40; +int d = 70; int p1 = d; int p2 = p1+d; int p3 = p2+d; int p4 = p3+d; -size(200, 200); +size(640, 360); background(0); +translate(140, 0); // Draw gray box stroke(153); diff --git a/java/examples/Basics/Form/ShapePrimitives/ShapePrimitives.pde b/java/examples/Basics/Form/ShapePrimitives/ShapePrimitives.pde index 4c0158f5d..198f56763 100644 --- a/java/examples/Basics/Form/ShapePrimitives/ShapePrimitives.pde +++ b/java/examples/Basics/Form/ShapePrimitives/ShapePrimitives.pde @@ -8,14 +8,18 @@ * of parameters to determine the shape's position and size. */ -size(200, 200); +size(640, 360); smooth(); background(0); noStroke(); -fill(226); -triangle(10, 10, 10, 200, 45, 200); -rect(45, 45, 35, 35); -quad(105, 10, 120, 10, 120, 200, 80, 200); -ellipse(140, 80, 40, 40); -triangle(160, 10, 195, 200, 160, 200); +fill(204); +triangle(18, 18, 18, 360, 81, 360); +fill(153); +rect(81, 81, 63, 63); +fill(204); +quad(189, 18, 216, 18, 216, 360, 144, 360); +fill(255); +ellipse(252, 144, 72, 72); +fill(204); +triangle(288, 18, 351, 360, 288, 360); diff --git a/java/examples/Basics/Form/SimpleCurves/SimpleCurves.pde b/java/examples/Basics/Form/SimpleCurves/SimpleCurves.pde index 8507d6dc1..3e281eda1 100644 --- a/java/examples/Basics/Form/SimpleCurves/SimpleCurves.pde +++ b/java/examples/Basics/Form/SimpleCurves/SimpleCurves.pde @@ -8,45 +8,46 @@ */ void setup() { - size(200, 200); + size(640, 360); colorMode(RGB, 100); + smooth(); background(0); noFill(); - noLoop(); + noLoop(); // Run once and stop } void draw() { stroke(40); beginShape(); - for(int i=0; i= 'A' && key <= 'z') { int keyIndex; if(key <= 'Z') { keyIndex = key-'A'; - letter_height = max_height; + letterHeight = maxHeight; fill(colors[key-'A']); } else { keyIndex = key-'a'; - letter_height = min_height; + letterHeight = minHeight; fill(colors[key-'a']); } } else { fill(0); - letter_height = 10; + letterHeight = 10; } newletter = true; // Update the "letter" position - x = ( x + letter_width ); + x = ( x + letterWidth ); // Wrap horizontally - if (x > width - letter_width) { + if (x > width - letterWidth) { x = 0; - y+= max_height; + y+= maxHeight; } // Wrap vertically - if( y > height - letter_height) { + if( y > height - letterHeight) { y = 0; // reset y to 0 } } diff --git a/java/examples/Basics/Input/Milliseconds/Milliseconds.pde b/java/examples/Basics/Input/Milliseconds/Milliseconds.pde index 2439ba363..5af9a69b9 100644 --- a/java/examples/Basics/Input/Milliseconds/Milliseconds.pde +++ b/java/examples/Basics/Input/Milliseconds/Milliseconds.pde @@ -11,16 +11,16 @@ float scale; void setup() { - size(200, 200); + size(640, 360); noStroke(); - scale = width/10; + scale = width/20; } void draw() { - for(int i=0; i 90) { - gx = 90; - } - - if (gy > 90) { - gy = 90; - } else if (gy < 10) { - gy = 10; - } -} diff --git a/java/examples/Basics/Input/Mouse2D/Mouse2D.pde b/java/examples/Basics/Input/Mouse2D/Mouse2D.pde index c316bc6ce..d4a05e2ff 100644 --- a/java/examples/Basics/Input/Mouse2D/Mouse2D.pde +++ b/java/examples/Basics/Input/Mouse2D/Mouse2D.pde @@ -6,7 +6,7 @@ void setup() { - size(200, 200); + size(640, 360); noStroke(); rectMode(CENTER); } diff --git a/java/examples/Basics/Input/MouseFunctions/MouseFunctions.pde b/java/examples/Basics/Input/MouseFunctions/MouseFunctions.pde index 8d4e0fe36..c7efdc226 100644 --- a/java/examples/Basics/Input/MouseFunctions/MouseFunctions.pde +++ b/java/examples/Basics/Input/MouseFunctions/MouseFunctions.pde @@ -6,7 +6,7 @@ float bx; float by; -int bs = 20; +int bs = 75; boolean bover = false; boolean locked = false; float bdifx = 0.0; @@ -15,7 +15,7 @@ float bdify = 0.0; void setup() { - size(200, 200); + size(640, 360); bx = width/2.0; by = height/2.0; rectMode(RADIUS); diff --git a/java/examples/Basics/Input/MousePress/MousePress.pde b/java/examples/Basics/Input/MousePress/MousePress.pde index 526eced76..d0657831b 100644 --- a/java/examples/Basics/Input/MousePress/MousePress.pde +++ b/java/examples/Basics/Input/MousePress/MousePress.pde @@ -1,5 +1,5 @@ /** - * Click. + * Mouse Press. * * Move the mouse to position the shape. * Press the mouse button to invert the color. @@ -7,7 +7,7 @@ void setup() { - size(200, 200); + size(640, 360); fill(126); background(102); } diff --git a/java/examples/Basics/Input/MouseSignals/MouseSignals.pde b/java/examples/Basics/Input/MouseSignals/MouseSignals.pde index 6e1fd2bbc..607cf87be 100644 --- a/java/examples/Basics/Input/MouseSignals/MouseSignals.pde +++ b/java/examples/Basics/Input/MouseSignals/MouseSignals.pde @@ -13,7 +13,7 @@ int[] bvals; void setup() { - size(200, 200); + size(640, 360); xvals = new int[width]; yvals = new int[width]; bvals = new int[width]; @@ -25,7 +25,7 @@ void draw() { background(102); - for(int i=1; i