Advertisement
Guest User

Untitled

a guest
Jun 8th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. ArrayList<PlanetWater> planetwaterL;
  2. color bg;
  3.  
  4. void setup() {
  5. size(1000, 1000, P2D);
  6.  
  7. initPlanet();
  8. }
  9.  
  10.  
  11. void draw() {
  12. background(60, 44, 65);
  13. background(bg);
  14.  
  15. for (PlanetWater pw : planetwaterL) {
  16. pw.run();
  17. }
  18.  
  19. if (keyPressed && key == ' ') {
  20. initPlanet();
  21. }
  22. }
  23.  
  24. void initPlanet() {
  25. planetwaterL = new ArrayList<PlanetWater>();
  26.  
  27. for (int i = 0; i < floor(random(3, 6)); i++) {
  28. float inner = random(100, 350);
  29. float outer = inner + random(20, 100);
  30. int precision = int(inner*1.3);
  31. color c = color(random(255), random(255), random(255));
  32. planetwaterL.add(new PlanetWater(new PVector(width/2, height/2), inner, outer, precision, c));
  33. }
  34.  
  35. bg = color(random(255), random(255), random(255));
  36. }
  37.  
  38.  
  39. //___________________________________________________________-_-_-_-_-_-PlanetWater.pde
  40.  
  41. class PlanetWater {
  42.  
  43. PVector pos;
  44. float radiusInner;
  45. float radiusOuter;
  46. int precision;
  47. float ex = 0.3;
  48. float points[] = new float [precision];
  49. color c;
  50.  
  51. PlanetWater(PVector _pos, float _inner, float _outer, int _precision, color _c) {
  52. pos = _pos.copy();
  53. radiusInner = _inner;
  54. radiusOuter = _outer;
  55. precision = _precision;
  56. c = _c;
  57. points = new float [precision];
  58. }
  59.  
  60. void update() {
  61. for (int i = 0; i < precision; i++) {
  62. float n = map(noise(i*ex, frameCount*0.05), 0.0, 1.0, radiusInner, radiusOuter);
  63. points[i] = n;
  64. }
  65. }
  66.  
  67. void display() {
  68. noStroke();
  69. fill(c, 200);
  70. pushMatrix();
  71. translate(pos.x, pos.y);
  72. beginShape(TRIANGLE_FAN);
  73. vertex(0, 0);
  74. for (int i = 0; i < precision; i++) {
  75. float x = cos(i*(TWO_PI/precision)) * points[i];
  76. float y = sin(i*(TWO_PI/precision)) * points[i];
  77. vertex(x, y);
  78. }
  79. float x = cos(0*(TWO_PI/precision)) * points[0]; //An aditional point to close the circle
  80. float y = sin(0*(TWO_PI/precision)) * points[0];
  81. vertex(x, y);
  82. endShape();
  83. popMatrix();
  84. }
  85.  
  86. void run() {
  87. this.update();
  88. this.display();
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement