thanks, but i see the one from the processing book is really bad, it doesn't look even close to a arc no matter where you have the mouse.
The wiki is to complicated, i have no ideas how to use it for my needs.
I was thinking i have just to rotate every time the width of the object to draw and after that the width of the spacing. Rotating from the bottom of the dashed line. (And the first time rotate half the width of the first object).
I managed to get some arc in some way, only half of the arc is 180degrees off (also spacing of red blocks isn't correct).
See:
Could someone take a look at my code?
Also keep in mind i want to be able to draw things continues like this:
In case it helps, i made this but i don't want straight lines anymore:
Copy code
- float[] line;
- float spacing = 5;
- float rh = 8; // rect height
- void setup() {
- size(800, 600);
- frameRate(0.3);
- smooth();
- noStroke();
- rectMode(CENTER);
- }
- void draw() {
- background(255);
- line = new float[int(random(5, 20))];
- for (int i = 0; i < line.length; i++) {
- line[i] = random(4, 10);
- }
-
-
- pushMatrix();
- translate(50, height/2);
- fill(0);
- drawStraight(line);
- // start where the other one ended
- float l = getLength(line);
- translate(l, 0);
- fill(255, 0, 0);
- // radius
- float r = l / (TWO_PI/4); // devide by 4 cause i want a 90 degree arc (Is this math correct?)
- println(r);
- drawArc(line, r);
- popMatrix();
- }
- // In case someone looks and is good at this stuff, being able to set how far it should go would be even more nice
- // like void drawArc(float[] line, float radius, float start, float stop) {
- // (and being able to bend to the other side with negative values or something?)
- void drawArc(float[] line, float radius) {
- pushMatrix();
- translate(0, -radius);
- rotate(HALF_PI);
- // rotate a litle bit for the first one to be correct
- float w = line[0]; // rect width
- float theta = atan2(-radius, w/2);
-
- rotate(theta);
-
-
- for (int i = 0; i < line.length; i++) {
- // width
- w = line[i]; // rect width
- theta = atan2(-radius, w);
-
- rotate(theta);
- rect(w/2, -radius + (-rh/2), w, rh);
- //spacing
- theta = atan2(-radius, spacing);
- rotate(theta);
- }
- popMatrix();
- }
- void drawStraight(float[] line) {
- pushMatrix();
- for (int i = 0; i < line.length; i++) {
- float rw = line[i]; // rect width
- float x = rw/2;
- float y = rh/2;
- rect(x, y, rw, rh);
- translate(rw+spacing, 0);
- }
- popMatrix();
- }
- float getLength(float[] line) {
- float l = 0;
- for (int i = 0; i < line.length; i++) {
- float rw = line[i]; // rect width
- l += rw+spacing;
- }
- return l;
- }
edit: -----
David also thanks, i saw your message after i posted this one. That thing is nice, the only hard thing with it is that you don't know the stop position. Like you can't easily have the radius adjusted so the total form is 90 degrees.