We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
arc() (Read 1748 times)
arc()
May 7th, 2010, 1:49pm
 
I'm trying to make a circle with arc() and divided him in x part. If it's possible I want to manage the segments dynamically, maybe with an array. But I get lost with the math to calculate the distance between the segments.. If someone can help me out I would be very grateful.

this is what I have so far:

Code:
float xpos; 
float ypos;
int sz;
int strokesize;
float angle1;

float[] data = { PI/16, PI/8, PI/4, PI/2, PI/1 };

void setup() {
frameRate(12);
size(1900,1000);
colorMode(HSB,255,255,255);
ellipseMode(RADIUS);
strokeCap(SQUARE);
//noFill();
xpos =0;
ypos = 0;
sz = width/8;
strokesize = width/10;
}

void draw() {
background(255);
translate(width/2,height/2);
Segmention1();
}


void Segmention1() {

stroke(255, 0, 0,255);
strokeWeight(strokesize);
arc(xpos, ypos, sz, sz, 0, PI/16);
}


thanks a lot!
Re: arc()
Reply #1 - May 8th, 2010, 8:36am
 
Can you explain in a little more detail what you want?  I can see the data[] array contains angles in radians, but then your function Segmention1() draws an arc of a fixed angle (PI/16).  The program creates one small arc in the window.

I think you want it to do something with the values in data[], but what exactly?
Re: arc()
Reply #2 - May 8th, 2010, 10:37am
 
Hi Smitty,

the array is a frustrated attempt..

I want to paint many arcs in the middle of the scene and change the amount of these arcs dynamically, and if it's possible I want to control the width and the distance between them.

Maybe this image help a bit more to explain my purpose:

...

thanks!
Re: arc()
Reply #3 - May 8th, 2010, 11:27am
 
Is this closer to what you want?  The segment() method draws an arc segment between two different angles; you could change those dynamically with a variable.

Code:

float xpos;
float ypos;
int sz;
int strokesize;
float angle1;

void setup() {
frameRate(12);
size(1900,1000);
colorMode(HSB,255,255,255);
ellipseMode(RADIUS);
strokeCap(SQUARE);
//noFill();
xpos =0;
ypos = 0;
sz = width/8;
strokesize = width/10;
}

void draw() {
background(255);
translate(width/2,height/2);
segment(0, PI/6);
segment(2*PI/6, 3*PI/6);
segment(4*PI/6, 5*PI/6);
segment(6*PI/6, 7*PI/6);
segment(8*PI/6, 9*PI/6);
segment(10*PI/6, 11*PI/6);
}


void segment(float angle1, float angle2) {
stroke(255, 0, 0,255);
strokeWeight(strokesize);
arc(xpos, ypos, sz, sz, angle1, angle2);
}

Re: arc()
Reply #4 - May 8th, 2010, 12:09pm
 
Thanks a lot, this is pretty close to what I want to do, but I need to set the amount of the segment dynamically (array?). Is this possible?
So I can set for example 64 or more segments.
Cheers
Re: arc()
Reply #5 - May 8th, 2010, 12:51pm
 
Hi jirko,

I've been playing around with the arc() function as well. If you're interested you can read a blogpost I wrote about it here. It might show you some of the possibilities of arc().

http://amnonp5.wordpress.com/2010/05/08/the-beauty-of-arcs

I have two tips for you:

1. Use radians() with degrees instead of PI-values. I think it's a lot easier.
2. I think using a FOR loop here is probably easier than an array.

Here is some code to show what I mean by these two suggestions.

Code:
int segments = 4;

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

void draw() {
background(255);
noFill();
strokeWeight(15);
strokeCap(SQUARE);
translate(width/2,height/2);

// using the radians() function means you can use 360 degrees,
// which simplifies the math a lot
stroke(0);
arc(10, 10, 100, 100, radians(0), radians(90));
arc(-10, 10, 100, 100, radians(90), radians(180));
arc(-10, -10, 100, 100, radians(180), radians(270));
arc(10, -10, 100, 100, radians(270), radians(360));

// using a FOR loop makes it easier to draw a number of
// similar shapes like this one
for (int i=0; i<segments; i++) {
stroke(i*100,255-i*50,0);
arc(0, 0, 200, 200, radians(i*90), radians((i+1)*90));
}

}


Now perhaps you could play around with the segments value and change some of the arc-math accordingly to make it all work the way you want to. Good luck!

Smiley
Re: arc()
Reply #6 - May 8th, 2010, 12:57pm
 
Consider Toxi's Spline class.
http://toxiclibs.org/docs/core/toxi/geom/Spline2D.html
Download his lib here: http://toxiclibs.org/

Has both 2D and 3D.  It will split an arc into dynamic segments.  He presents an example in this thread.
http://processing.org/discourse/yabb2/num_1229440845.html
Re: arc()
Reply #7 - May 9th, 2010, 2:49am
 
Hey guys,
thanks a lot , very helpful! Enough to get the ball rolling.  Cheesy

Cheers

J
Page Index Toggle Pages: 1