|
Author |
Topic: circle segments (Read 377 times) |
|
_C
|
circle segments
« on: Dec 16th, 2004, 3:07am » |
|
problem is that im searching for a simple method to create cicle segments, like this scipt does. problem is that only polygons, three-sided forms will be filled, however, i didnt manage that till now. someone did that already? thanks for any hints c Code: Segment s_1, s_2; float u,v; void setup() { ellipseMode(CENTER_DIAMETER); size(800, 500); background(155); stroke(0, 237,235); v=0; s_1 = new Segment(60, 80, 0, v, color(0,0, 200)); s_2 = new Segment(80, 100, 0, v, color(0,200,0)); } void loop() { clear(); if( radians(mouseY)-PI/2>radians(360)-PI/2 ) { u = radians(360)-PI/2; } else u = radians(mouseY)-PI/2; if( radians(mouseX)-PI/2>radians(360)-PI/2 ) { v = radians(360)-PI/2; } else v = radians(mouseX)-PI/2; s_1.wEnd = u; s_2.wEnd = v; s_2.draw(); s_1.draw(); } class Segment { // int value of inner and outer radius; int iRadius, aRadius; // degree values of the start and end point of the segment; float wStart, wEnd; color clr; Segment(int iR, int aR, float wS, float wE, color c) { iRadius = iR; aRadius = aR; wStart = radians(wS)-PI/2; wEnd = radians(wE)-PI/2; clr = c; } void update() { } void drawSegment() { stroke(clr); //start stroke of segment beginShape(LINE_STRIP); //first line vertex( cos(wStart)*iRadius, sin(wStart)*iRadius ); vertex( cos(wStart)*aRadius, sin(wStart)*aRadius ); endShape(); //outer bow beginShape(LINE_STRIP); curveVertex( cos(wStart)*aRadius, sin(wStart)*aRadius ); for(float i=0; i<1; i+=0.05) { curveVertex( cos( wStart+(wEnd-wStart)*i )*aRadius, sin( wStart+(wEnd-wStart)*i )*aRadius ); } curveVertex( cos(wEnd)*aRadius, sin(wEnd)*aRadius ); curveVertex( cos(wEnd)*aRadius, sin(wEnd)*aRadius ); endShape(); //second line beginShape(LINE_STRIP); vertex( cos(wEnd)*aRadius, sin(wEnd)*aRadius ); vertex( cos(wEnd)*iRadius, sin(wEnd)*iRadius ); endShape(); //inner bow beginShape(LINE_STRIP); curveVertex( cos(wEnd)*iRadius, sin(wEnd)*iRadius ); for(float i=1; i>0; i-=0.05) { curveVertex( cos( wStart+(wEnd-wStart)*i )*iRadius, sin( wStart+(wEnd-wStart)*i )*iRadius ); } curveVertex( cos(wStart)*iRadius, sin(wStart)*iRadius ); curveVertex( cos(wStart)*iRadius, sin(wStart)*iRadius ); endShape(); } void drawOutlines() { stroke(200,200, 200,77); noFill(); ellipse(0,0, iRadius*2, iRadius*2); ellipse(0,0, aRadius*2, aRadius*2); } void draw() { push(); translate(width/2, height/2, 0); drawOutlines(); drawSegment(); pop(); } } |
|
|
|
|
|
flight404
|
Re: circle segments
« Reply #1 on: Dec 16th, 2004, 3:14am » |
|
Not exactly sure what you are asking for, but does this help any? http://www.toxi.co.uk/p5/segments/
|
|
|
|
_C
|
Re: circle segments
« Reply #2 on: Dec 16th, 2004, 5:50pm » |
|
thanks, man. i think i can use this as a codebase for a segmentclass. just trying to find a good solution that draws them clear enough...
|
|
|
|
|