Loading...
Logo
Processing Forum
i don't understan why it is not a perfect circle!!

Copy code
  1. float inner_radius = 80f, outer_radius = 160f;
  2. int numpoint = 30;

  3. void setup() {
  4.   size(500, 500); 
  5.   smooth();
  6. }

  7. void draw() {
  8.   background(0);
  9.   translate(width/2, height/2);

  10.   float  k = 6;
  11.   float c[], s[];
  12.   float theta=0, dt;


  13.   noFill();
  14.   stroke(200);

  15.   c = new float[numpoint];
  16.   s = new float[numpoint];

  17.   stroke(200);
  18.   noFill();
  19.   dt=TWO_PI/(k*(numpoint));

  20.   for(int spicchi=0; spicchi<k; spicchi++) {  

  21.     println( degrees(theta) );

  22.     for(int i=0; i<numpoint; i++) {  
  23.       c[i] = cos(theta);  
  24.       s[i] = sin(theta);

  25.       theta += dt;
  26.     }

  27.     beginShape();

  28.     for(int i=0; i<numpoint; i++) {  
  29.       vertex(c[i]*inner_radius, s[i]*inner_radius);
  30.     }
  31.     for(int i=numpoint-1; i>0; i--) {  
  32.       vertex(c[i]*outer_radius, s[i]*outer_radius);
  33.     }
  34.     vertex(c[0]*inner_radius, s[0]*inner_radius);
  35.     endShape();
  36.   }
  37.   println( degrees(theta) );
  38.   noLoop();
  39. }

Replies(4)

what is not perfect? it is at least round as it should be.
how is it supposed to look like ?
it is not closed! 

this is what i want!

[edit]
i've done with a really dirty hack
Copy code
  1. beginShape();
  2.     for(int i=0; i<numpoint; i++) {  
  3.       vertex(c[i]*inner_radius, s[i]*inner_radius);
  4.     }
  5.     vertex(cos(theta+dt)*inner_radius, sin(theta+dt)*inner_radius);
  6.     
  7.     vertex(cos(theta+dt)*outer_radius, sin(theta+dt)*outer_radius);
  8.     for(int i=numpoint-1; i>0; i--) {  
  9.       vertex(c[i]*outer_radius, s[i]*outer_radius);
  10.     }
  11.     endShape();
but if i put lower sampling point for each slice ( numpoint=5 ) it get some bad errors!
i don't like this solutions at all!
I tried to disassemble your code, but ended up with some kind of weird zoopraxiscope! There's some stuff going on you probably don't need. If you just want the shape, of course there are many ways to make it, for example arcs or curveVertices. It depends on your end-goal. Perhaps going back to basics will provice some clarity with regard to accurate sin-cos rotation.

Code example:
Copy code
  1. boolean linesOnly;
  2. void mouseClicked() { linesOnly = !linesOnly; } // click the mouse to toggle

  3. float inner_radius = 80;
  4. float outer_radius = 160;
  5. int numpoints;

  6. void setup() {
  7.   size(500,500);
  8.   smooth();
  9.   noFill();
  10.   strokeWeight(2);
  11. }

  12. void draw() {
  13.   background(0);
  14.   translate(width/2, height/2);

  15.   numpoints = 3 + mouseX/25;

  16.   stroke(200);
  17.   if (linesOnly) { beginShape(LINES); } else { beginShape(QUAD_STRIP); }
  18.   for(int i=0; i<numpoints+1; i++) {
  19.     vertex(sin(radians(i*360/numpoints))*inner_radius, cos(radians(i*360/numpoints))*inner_radius);
  20.     vertex(sin(radians(i*360/numpoints))*outer_radius, cos(radians(i*360/numpoints))*outer_radius);
  21.   }
  22.   endShape();

  23.   stroke(0,200,0);
  24.   ellipse(0,0,inner_radius*2,inner_radius*2);
  25.   ellipse(0,0,outer_radius*2,outer_radius*2);
  26. }

hei :)
weird  zoopraxiscope is the Path.. ;)

well, i'm using processing to prototype, you know, i wanto to learn pure opengl and all others setups that proceesing hopefully bypass when scretching, so i'm tring not to use PApplet arcs and curves at all
[and, honestly i love have trouble with trigonometry and good old plain vertex]

bytheway, i wanto to do a color wheel like adobe illustrator "colour harmony" panel i don't know if you've got in mind (and  actually i'musing the little hacks i posted and now doing harmony rule system)

so i need to do a slices with different colours and with your QUAD_STRIP technicque is not possible

i think the problem is that in a really strange&weird way i skip a pass of theta+dt and... i don't know,
but if you have solutions or something that could be put in let me know!