Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<PlanetWater> planetwaterL;
- color bg;
- void setup() {
- size(1000, 1000, P2D);
- initPlanet();
- }
- void draw() {
- background(60, 44, 65);
- background(bg);
- for (PlanetWater pw : planetwaterL) {
- pw.run();
- }
- if (keyPressed && key == ' ') {
- initPlanet();
- }
- }
- void initPlanet() {
- planetwaterL = new ArrayList<PlanetWater>();
- for (int i = 0; i < floor(random(3, 6)); i++) {
- float inner = random(100, 350);
- float outer = inner + random(20, 100);
- int precision = int(inner*1.3);
- color c = color(random(255), random(255), random(255));
- planetwaterL.add(new PlanetWater(new PVector(width/2, height/2), inner, outer, precision, c));
- }
- bg = color(random(255), random(255), random(255));
- }
- //___________________________________________________________-_-_-_-_-_-PlanetWater.pde
- class PlanetWater {
- PVector pos;
- float radiusInner;
- float radiusOuter;
- int precision;
- float ex = 0.3;
- float points[] = new float [precision];
- color c;
- PlanetWater(PVector _pos, float _inner, float _outer, int _precision, color _c) {
- pos = _pos.copy();
- radiusInner = _inner;
- radiusOuter = _outer;
- precision = _precision;
- c = _c;
- points = new float [precision];
- }
- void update() {
- for (int i = 0; i < precision; i++) {
- float n = map(noise(i*ex, frameCount*0.05), 0.0, 1.0, radiusInner, radiusOuter);
- points[i] = n;
- }
- }
- void display() {
- noStroke();
- fill(c, 200);
- pushMatrix();
- translate(pos.x, pos.y);
- beginShape(TRIANGLE_FAN);
- vertex(0, 0);
- for (int i = 0; i < precision; i++) {
- float x = cos(i*(TWO_PI/precision)) * points[i];
- float y = sin(i*(TWO_PI/precision)) * points[i];
- vertex(x, y);
- }
- float x = cos(0*(TWO_PI/precision)) * points[0]; //An aditional point to close the circle
- float y = sin(0*(TWO_PI/precision)) * points[0];
- vertex(x, y);
- endShape();
- popMatrix();
- }
- void run() {
- this.update();
- this.display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement