| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,26 +10,35 @@ | |||
| 10 | 10 | * separate ways on the screen. | |
| 11 | 11 | */ | |
| 12 | 12 | ||
| 13 | - size(200, 200); | ||
| 14 | 13 | ||
| 15 | - float[] coswave = new float[width]; | ||
| 14 | + float[] coswave; | ||
| 16 | 15 | ||
| 17 | - for (int i = 0; i < width; i++) { | ||
| 18 | - float amount = map(i, 0, width, 0, PI); | ||
| 19 | - coswave[i] = abs(cos(amount)); | ||
| 16 | + void setup() { | ||
| 17 | + size(640, 360); | ||
| 18 | + coswave = new float[width]; | ||
| 19 | + for (int i = 0; i < width; i++) { | ||
| 20 | + float amount = map(i, 0, width, 0, PI); | ||
| 21 | + coswave[i] = abs(cos(amount)); | ||
| 22 | + } | ||
| 23 | + noLoop(); | ||
| 20 | 24 | } | |
| 21 | 25 | ||
| 22 | - for (int i = 0; i < width; i++) { | ||
| 23 | - stroke(coswave[i]*255); | ||
| 24 | - line(i, 0, i, height/3); | ||
| 25 | - } | ||
| 26 | + void draw() { | ||
| 26 | 27 | ||
| 27 | - for (int i = 0; i < width; i++) { | ||
| 28 | - stroke(coswave[i]*255 / 4); | ||
| 29 | - line(i, height/3, i, height/3*2); | ||
| 30 | - } | ||
| 28 | + for (int i = 0; i < width; i++) { | ||
| 29 | + stroke(coswave[i]*255); | ||
| 30 | + line(i, 0, i, height/3); | ||
| 31 | + } | ||
| 31 | 32 | ||
| 32 | - for (int i = 0; i < width; i++) { | ||
| 33 | - stroke(255 - coswave[i]*255); | ||
| 34 | - line(i, height/3*2, i, height); | ||
| 33 | + for (int i = 0; i < width; i++) { | ||
| 34 | + stroke(coswave[i]*255 / 4); | ||
| 35 | + line(i, height/3, i, height/3*2); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + for (int i = 0; i < width; i++) { | ||
| 39 | + stroke(255 - coswave[i]*255); | ||
| 40 | + line(i, height/3*2, i, height); | ||
| 41 | + } | ||
| 42 | + | ||
| 35 | 43 | } | |
| 44 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,27 +6,32 @@ | |||
| 6 | 6 | * 2D arrays are useful for storing images. In this example, each dot | |
| 7 | 7 | * is colored in relation to its distance from the center of the image. | |
| 8 | 8 | */ | |
| 9 | - | ||
| 9 | + | ||
| 10 | 10 | float[][] distances; | |
| 11 | 11 | float maxDistance; | |
| 12 | + int spacer = 10; | ||
| 12 | 13 | ||
| 13 | - size(200, 200); | ||
| 14 | - background(0); | ||
| 15 | - maxDistance = dist(width/2, height/2, width, height); | ||
| 16 | - distances = new float[width][height]; | ||
| 17 | - for(int i=0; i<height; i++) { | ||
| 18 | - for(int j=0; j<width; j++) { | ||
| 19 | - float dist = dist(width/2, height/2, j, i); | ||
| 20 | - distances[j][i] = dist/maxDistance * 255; | ||
| 14 | + void setup() { | ||
| 15 | + size(640, 360); | ||
| 16 | + maxDistance = dist(width/2, height/2, width, height); | ||
| 17 | + distances = new float[width][height]; | ||
| 18 | + for (int y = 0; y < height; y++) { | ||
| 19 | + for (int x = 0; x < width; x++) { | ||
| 20 | + float dist = dist(width/2, height/2, x, y); | ||
| 21 | + distances[x][y] = dist/maxDistance * 255; | ||
| 22 | + } | ||
| 21 | 23 | } | |
| 24 | + noLoop(); // Run once and stop | ||
| 22 | 25 | } | |
| 23 | 26 | ||
| 24 | - for(int i=0; i<height; i+=2) { | ||
| 25 | - for(int j=0; j<width; j+=2) { | ||
| 26 | - stroke(distances[j][i]); | ||
| 27 | - point(j, i); | ||
| 27 | + void draw() { | ||
| 28 | + background(0); | ||
| 29 | + for (int y = 0; y < height; y += spacer) { | ||
| 30 | + for (int x = 0; x < width; x += spacer) { | ||
| 31 | + stroke(distances[x][y]); | ||
| 32 | + point(x + spacer/2, y + spacer/2); | ||
| 33 | + } | ||
| 28 | 34 | } | |
| 29 | 35 | } | |
| 30 | 36 | ||
| 31 | 37 | ||
| 32 | - | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,12 +10,11 @@ int unit = 40; | |||
| 10 | 10 | int count; | |
| 11 | 11 | Module[] mods; | |
| 12 | 12 | ||
| 13 | - | ||
| 14 | 13 | void setup() { | |
| 15 | - size(320, 240); | ||
| 14 | + size(640, 360); | ||
| 16 | 15 | background(176); | |
| 17 | 16 | noStroke(); | |
| 18 | - | ||
| 17 | + smooth(); | ||
| 19 | 18 | int wideCount = width / unit; | |
| 20 | 19 | int highCount = height / unit; | |
| 21 | 20 | count = wideCount * highCount; | |
@@ -24,13 +23,13 @@ void setup() { | |||
| 24 | 23 | int index = 0; | |
| 25 | 24 | for (int y = 0; y < highCount; y++) { | |
| 26 | 25 | for (int x = 0; x < wideCount; x++) { | |
| 27 | - mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8)); | ||
| 26 | + mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit); | ||
| 28 | 27 | } | |
| 29 | 28 | } | |
| 30 | 29 | } | |
| 31 | 30 | ||
| 32 | - | ||
| 33 | 31 | void draw() { | |
| 32 | + background(0); | ||
| 34 | 33 | for (int i = 0; i < count; i++) { | |
| 35 | 34 | mods[i].update(); | |
| 36 | 35 | mods[i].draw(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,38 +1,39 @@ | |||
| 1 | 1 | class Module { | |
| 2 | - int mx, my; | ||
| 3 | - int big; | ||
| 2 | + int xOffset; | ||
| 3 | + int yOffset; | ||
| 4 | 4 | float x, y; | |
| 5 | - int xdir = 1; | ||
| 6 | - int ydir = 1; | ||
| 5 | + int unit; | ||
| 6 | + int xDirection = 1; | ||
| 7 | + int yDirection = 1; | ||
| 7 | 8 | float speed; | |
| 8 | 9 | ||
| 9 | - // Contructor (required) | ||
| 10 | - Module(int imx, int imy, int ix, int iy, float ispeed) { | ||
| 11 | - mx = imx; | ||
| 12 | - my = imy; | ||
| 13 | - x = ix; | ||
| 14 | - y = iy; | ||
| 15 | - speed = ispeed; | ||
| 16 | - big = unit; | ||
| 10 | + // Contructor | ||
| 11 | + Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) { | ||
| 12 | + xOffset = xOffsetTemp; | ||
| 13 | + yOffset = yOffsetTemp; | ||
| 14 | + x = xTemp; | ||
| 15 | + y = yTemp; | ||
| 16 | + speed = speedTemp; | ||
| 17 | + unit = tempUnit; | ||
| 17 | 18 | } | |
| 18 | 19 | ||
| 19 | 20 | // Custom method for updating the variables | |
| 20 | 21 | void update() { | |
| 21 | - x = x + (speed * xdir); | ||
| 22 | - if (x >= big || x <= 0) { | ||
| 23 | - xdir *= -1; | ||
| 24 | - x = x + (1 * xdir); | ||
| 25 | - y = y + (1 * ydir); | ||
| 22 | + x = x + (speed * xDirection); | ||
| 23 | + if (x >= unit || x <= 0) { | ||
| 24 | + xDirection *= -1; | ||
| 25 | + x = x + (1 * xDirection); | ||
| 26 | + y = y + (1 * yDirection); | ||
| 26 | 27 | } | |
| 27 | - if (y >= big || y <= 0) { | ||
| 28 | - ydir *= -1; | ||
| 29 | - y = y + (1 * ydir); | ||
| 28 | + if (y >= unit || y <= 0) { | ||
| 29 | + yDirection *= -1; | ||
| 30 | + y = y + (1 * yDirection); | ||
| 30 | 31 | } | |
| 31 | 32 | } | |
| 32 | 33 | ||
| 33 | 34 | // Custom method for drawing the object | |
| 34 | 35 | void draw() { | |
| 35 | - stroke(second() * 4); | ||
| 36 | - point(mx+x-1, my+y-1); | ||
| 36 | + fill(255); | ||
| 37 | + ellipse(xOffset + x, yOffset + y, 6, 6); | ||
| 37 | 38 | } | |
| 38 | 39 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,26 +6,25 @@ | |||
| 6 | 6 | * Move the cursor vertically over each bar to alter its hue. | |
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | - int barWidth = 5; | ||
| 10 | - int[] hue; | ||
| 9 | + int barWidth = 20; | ||
| 10 | + int lastBar = -1; | ||
| 11 | 11 | ||
| 12 | 12 | void setup() | |
| 13 | 13 | { | |
| 14 | - size(200, 200); | ||
| 15 | - colorMode(HSB, 360, height, height); | ||
| 16 | - hue = new int[width/barWidth]; | ||
| 14 | + size(640, 360); | ||
| 15 | + colorMode(HSB, height, height, height); | ||
| 17 | 16 | noStroke(); | |
| 17 | + background(0); | ||
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | 20 | void draw() | |
| 21 | 21 | { | |
| 22 | - int j = 0; | ||
| 23 | - for (int i=0; i<=(width-barWidth); i+=barWidth) { | ||
| 24 | - if ((mouseX > i) && (mouseX < i+barWidth)) { | ||
| 25 | - hue[j] = mouseY; | ||
| 26 | - } | ||
| 27 | - fill(hue[j], height/1.2, height/1.2); | ||
| 28 | - rect(i, 0, barWidth, height); | ||
| 29 | - j++; | ||
| 22 | + int whichBar = mouseX / barWidth; | ||
| 23 | + if (whichBar != lastBar) { | ||
| 24 | + int barX = whichBar * barWidth; | ||
| 25 | + fill(mouseY, height, height); | ||
| 26 | + rect(barX, 0, barWidth, height); | ||
| 27 | + lastBar = whichBar; | ||
| 30 | 28 | } | |
| 31 | 29 | } | |
| 30 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,12 +7,12 @@ | |||
| 7 | 7 | * Move the cursor vertically over each bar to alter its saturation. | |
| 8 | 8 | */ | |
| 9 | 9 | ||
| 10 | - int barWidth = 5; | ||
| 10 | + int barWidth = 20; | ||
| 11 | 11 | int lastBar = -1; | |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | void setup() { | |
| 15 | - size(200, 200); | ||
| 15 | + size(640, 360); | ||
| 16 | 16 | colorMode(HSB, width, height, 100); | |
| 17 | 17 | noStroke(); | |
| 18 | 18 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,15 +10,15 @@ | |||
| 10 | 10 | * equal to zero then draw a line. | |
| 11 | 11 | */ | |
| 12 | 12 | ||
| 13 | - size(200, 200); | ||
| 13 | + size(640, 360); | ||
| 14 | 14 | background(0); | |
| 15 | 15 | ||
| 16 | - for(int i=10; i<width; i+=10) { | ||
| 16 | + for(int i = 10; i < width; i += 10) { | ||
| 17 | 17 | // If 'i' divides by 20 with no remainder draw the first line | |
| 18 | 18 | // else draw the second line | |
| 19 | 19 | if(i%20 == 0) { | |
| 20 | 20 | stroke(153); | |
| 21 | - line(i, 40, i, height/2); | ||
| 21 | + line(i, 80, i, height/2); | ||
| 22 | 22 | } else { | |
| 23 | 23 | stroke(102); | |
| 24 | 24 | line(i, 20, i, 180); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,20 +7,20 @@ | |||
| 7 | 7 | * action. | |
| 8 | 8 | */ | |
| 9 | 9 | ||
| 10 | - size(200, 200); | ||
| 10 | + size(640, 360); | ||
| 11 | 11 | background(0); | |
| 12 | 12 | ||
| 13 | - for(int i=2; i<width-2; i+=2) { | ||
| 13 | + for(int i = 2; i < width-2; i += 2) { | ||
| 14 | 14 | // If 'i' divides by 20 with no remainder | |
| 15 | 15 | // draw the first line else draw the second line | |
| 16 | - if(i%20 == 0) { | ||
| 16 | + if((i % 20) == 0) { | ||
| 17 | 17 | stroke(255); | |
| 18 | - line(i, 40, i, height/2); | ||
| 19 | - } else if (i%10 == 0) { | ||
| 18 | + line(i, 80, i, height/2); | ||
| 19 | + } else if ((i % 10) == 0) { | ||
| 20 | 20 | stroke(153); | |
| 21 | 21 | line(i, 20, i, 180); | |
| 22 | - } else { | ||
| 22 | + } else { | ||
| 23 | 23 | stroke(102); | |
| 24 | - line(i, height/2, i, height-40); | ||
| 24 | + line(i, height/2, i, height-20); | ||
| 25 | 25 | } | |
| 26 | 26 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,26 +2,23 @@ | |||
| 2 | 2 | * Embedding Iteration. | |
| 3 | 3 | * | |
| 4 | 4 | * Embedding "for" structures allows repetition in two dimensions. | |
| 5 | + * | ||
| 5 | 6 | */ | |
| 6 | - | ||
| 7 | - float box_size = 11; | ||
| 8 | - float box_space = 12; | ||
| 9 | - int margin = 7; | ||
| 10 | - | ||
| 11 | - size(200, 200); | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + size(640, 360); | ||
| 12 | 10 | background(0); | |
| 13 | 11 | noStroke(); | |
| 14 | - | ||
| 15 | - // Draw gray boxes | ||
| 16 | - | ||
| 17 | - for (int i = margin; i < height-margin; i += box_space){ | ||
| 18 | - if(box_size > 0){ | ||
| 19 | - for(int j = margin; j < width-margin; j+= box_space){ | ||
| 20 | - fill(255-box_size*10); | ||
| 21 | - rect(j, i, box_size, box_size); | ||
| 22 | - } | ||
| 23 | - box_size = box_size - 0.6; | ||
| 12 | + | ||
| 13 | + int gridSize = 40; | ||
| 14 | + | ||
| 15 | + for (int x = gridSize; x <= width - gridSize; x += gridSize) { | ||
| 16 | + for (int y = gridSize; y <= height - gridSize; y += gridSize) { | ||
| 17 | + noStroke(); | ||
| 18 | + fill(255); | ||
| 19 | + rect(x-1, y-1, 3, 3); | ||
| 20 | + stroke(255, 50); | ||
| 21 | + line(x, y, width/2, height/2); | ||
| 24 | 22 | } | |
| 25 | 23 | } | |
| 26 | 24 | ||
| 27 | - | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,45 +1,41 @@ | |||
| 1 | 1 | /** | |
| 2 | 2 | * Iteration. | |
| 3 | 3 | * | |
| 4 | - * Iteration with a "for" structure constructs repetitive forms. | ||
| 4 | + * Iteration with a "for" structure to construct repetitive forms. | ||
| 5 | 5 | */ | |
| 6 | 6 | ||
| 7 | - int k; | ||
| 8 | - int xpos1 = 100; | ||
| 9 | - int xpos2 = 118; | ||
| 10 | - int count = 0; | ||
| 11 | - int timey = 0; | ||
| 12 | - int num = 12; | ||
| 7 | + int y; | ||
| 8 | + int num = 14; | ||
| 13 | 9 | ||
| 14 | - size(200, 200); | ||
| 10 | + size(640, 360); | ||
| 15 | 11 | background(102); | |
| 16 | 12 | noStroke(); | |
| 17 | 13 | ||
| 18 | 14 | // Draw gray bars | |
| 19 | 15 | fill(255); | |
| 20 | - k=60; | ||
| 21 | - for(int i=0; i < num/3; i++) { | ||
| 22 | - rect(25, k, 155, 5); | ||
| 23 | - k+=10; | ||
| 16 | + y = 60; | ||
| 17 | + for(int i = 0; i < num/3; i++) { | ||
| 18 | + rect(50, y, 475, 10); | ||
| 19 | + y+=20; | ||
| 24 | 20 | } | |
| 25 | 21 | ||
| 26 | - // Black bars | ||
| 22 | + // Gray bars | ||
| 27 | 23 | fill(51); | |
| 28 | - k = 40; | ||
| 29 | - for(int i=0; i < num; i++) { | ||
| 30 | - rect(105, k, 30, 5); | ||
| 31 | - k += 10; | ||
| 24 | + y = 40; | ||
| 25 | + for(int i = 0; i < num; i++) { | ||
| 26 | + rect(405, y, 30, 10); | ||
| 27 | + y += 20; | ||
| 32 | 28 | } | |
| 33 | - k = 15; | ||
| 29 | + y = 50; | ||
| 34 | 30 | for(int i = 0; i < num; i++) { | |
| 35 | - rect(125, k, 30, 5); | ||
| 36 | - k +=10; | ||
| 31 | + rect(425, y, 30, 10); | ||
| 32 | + y += 20; | ||
| 37 | 33 | } | |
| 38 | 34 | ||
| 39 | 35 | // Thin lines | |
| 40 | - k = 42; | ||
| 36 | + y = 45; | ||
| 41 | 37 | fill(0); | |
| 42 | - for(int i=0; i < num-1; i++) { | ||
| 43 | - rect(36, k, 20, 1); | ||
| 44 | - k+=10; | ||
| 38 | + for(int i = 0; i < num-1; i++) { | ||
| 39 | + rect(120, y, 40, 1); | ||
| 40 | + y+= 20; | ||
| 45 | 41 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments