Haoxiang Particle System (Part 2): Exciting Angels - With KarlaColorsCL



CÓDIGO

//(C)Sergio Salazar Latorre
//Haoxiang Particle System With KarlaColorsCL
//Part 1: Exciting Angels
let l = 600
let tb = 10
let np = 500
let p = Array(np)
let ncol = [1,2,3,4,5]
let nc
//----------------------------

function setup() {
  createCanvas(l,l);
  nc = random(ncol)
  loadParticles(nc)
  angleMode(DEGREES)
}

function draw() {
  background(0,tb);
  showParticles()
}

//-----------------------------

function loadParticles(){
  for(let i=0; i<np; i++){
    p[i] = new HaoxiangCL(giveMeKC()) 
  }
}
 
function giveMeKC(){
  //Objeto Instanciado de la clase KarlaColors
  this.KC = new KarlaColors()
  
  //Llamada al metodo del la clase KarlaColors
  if(nc==1){
    return KC.karlaMarina()
  } else if(nc==2){
    return KC.karlaAutumnIng()
  } else if(nc==3){
    return KC.karlaDeepCuore()  
  } else if(nc==4){
    return KC.karlaMangaSunday()  
  } else if(nc==5){
    return KC.karlaTurquoise()
  }
}

function showParticles(){
  for(let i=0; i<np; i++){
    p[i].show()
  }
}


//*****************************

class HaoxiangCL{
  constructor(C){
    this.x = random(l)
    this.y = random(l)
    this.D = random(1,10)
    this.cox = random(l*2/8, l*5/8)
    this.coy = random(l*2/8, l*5/8)
    this.vox = random(0.1,1.5)
    this.voy = random(0.1,1.5)
    this.rox = random(10,l*3/8)
    this.roy = random(10,l*3/8)
    this.c = C
    this.a=0
  }
  
  show(){
    fill(this.c,10)
    stroke(this.c,4)
    this.updatePosition()
    square(this.x, this.y, this.D)
    circle(this.x, this.y, this.D)
    circle(this.x+10, this.y, this.D)
  }
  
  updatePosition(){
    this.x= this.cox + sin(frameCount*this.vox)*this.rox
    this.y= this.coy + cos(frameCount*this.voy)*this.roy
  }
}

// CLASE KARLACOLORS---------------------

class KarlaColors
{
  constructor(){}
  
  karlaAutumnIng(){
    return color(random(0,255),
                 random(50,255),
                 random(120,128))
  }
  karlaMarina(){
    return color(random(255),
                 random(190,255),
                 random(220,255))
  }
  karlaDeepCuore(){
    return color(random(245,255),
                 random(100,255),
                 random(100,255))
  }
  karlaMangaSunday(){
    return color(random(100,255),
                 random(100,255),
                 random(100,255))
  }
  karlaTurquoise(){
     //color(93,193,185)
     //color('hsla(160,100%,50%,1)')
    return color(93,193,185,
                 random(200,255))
  }
}

Comentarios

Entradas populares