Category: Lessons
-
Exercise 36
Now let’s apply the same approach to a circle: size(500, 300); background(255); strokeWeight(5); smooth(); float radius = 100; int centX = 250; int centY = 150; stroke(0, 30); noFill(); ellipse(centX, centY, radius*2, radius*2); stroke(20, 50, 70); float x, y; float lastx = -999; float lasty = -999; for (float ang = 0; ang
-
Exercise 35
Now let’s add noise instead of randomizing. the new point will have some reference to the point before it. size(500, 100); background(255); strokeWeight(5); smooth(); stroke(0, 30); line(20, 50, 480, 50); stroke(20, 50, 70); int step = 10; float lastx = -999; float lasty = -999; float ynoise = random(10); float y; for (int x=20; x…
-
Exercise 34
size(500,100); background(255); strokeWeight(5); smooth(); int step = 10; float lastX = -999; float lastY = -999; float y = 50; int borderX = 20; int borderY = 20; for( int x = borderX; x -999) { line(x, y, lastX, lastY); } lastX = x; lastY = y; }
-
Exercise 33
Now let’s animate the circles to move independently. int _num = 10; Circle[] _circleArr = { }; void setup() { size(800, 800); background(255); smooth(); strokeWeight(1); fill(150, 50); drawCircles(); } void draw() { background(255); for (int i=0; i (height+radius)) { y = 0 – radius; } if (y < (0-radius)) { y = height+radius; } drawMe();…
-
Exercise 32
Instead of just telling Processing to draw a circle, let’s instead create a circle object. The circle object will encapsulate everything there is to know about itself, which at the moment isn’t much more than the x,y of its center point, and its radius. class Circle { float x, y; float radius; color linecol, fillcol;…
-
Exercise 31
Let’s start simple. The following listing creates a script that draws a handful of randomly placed circles every time the mouse is clicked. int _num = 10; void setup() { size(500, 300); background(255); smooth(); strokeWeight(1); fill(150, 50); drawCircles(); } void draw() { } void mouseReleased() { drawCircles(); } void drawCircles() { for (int i=0; i
-
Exercise 30
Let’s replace our while loop with a For Loop to see how it works int ellipseSize = 40; void setup() { size(800, 800); smooth(); } void draw() { noFill(); strokeWeight(.5); stroke(255); for (int i=0; i
-
Exercise 29
now let’s improve our grid sketch by overlapping the circles and giving them a random transparency size(400, 400); noStroke(); background(255); float x = 0; while (x < width) { float y = 0; while (y < height) { if (random(100) > 98) { fill(255, 0, 0, random(50)); } else { // but usually pick a…
-
Exercise 28
Now let’s change our rectangle to a circle and adjust the spacing size(400, 400); noStroke(); background(255); float x = 0; while (x < width) { float y = 0; while (y < height) { if (random(100) > 98) { fill(255, 0, 0); } else { // but usually pick a random gray color fill(random(100, 200));…
-
Exercise 27
Adding a small probability of a red square to our grid size(400, 400); noStroke(); background(255); float x = 0; while (x < width) { float y = 0; while (y < height) { if (random(100) > 98) { fill(255, 0, 0); } else { // but usually pick a random gray color fill(random(100, 200)); }…