# Polygon Exploration

**URL:** <https://discourse.processing.org/t/polygon-exploration/44606>\
**Category:** Gallery\
**Created:** [June 17, 2024, 11:58am UTC](https://discourse.processing.org/t/polygon-exploration/44606 "2024-06-17T11:58:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 17, 2024, 11:58am UTC](https://discourse.processing.org/t/polygon-exploration/44606/1 "2024-06-17T11:58:37Z")

</div>

Some fun with polygons!

```auto
/*
 Project: Polygons
 Author: GLV
 Date: 2024-06-17
 Version: 1.0.0
*/

int choice, seed;
int id, idlast, sb, num, mxvs;
int counter;

PVector[] v;

boolean warning = true;

void settings()
  {
  size(400, 400, P2D);
  }

void setup() 
  { 
  background(0);
  strokeWeight(2);
  noLoop();
  }
  
void draw()
  {
  background(0);
  translate(width/2, height/2);
 
  int vs = 10; // 1 to max vertices
  int sp = 12; // speed   
 
   // Some bit manipulation just for the challenge!
  id = ((counter+vs*sp)/sp)%(2*vs)-vs;    
  sb = (id>>23)&1;
  num = (id^-sb)+sb+1;
  
  stats(); // Development and debug
  
  v = new PVector[num];  
  int r = 150;
  
  // Polygons
  if(choice == 0)
    {
    stroke(255, 100, 0);
    for(int k = 0; k < num; k++)
      {
      float angle = k*(TAU/num) - TAU/4;
      float x = r*cos(angle);
      float y = r*sin(angle);
      v[k] = new PVector(x, y);
      }
    }
    
  // Random points
  else if (choice == 1)
    {
    stroke(0, 255, 0);
    randomSeed(seed);
    for(int k = 0; k < num; k++)
      {  
      float x = random(-width/2+10, width/2-10);
      float y = random(-height/2+10, height/2-10);
      v[k] = new PVector(x, y);
      }
    } 
    
  // Random offsets on polygons
  else if (choice == 2)
    {
    stroke(255, 255, 0);  
    for(int k = 0; k < num; k++)
      {
      r = (int) random(130, 170);
      float angle = k*(TAU/num) - TAU/4;
      float x = r*cos(angle);
      float y = r*sin(angle);
      v[k] = new PVector(x, y);
      }
    }  
      
  for(int i = 0; i < num-1; i++)
    {
    for(int j = i+1; j < num; j++)
      {
      //println(i,j);  
      line(v[i].x, v[i].y, v[j].x, v[j].y);
      }
    } 
    
  counter++;
  
  if (warning)
    {
    background(0);
    
    rectMode(CENTER);
    fill(0);
    noStroke();
    rect(0, 0, width, height);
    
    textAlign(CENTER, CENTER);
    textSize(48);
    fill(255, 0, 0);
    text("WARNING", 0, -height/3);
    
    fill(255, 255, 0);
    textSize(32);
    text("This animation contains \n fast moving images.", 0, -50);
    fill(255, 255, 0);
    textSize(32);
    text("Press 5 to continue. \n Press any other key to exit.", 0, 60);  
    fill(0, 255, 255);
    textSize(24);
    text("Press mouse to change animation!", 0, 140); 
    }
  }

void stats()
  {
  if(id != idlast) 
    {
    println(str(' ')+num, id); // end line and line feed. 
    } 
  print(sb);
  idlast = id;
  }

void keyPressed()
  {
  if (key == '5')
    {
    warning = false;
    choice = 0;
    counter = 0;
    loop();  
    }
  else
    exit();
  }
  
void mousePressed()
  {
  choice++;
  choice = choice%3;
  counter = 0;
  seed = frameCount;
  println(choice);
  }

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/3/b3203cef317fa9c9780fb396af2af247a822e559.png)

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/9/796310127f5a8dae4eeb3089a0174decd767c781.png)

`:)`
