fractalkitty looking for math? fractalkitty.com

100 days of code

semiChaotic_Day5

#random#trig#3d#interactive#animation

sArrayDsArrayPxsArrayPysArrayPzsArrayRsCntmakeSphereplotSpheres

let sArrayD = [];//diameter array
let sArrayPx = [];//xperiod
let sArrayPy = [];//yperiod
let sArrayPz = [];//zperiod
let sArrayR = [];//dilation of orbit
let sCnt = 0;
function setup() {
  createCanvas(500, 500,WEBGL);
  noStroke()
}
function draw() {
  background(0);
  ambientLight(-60+sCnt/2, -50+sCnt/1.5, -30+sCnt);//change lighting with more spheres
  pointLight(255, 255, 255, mouseX-width/2, mouseY-width/2, 70);
  orbitControl()//allows for zoom and rotate
  plotSpheres()//plotspheres
  
}
function mousePressed(){//make a new sphere when the mouse is clicked
  makeSphere()
}
function makeSphere(){
  sArrayD[sCnt] = random(1,40);
  sArrayPx[sCnt]= random(10,80);
  sArrayPy[sCnt]= random(10,80);
  sArrayPz[sCnt]= random(10,80);
  sArrayR[sCnt]= random(10,150);
  if (sCnt<200){
    sCnt = sCnt+ 1;
  } 
}
function plotSpheres(){
  for (let i=0;i<sCnt;i++){
    x = sArrayR[i]*sin(frameCount/sArrayPx[i]);
    y = sArrayR[i]*cos(frameCount/sArrayPy[i]);
    z = sArrayR[i]*cos(frameCount/sArrayPz[i]);
    push()
      translate(x,y,z);
      sphere(sArrayD[i],20,20);
    pop()
  }
}