Rotating objects inside the canvas

Hello,

I fiddled with your code a bit.
Take a look at what I did to help understand what I did and code is doing.
Good tools for understanding and debugging code are:

  • println()
  • simple visuals like point() to see what is going on.
  • comment/ uncomment
  • noLoop You have this!
  • Slow frameRate You did this!
//https://discourse.processing.org/t/rotating-objects-inside-the-canvas/19387

void setup() 
  {
 size(800, 800);
 frameRate(1);
 //noLoop();
   }

void draw() 
  {
 background(0);
 noFill();
 stroke(255);
 
 translate(width/2, height/2);  // Origin is center of screen
 
 for (int i=0; i<20; i++)
   {
   float x=random(width/8);        // Limit to width/8
   float y=random(height/8);       // Limit to height/8
   //x = 0;
   //y = 0;
   println(x, y);
   //float w=100+random(200);
   //float h=random(20);
   //float len=random(0.0,PI/10);
   //float ph=random(800);
   
  pushMatrix();
   translate(x,y);
   rotate(radians(random(180)));
   //sindraw(x,y,w,h,len,ph);
   
   //Test points
   stroke(255, 255, 0);
   strokeWeight(3);
   point(x, y);
   
  popMatrix();
   }
  }

There are also lots of resources here:

And here:

:)

2 Likes