Windmill

Not so prud of this one, but always learning something in the process. The code is a mess, as you can see by yourself.

let n = 10;
let circleSize = 40;
let baseSpeed = 0.03;
let cQ = [];
let cQ2 = [];
let cQ3 = [];
let cQ4 = [];

function setup() {
  createCanvas(windowWidth, windowHeight);
  for(let i = 1; i <= n; i++){
    cQ[i-1] = new CircleQueue(20 + i, circleSize, baseSpeed - 0.001*i, i * (circleSize), 0);
  }
  for(let i = 1; i <= n; i++){
    cQ2[i-1] = new CircleQueue(20 + i, circleSize, baseSpeed - 0.001*i, i * (circleSize), PI);
  }
    for(let i = 1; i <= n; i++){
    cQ3[i-1] = new CircleQueue(20 + i, circleSize, baseSpeed - 0.001*i, i * (circleSize), PI/2);
  }
  for(let i = 1; i <= n; i++){
    cQ4[i-1] = new CircleQueue(20 + i, circleSize, baseSpeed - 0.001*i, i * (circleSize), 3*PI/2);
  }  
  noStroke();
  let fs = fullscreen();
  fullscreen();
}

function draw() {
  background(0);
  for(let i = 1; i <= n; i++){
    cQ[i-1].update();
    cQ2[i-1].update();
    cQ3[i-1].update();
    cQ4[i-1].update();
  }
}

class CircleQueue{
  queue;
  constructor(length, size, speed, pathSize, offset){
    this.counter = 0.0;
    this.queue = [];
    this.length = length;
    this.size = size;
    this.speed = speed;
    this.pathSize = pathSize;
    this.offset = offset;
    for(let i = 0; i < length; i++){
      this.queue.push(new Circle(windowWidth/2,windowHeight/2));
    }
  }
  
  update(){
    
    this.counter += this.speed;
    
    for(var i = 0; i < this.length - 1; i++){
      this.queue[i].x = this.queue[i+1].x;
      this.queue[i].y = this.queue[i+1].y;
      fill(i * 255/this.length);
      circle(this.queue[i].x, this.queue[i].y, this.size * (i+1)/this.length);
    }
    
    var currX = windowWidth/2 + cos(this.counter + this.offset) * this.pathSize + cos(this.counter+ this.offset);
    var currY = windowHeight/2 + sin(this.counter+ this.offset) * this.pathSize + sin(this.counter+ this.offset);
    
    this.queue[this.length-1].x = currX;
    this.queue[this.length-1].y = currY;
  }
}
  
class Circle{
  x;
  y;
  constructor(x, y){
    this.x = x;
    this.y = y;
  }
}

function mousePressed() {
  if (mouseX > 0 && mouseX < windowWidth && mouseY > 0 && mouseY < windowHeight) {
    let fs = fullscreen();
    fullscreen(!fs);
  }
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
}

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *