DMCPS V2.0

 

DIMA Medieval Chemical Particle System

CÓDIGO

//(C)Sergio Salazar Latorre

//DMCPS V2.0

let l = 600

let np = 75

let p = Array(np)

let dm=l*5/8

let di=50

let dM=dm+di

let codMov = [1,2,1,1]

let ctb = 13

let ctf = 6

let ts=60

let DC = 0.5

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

class Particula{

  constructor(i){

    this.x = random(l)

    this.y = random(l)

    this.nparticula = i

    this.cm = random(codMov)

    this.cx = this.x

    this.cy = this.y

    this.vx = random(-1, 1)

    this.vy = random(-1,1)

    this.rx = random(l/8,l/5)

    this.ry = random(l/8,l/5)

    

  }

  dibujarParticula(){

    this.calcularCoordenadas()

    fill(128,255,0,ctf)

    circle(this.x,this.y, DC)

  }

  

  calcularCoordenadas(){

    if(this.cm==1){

      this.circular()

    }else if(this.cm==2){

      this.diagonal()

    }else if(this.cm==3){

      this.aleatorio()

    }

  }

  

  circular(){

    this.x = this.cx + sin(frameCount*this.vx)*this.rx

    this.y = this.cy + cos(frameCount*this.vy)*this.ry

  }

  

  diagonal(){

    this.x=(this.x+random(-0.2,0.3))%l

    this.y=(this.y+random(-0.3,0.2))%l

  }

  

  aleatorio(){

    this.x += this.x+random(-5,5)%l

    this.y += this.y+random(-5,5)%l

  }

  

}

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

function configurarLienzoS(){

  createCanvas(l,l)

  angleMode(DEGREES)

  background(0)

}

function configurarLienzoD(){

  background(0,ctb)

  strokeWeight(1)

  stroke(255)

  noFill()

}

function crearParticulas(){

  for(let i=0; i<np; i++){

    p[i] = new Particula(i)

  }

}

function dibujarDistancias(){

  for(let i=0; i<np; i++){

    for(let j=i+1; j<np; j++){

      let dd = dist(p[i].x, p[i].y,

                   p[j].x, p[j].y)

      

      if(dd>dm && dd<dM){

        strokeWeight(0.2)

        stroke(128,255,0,ts) 

        p[i].dibujarParticula()

        p[j].dibujarParticula()

        line(p[i].x, p[i].y,

             p[j].x, p[j].y)

      }

      

      if(dd>dm*5/8 && dd<dM*5/8){

        strokeWeight(0.4)

        stroke(128,255,0,ts) 

        p[i].dibujarParticula()

        p[j].dibujarParticula()

        line(p[i].x, p[i].y,

             p[j].x, p[j].y)

      }

      

      if(dd>dm*3/8 && dd<dM*3/8){

        strokeWeight(0.6)

        stroke(128,255,0,ts) 

        p[i].dibujarParticula()

        p[j].dibujarParticula()

        line(p[i].x, p[i].y,

             p[j].x, p[j].y)

      }

      

      if(dd>dm*2/8 && dd<dM*2/8){

        strokeWeight(0.8)

        stroke(128,255,0,ts)

        p[i].dibujarParticula()

        p[j].dibujarParticula() 

        line(p[i].x, p[i].y,

             p[j].x, p[j].y)

      }

    }

    

  }  

  }

function dibujarParticulas(){

  for(let i=0; i<np; i++){

    p[i].dibujarParticula()

  }  

}


function Firma(){

  strokeWeight(4)

  stroke(50,255,100)

  fill(0)

  text("(C)Sergio Salazar Latorre",10,l-25)

  text("DMCPS V2.0",10,l-5)

}


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


function setup() {

  configurarLienzoS()

  crearParticulas()

}


function draw() {

  configurarLienzoD()

  dibujarParticulas()

  dibujarDistancias()

  Firma()

}



Comentarios