Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                var a =18, b = 10, c = 11,d =5;//initial coefficients for equations
var nParticles = 3000; //number of particles in wave
let pArrayX = [];//xcoordinates
let pArrayY = [];//ycoordinates
let cLim = 10;
var alpha = 4;
var stepD = 10;
function setup() {
  createCanvas(600, 600);//canvas size
  background(255);//white background creates fade effect
  angleMode(DEGREES);//degree mode
  makePArray();//initializes particles
  noStroke();//no outline
}

function draw() {
  translate(width/2,width/2);//origin at center
  background(0,0,0,alpha);//black and transparent
  stepPArray(); //animates particles through parametric equation
}
function mousePressed() {//creates new wave with random equation
    background(255)//white creates fade
    frameCount = 1;//reset frames
    a = round(random(22))//random coefficients a - d
    b = round(random(22))
    c = round(random(22))
    d = round(random(22))
    print(a,b,c,d)//print in console for reproduction
    makePArray()//initialize new particle arrays
}
function makePArray(){
  nParticles = int(random(500,9000))
  cLim = int(random(400,800))
  alpha = random(0.1,20)
  stepD = int(random(8,20))
  pArrayX = [];//clear array
  pArrayY = [];//clear array
  step = frameCount/stepD;//step/speed of wave
  pArrayX[0] = width/4*(cos(a*step)*sin(step)+sin(b*step)/2);//parametric equation for x where step is t
  pArrayY[0] = width/4*(sin(c*step)/2+cos(d*step)*cos(step)) //parametric equation for y where step is t
  for (let i = 1;i<nParticles;i++){//randomize points around the parametric x,y for nParticles
    pArrayX[i] = pArrayX[0]+random(-35,20)*sin(i/9)*cos(i/9)+sin(i*11)+random(-5,5)*cos(i/20)*cos(i)
    pArrayY[i] = pArrayY[0]+random(-50,25)*sin(i*9)*cos(i/11)+random(-5,5)*cos(i/20)*cos(i)
  }
}

function stepPArray(){
  step = frameCount/stepD;//step size for animation
  newX = width/4*(cos(a*step)*sin(step)+sin(b*step)/2);//parametric equation for x where step is t
  newY = width/4*(sin(c*step)/2+cos(d*step)*cos(step));//parametric equation for y where step is t
  deltaX = (pArrayX[0] - newX);//change in x from last point
  deltaY = (pArrayY[0] - newY);//change in y from last point
  pArrayX[0] = newX;//new x -center point
  pArrayY[0] = newY;//new y -center point
  fill(255)
  circle(pArrayX[0],pArrayY[0],3)//plot point
  for (i=1;i<nParticles;i++){//create dispersion of points
    mod1 = pArrayX[i]-pArrayX[0] //find x dist from center point
    mod2 = pArrayY[i]-pArrayY[0]//find y dist from center point
    fill(180-2*(abs(mod1+mod2)),255-0.5*(abs(mod1+mod2)),255-0.5*(abs(mod1+mod2)))//base color on distance from center
    if (mod1 < cLim && mod1>-cLim){ //keep particles in constrained
      mod1 = 0
    }
    if (mod2 < cLim && mod2>-cLim){
      mod2 = 0
    }
    //base new position on last position - delta plus randomness
    pArrayX[i] = (pArrayX[i]-deltaX+randomGaussian(0,0.5))+random(-5,5)*cos(i/11)*sin(i)-random(-4,3)*sin(i/20)-mod1*sin(frameCount);
    pArrayY[i] = ( pArrayY[i]-deltaY+randomGaussian(0,0.5))+ random(-5,5)*cos(i/11)*cos(i*9)-mod2*sin(frameCount)
    circle(pArrayX[i],pArrayY[i],1)//plot particle
  }
}
              
            
!
999px

Console