| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,13 +6,18 @@ | |||
| 6 | 6 | * the last point. The middle parameters set the control points | |
| 7 | 7 | * that define the shape of the curve. | |
| 8 | 8 | */ | |
| 9 | - | ||
| 10 | - size(640, 360); | ||
| 11 | - background(0); | ||
| 12 | - stroke(255); | ||
| 13 | - noFill(); | ||
| 14 | - smooth(); | ||
| 15 | 9 | ||
| 16 | - for(int i = 0; i < 200; i += 20) { | ||
| 17 | - bezier(180-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0)); | ||
| 10 | + void setup() { | ||
| 11 | + size(640, 360); | ||
| 12 | + stroke(255); | ||
| 13 | + noFill(); | ||
| 14 | + smooth(); | ||
| 18 | 15 | } | |
| 16 | + | ||
| 17 | + void draw() { | ||
| 18 | + background(0); | ||
| 19 | + for (int i = 0; i < 200; i += 20) { | ||
| 20 | + bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0)); | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,11 +13,6 @@ int x; | |||
| 13 | 13 | int y; | |
| 14 | 14 | float outerRad; | |
| 15 | 15 | float innerRad; | |
| 16 | - float px = 0; | ||
| 17 | - float py = 0; | ||
| 18 | - float angle = 0; | ||
| 19 | - float pts = 36; | ||
| 20 | - float rot = 360.0/pts; | ||
| 21 | 16 | ||
| 22 | 17 | void setup() { | |
| 23 | 18 | size(640, 360); | |
@@ -30,10 +25,16 @@ void setup() { | |||
| 30 | 25 | } | |
| 31 | 26 | ||
| 32 | 27 | void draw() { | |
| 28 | + background(204); | ||
| 29 | + | ||
| 30 | + int pts = int(map(mouseX, 0, width, 6, 60)); | ||
| 31 | + float rot = 180.0/pts; | ||
| 32 | + float angle = 0; | ||
| 33 | + | ||
| 33 | 34 | beginShape(TRIANGLE_STRIP); | |
| 34 | - for (int i = 0; i < pts; i++) { | ||
| 35 | - px = x + cos(radians(angle)) * outerRad; | ||
| 36 | - py = y + sin(radians(angle)) * outerRad; | ||
| 35 | + for (int i = 0; i <= pts; i++) { | ||
| 36 | + float px = x + cos(radians(angle)) * outerRad; | ||
| 37 | + float py = y + sin(radians(angle)) * outerRad; | ||
| 37 | 38 | angle += rot; | |
| 38 | 39 | vertex(px, py); | |
| 39 | 40 | px = x + cos(radians(angle)) * innerRad; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,6 @@ | |||
| 3 | 3 | * | |
| 4 | 4 | * Move the mouse across the screen to move the circle. | |
| 5 | 5 | * The program constrains the circle to its box. | |
| 6 | - * | ||
| 7 | - * Updated 27 February 2010 to handle changes in size(). | ||
| 8 | 6 | */ | |
| 9 | 7 | ||
| 10 | 8 | float mx; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ void setup() | |||
| 30 | 30 | background(numChars/2); | |
| 31 | 31 | // Set a gray value for each key | |
| 32 | 32 | for(int i=0; i<numChars; i++) { | |
| 33 | - colors[i] = color(i, i, i); | ||
| 33 | + colors[i] = color(i); | ||
| 34 | 34 | } | |
| 35 | 35 | } | |
| 36 | 36 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,12 +6,11 @@ | |||
| 6 | 6 | ||
| 7 | 7 | float bx; | |
| 8 | 8 | float by; | |
| 9 | - int bs = 75; | ||
| 10 | - boolean bover = false; | ||
| 9 | + int boxSize = 75; | ||
| 10 | + boolean overBox = false; | ||
| 11 | 11 | boolean locked = false; | |
| 12 | - float bdifx = 0.0; | ||
| 13 | - float bdify = 0.0; | ||
| 14 | - | ||
| 12 | + float xOffset = 0.0; | ||
| 13 | + float yOffset = 0.0; | ||
| 15 | 14 | ||
| 16 | 15 | void setup() | |
| 17 | 16 | { | |
@@ -26,39 +25,39 @@ void draw() | |||
| 26 | 25 | background(0); | |
| 27 | 26 | ||
| 28 | 27 | // Test if the cursor is over the box | |
| 29 | - if (mouseX > bx-bs && mouseX < bx+bs && | ||
| 30 | - mouseY > by-bs && mouseY < by+bs) { | ||
| 31 | - bover = true; | ||
| 28 | + if (mouseX > bx-boxSize && mouseX < bx+boxSize && | ||
| 29 | + mouseY > by-boxSize && mouseY < by+boxSize) { | ||
| 30 | + overBox = true; | ||
| 32 | 31 | if(!locked) { | |
| 33 | 32 | stroke(255); | |
| 34 | 33 | fill(153); | |
| 35 | 34 | } | |
| 36 | 35 | } else { | |
| 37 | 36 | stroke(153); | |
| 38 | 37 | fill(153); | |
| 39 | - bover = false; | ||
| 38 | + overBox = false; | ||
| 40 | 39 | } | |
| 41 | 40 | ||
| 42 | 41 | // Draw the box | |
| 43 | - rect(bx, by, bs, bs); | ||
| 42 | + rect(bx, by, boxSize, boxSize); | ||
| 44 | 43 | } | |
| 45 | 44 | ||
| 46 | 45 | void mousePressed() { | |
| 47 | - if(bover) { | ||
| 46 | + if(overBox) { | ||
| 48 | 47 | locked = true; | |
| 49 | 48 | fill(255, 255, 255); | |
| 50 | 49 | } else { | |
| 51 | 50 | locked = false; | |
| 52 | 51 | } | |
| 53 | - bdifx = mouseX-bx; | ||
| 54 | - bdify = mouseY-by; | ||
| 52 | + xOffset = mouseX-bx; | ||
| 53 | + yOffset = mouseY-by; | ||
| 55 | 54 | ||
| 56 | 55 | } | |
| 57 | 56 | ||
| 58 | 57 | void mouseDragged() { | |
| 59 | 58 | if(locked) { | |
| 60 | - bx = mouseX-bdifx; | ||
| 61 | - by = mouseY-bdify; | ||
| 59 | + bx = mouseX-xOffset; | ||
| 60 | + by = mouseY-yOffset; | ||
| 62 | 61 | } | |
| 63 | 62 | } | |
| 64 | 63 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ void setup() { | |||
| 13 | 13 | } | |
| 14 | 14 | ||
| 15 | 15 | void draw() { | |
| 16 | - if(mousePressed) { | ||
| 16 | + if (mousePressed) { | ||
| 17 | 17 | stroke(255); | |
| 18 | 18 | } else { | |
| 19 | 19 | stroke(0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,18 +6,16 @@ | |||
| 6 | 6 | * to the cursor. | |
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | - Eye e1, e2, e3, e4, e5; | ||
| 9 | + Eye e1, e2, e3; | ||
| 10 | 10 | ||
| 11 | 11 | void setup() | |
| 12 | 12 | { | |
| 13 | - size(200, 200); | ||
| 13 | + size(640, 360); | ||
| 14 | 14 | smooth(); | |
| 15 | 15 | noStroke(); | |
| 16 | - e1 = new Eye( 50, 16, 80); | ||
| 17 | - e2 = new Eye( 64, 85, 40); | ||
| 18 | - e3 = new Eye( 90, 200, 120); | ||
| 19 | - e4 = new Eye(150, 44, 40); | ||
| 20 | - e5 = new Eye(175, 120, 80); | ||
| 16 | + e1 = new Eye( 190, 16, 120); | ||
| 17 | + e2 = new Eye( 164, 185, 80); | ||
| 18 | + e3 = new Eye( 390, 200, 220); | ||
| 21 | 19 | } | |
| 22 | 20 | ||
| 23 | 21 | void draw() | |
@@ -27,35 +25,31 @@ void draw() | |||
| 27 | 25 | e1.update(mouseX, mouseY); | |
| 28 | 26 | e2.update(mouseX, mouseY); | |
| 29 | 27 | e3.update(mouseX, mouseY); | |
| 30 | - e4.update(mouseX, mouseY); | ||
| 31 | - e5.update(mouseX, mouseY); | ||
| 32 | 28 | ||
| 33 | 29 | e1.display(); | |
| 34 | 30 | e2.display(); | |
| 35 | 31 | e3.display(); | |
| 36 | - e4.display(); | ||
| 37 | - e5.display(); | ||
| 38 | 32 | } | |
| 39 | 33 | ||
| 40 | 34 | class Eye | |
| 41 | 35 | { | |
| 42 | - int ex, ey; | ||
| 36 | + int x, y; | ||
| 43 | 37 | int size; | |
| 44 | 38 | float angle = 0.0; | |
| 45 | 39 | ||
| 46 | - Eye(int x, int y, int s) { | ||
| 47 | - ex = x; | ||
| 48 | - ey = y; | ||
| 49 | - size = s; | ||
| 40 | + Eye(int tx, int ty, int ts) { | ||
| 41 | + x = tx; | ||
| 42 | + y = ty; | ||
| 43 | + size = ts; | ||
| 50 | 44 | } | |
| 51 | 45 | ||
| 52 | 46 | void update(int mx, int my) { | |
| 53 | - angle = atan2(my-ey, mx-ex); | ||
| 47 | + angle = atan2(my-y, mx-x); | ||
| 54 | 48 | } | |
| 55 | 49 | ||
| 56 | 50 | void display() { | |
| 57 | 51 | pushMatrix(); | |
| 58 | - translate(ex, ey); | ||
| 52 | + translate(x, y); | ||
| 59 | 53 | fill(255); | |
| 60 | 54 | ellipse(0, 0, size, size); | |
| 61 | 55 | rotate(angle); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,18 +5,21 @@ | |||
| 5 | 5 | * speed and direction of the moving shapes. | |
| 6 | 6 | */ | |
| 7 | 7 | ||
| 8 | + float xpos1; | ||
| 9 | + float xpos2; | ||
| 10 | + float xpos3; | ||
| 11 | + float xpos4; | ||
| 8 | 12 | int thin = 8; | |
| 9 | 13 | int thick = 36; | |
| 10 | - float xpos1 = 134.0; | ||
| 11 | - float xpos2 = 44.0; | ||
| 12 | - float xpos3 = 58.0; | ||
| 13 | - float xpos4 = 120.0; | ||
| 14 | 14 | ||
| 15 | 15 | void setup() | |
| 16 | 16 | { | |
| 17 | - size(200, 200); | ||
| 17 | + size(640, 360); | ||
| 18 | 18 | noStroke(); | |
| 19 | - frameRate(60); | ||
| 19 | + xpos1 = width/2; | ||
| 20 | + xpos2 = width/2; | ||
| 21 | + xpos3 = width/2; | ||
| 22 | + xpos4 = width/2; | ||
| 20 | 23 | } | |
| 21 | 24 | ||
| 22 | 25 | void draw() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,15 +9,15 @@ | |||
| 9 | 9 | float max_distance; | |
| 10 | 10 | ||
| 11 | 11 | void setup() { | |
| 12 | - size(200, 200); | ||
| 12 | + size(640, 360); | ||
| 13 | 13 | smooth(); | |
| 14 | 14 | noStroke(); | |
| 15 | 15 | max_distance = dist(0, 0, width, height); | |
| 16 | 16 | } | |
| 17 | 17 | ||
| 18 | 18 | void draw() | |
| 19 | 19 | { | |
| 20 | - background(51); | ||
| 20 | + background(0); | ||
| 21 | 21 | ||
| 22 | 22 | for(int i = 0; i <= width; i += 20) { | |
| 23 | 23 | for(int j = 0; j <= height; j += 20) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,15 +6,21 @@ | |||
| 6 | 6 | * to create an irregular sawtooth line. | |
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | - size(200, 200); | ||
| 10 | - background(0); | ||
| 11 | 9 | int totalPts = 300; | |
| 12 | 10 | float steps = totalPts + 1; | |
| 13 | - stroke(255); | ||
| 14 | - float rand = 0; | ||
| 11 | + | ||
| 12 | + void setup() { | ||
| 13 | + size(640, 360); | ||
| 14 | + stroke(255); | ||
| 15 | + frameRate(1); | ||
| 16 | + } | ||
| 15 | 17 | ||
| 16 | - for (int i = 1; i < steps; i++){ | ||
| 17 | - point( (width/steps) * i, (height/2) + random(-rand, rand) ); | ||
| 18 | - rand += random(-5, 5); | ||
| 18 | + void draw() { | ||
| 19 | + background(0); | ||
| 20 | + float rand = 0; | ||
| 21 | + for (int i = 1; i < steps; i++) { | ||
| 22 | + point( (width/steps) * i, (height/2) + random(-rand, rand) ); | ||
| 23 | + rand += random(-5, 5); | ||
| 24 | + } | ||
| 19 | 25 | } | |
| 20 | 26 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments