#17: polígonos

A tarefa consistia em: "Empregando rotate(), criar uma aplicação que desenha um polígono regular centralizado na tela com a quantidade de lados informada no próprio código."

Para a resolução desta atividade, foi utilizado beginShape() e endShape(CLOSE), translate(), rotate() e vertex(), onde a variável N serve para escolher a quantidade de lados do polígono.




int n = 3;

void setup(){
  size(400, 500);
}

void draw() {
  background(255);
 
  // Texto
  fill(0);
  textSize(20);
  text("Lados: " + n, 90, 470);

  translate(width*0.5, height*0.5+50);
  rotate(frameCount/60.0);
  drawPoli(0, 0, n, 150);
}

void drawPoli(int cx,int cy, int nLados, int raio){
 
  float ang = TWO_PI/nLados;
  strokeWeight(5);
  stroke(0);
  noFill();

  beginShape();
  for (float i = 0; i < TWO_PI; i += ang){
    float x = cx + cos(i) * raio;
    float y = cy + sin(i) * raio;
    vertex(x, y);
  }
  endShape(CLOSE);
}

Share this:

CONVERSATION

0 comentários:

Postar um comentário