Last active
January 14, 2019 15:48
-
-
Save dispensable/00d04a90395adc126c8ce211197b79e5 to your computer and use it in GitHub Desktop.
array教学
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int size = 60; | |
float x = 0; | |
color bgColor = #267598; | |
color fillColor = #77C5E8; | |
color strokeColor = #A6E2FC; | |
int stroke = size / 10; | |
int dir = -1; | |
int numBubbles = 5; | |
float[] y = new float[numBubbles]; | |
int[] speed = new int[numBubbles]; | |
void setup() { | |
size(600, 600); | |
fill(fillColor); | |
stroke(strokeColor); | |
strokeWeight(stroke); | |
x = width / 2; | |
} | |
void draw() { | |
background(bgColor); | |
update(); | |
} | |
void update() { | |
for (int i = 0; i<numBubbles; ++i) { | |
y[i] = random(height); | |
speed[i] = int(random(1,4)); | |
} | |
for (int i = 0; i<numBubbles; ++i) { | |
ellipse(width/numBubbles*i,y[i],50,50); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int amount_of_circles = 20; | |
int[][] init_xy = new int[amount_of_circles][2]; | |
int[] circle_r = new int[amount_of_circles]; | |
int growing_speed = 1; | |
int max_r = 400; | |
void setup() { | |
size(800, 800); | |
// init circle position | |
for (int i=0; i<amount_of_circles; i++) { | |
int[] temp = {int(random(width)), int(random(height))}; | |
init_xy[i] = temp; | |
circle_r[i] = int(random(0, width/2)); | |
} | |
} | |
void draw() { | |
background(200); | |
fill(10, 10, 10, 0.6); | |
for (int i=0; i<amount_of_circles; i++) { | |
ellipse(init_xy[i][0], init_xy[i][1], circle_r[i] += 1, circle_r[i] += 1); | |
if (circle_r[i] > max_r) { | |
int[] temp = {int(random(width)), int(random(height))}; | |
init_xy[i] = temp; | |
circle_r[i] = int(random(0, width/2)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment