Loading...
Logo
Processing Forum
hello

I am writing a program that distributes .svg's around a circle and am having a problem with a transformation i want to apply. I have simulated the problem with a triangle in the code below.

Basically i want to change the vertical scale of a shape independently of the horizontal scale and then distribute shapes evenly around a circle. When i apply the transformation the circle warps. I understand why this is happening as I am doing scale > rotate > draw but can't find a way around the issue. Have tried draw > scale > rotate which also doesn't work for obvious reasons...

Any help would be well appreciated cheers...

Copy code
  1. int numTri;
  2. float gap;

  3. void setup() {

  4.   size(500, 500);
  5.   background(0);
  6.   noFill();
  7.   stroke(255);
  8.   smooth();
  9.   
  10.   numTri = 8;
  11. }

  12. void draw() {
  13. }

  14. void mouseClicked() {
  15.   
  16.   background(0);
  17.   drawCirc();
  18.   
  19. }

  20. void drawCirc() {

  21.   gap = radians(360)/numTri;

  22.   for(int i = 0; i < numTri; i++) {
  23.     pushMatrix();
  24.     
  25.     translate(mouseX, mouseY);
  26.     scale(1, 0.5);
  27.     rotate(i * gap);
  28.     triangle(0, 0, -50, -200, 50, -200);
  29.     
  30.     popMatrix();
  31.   }
  32. }

Replies(2)

Not sure if I fully understand the problem but if I have then this might be what you want.


Copy code
  1. void mouseClicked() {
  2.   background(0);
  3.   hScale = 1.0;
  4.   drawCirc();
  5.   hScale = 1.2;
  6.   drawCirc();
  7.   hScale = 1.4;
  8.   drawCirc();
  9.   hScale = 1.6;
  10.   drawCirc();
  11. }

  12. void drawCirc() {
  13.   gap = radians(360)/numTri;
  14.   pushMatrix();
  15.   translate(mouseX, mouseY);
  16.   for(int i = 0; i < numTri; i++) {
  17.     pushMatrix();
  18.     rotate(i * gap);
  19.     scale(hScale, 0.5 ); // height scale, base scale
  20.     triangle(0, 0, -87, -50, -87, 50);
  21.     popMatrix();
  22.   }
  23.   popMatrix();
  24. }


perfect, thank you very much.

The problem was the circle getting squashed into an oval. obviously need to rotate first and then scale.... 

very much appreciated