Advertisement
Guest User

Untitled

a guest
Nov 16th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1.  
  2. void setup() {
  3.     //set resolution here
  4.     size(500, 500);
  5.     SPACE = width / num;
  6.     rectMode(CENTER);
  7.     long rand1 = (long) random(0,10000);
  8.     long rand2 = (long) random(0,10000);
  9.     osn = new OpenSimplexNoise(rand1);
  10.     osn2 = new OpenSimplexNoise(rand2);
  11.    
  12.     //set background color here
  13.     background(0, 0, 0);
  14.     drawParticles();
  15.     colorMode(HSB,100);
  16.     //set stroke color here
  17.     stroke(0,0,0,50);
  18.    
  19.     strokeWeight(str_weight);
  20.    
  21. }
  22.  
  23. ArrayList<Particle> p = new ArrayList<Particle>();
  24. OpenSimplexNoise osn;
  25. OpenSimplexNoise osn2;
  26. //set number of particles here, width/60 is a good number
  27. int num = 10;
  28.  
  29. //set noise multiplier. higher number = higher complexity
  30. float noiseVal = 0.0032;
  31. float noiseVal2 = 0.0036;
  32. float noiseVal3 = 0.008;
  33.  
  34. //set stroke weight here
  35. float str_weight = 0.95;
  36. int SPACE;
  37. int SEED = 0;
  38. int LEN = 200;
  39.  
  40. int iterations = 1;
  41. int globalFrame = 0;
  42. void draw() {
  43.     background(0);
  44.     //for each particle
  45.    
  46.     while(globalFrame < LEN) {
  47.         for (int i = 0; i < p.size(); i++) {
  48.             p.get(i).move();
  49.             p.get(i).display();
  50.            
  51.         }
  52.         globalFrame++;
  53.     }
  54.     println("frame : " + SEED);
  55.     saveFrame("output/sin_####.png");
  56.     p = new ArrayList<Particle>();
  57.     drawParticles();
  58.     globalFrame = 0;
  59.     SEED++;
  60.     if (SEED == 360) {
  61.         exit();
  62.     }
  63.    
  64. }
  65.  
  66. //takes screenshot on key press
  67. void keyPressed() {
  68.     saveFrame("new - perl - ###### - " + p.size() + "rem.png");
  69. }
  70.  
  71. float SIN_MULT = 0.75;
  72. float NOISE_RADIUS = 200;
  73. //particle class
  74. class Particle {
  75.     float x;
  76.     float y;
  77.     float nx;
  78.     float ny;
  79.     float j;
  80.     float i;
  81.     boolean d;
  82.     Particle(float x, float y, boolean d) {
  83.         this.x = x;
  84.         this.y = y;
  85.         this.d = d;
  86.        
  87.     }
  88.    
  89.     void display() {
  90.         float nh = (float) osn.eval(
  91.             this.x * noiseVal3,
  92.             this.y * noiseVal3,
  93.             (globalFrame + sin(radians(SEED)) * NOISE_RADIUS) * noiseVal3,
  94.             (globalFrame + cos(radians(SEED)) * NOISE_RADIUS) *  noiseVal3
  95.             );
  96.         float h = map(nh, - 1, 1, - 50,150);
  97.         float b = map(globalFrame,0,LEN,50,100);
  98.         float sx = map(this.nx, - 1,1,2,15);
  99.         float sy = map(this.ny, - 1,1,2,15);
  100.         if (this.d) {
  101.             fill((h) % 100,100,b);
  102.         } else {
  103.             fill(100,b);
  104.         }
  105.         ellipse(this.x,this.y,10,10);
  106.        
  107.     }
  108.    
  109.     void move() {
  110.        
  111.         this.nx = (float) osn.eval(
  112.             this.x * noiseVal,
  113.             this.y * noiseVal,
  114.             (globalFrame + sin(radians(SEED)) * NOISE_RADIUS) * noiseVal,
  115.             (globalFrame + cos(radians(SEED)) * NOISE_RADIUS) *  noiseVal
  116.             );
  117.         this.ny = (float) osn2.eval(
  118.             this.y * noiseVal2,
  119.             this.x * noiseVal2,
  120.             (globalFrame + sin(radians(SEED + 50)) * NOISE_RADIUS) * noiseVal2,
  121.             (globalFrame + cos(radians(SEED + 50)) * NOISE_RADIUS) *  noiseVal2
  122.             );
  123.         this.x += this.nx * SIN_MULT;
  124.         this.y += this.ny * SIN_MULT;
  125.     }
  126. }
  127.  
  128. //loads particles into particle array
  129. void drawParticles() {
  130.     // HEX
  131.     // int count = 0;
  132.     // for (int i = 0; i <= num; i++) {
  133.     //  for (int j = 0; j <= num ; j++) {
  134.     //      float offset = 0;
  135.     //      if (j % 2 == 0) {
  136.     //          offset = width / num / 2;
  137.     //      }
  138.     //      // row.push(new Node(i * SPACE + offset, j * (SPACE / 2) * sqrt(3), i, j));
  139.     //      p.add(new Particle((SPACE * i) + offset,j * (SPACE / 2) * sqrt(3),count));
  140.     //         count++;
  141.     //  }
  142.     // }
  143.     float STEPS = 75;
  144.     float st = width / STEPS;
  145.     for (float i = 0; i < width; i += st) {
  146.         p.add(
  147.             new Particle(
  148.                 i,
  149.                 height / 2 + sin(radians(i + SEED)) * cos(radians(SEED)) * 100,
  150.                 true
  151.             )
  152.         );
  153.         // p.add(
  154.         //     new Particle(
  155.         //         i,
  156.         //         height / 2 + sin(radians(i - SEED + 180)) * 100,
  157.         //         true
  158.         //     )
  159.         // );
  160.     }
  161. }
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement