We are about to switch to a new forum software. Until then we have removed the registration on this forum.
With a combination of few lines of code I find on the internet, I tried to generate concentric closed curves (looking like irregular circles in the inside of a tree). Instead of drawing multiple curves, I only manage to draw one spiral closing at the end... How could I fix that ?
Here is the code :
import java.util.Iterator;
ArrayList coords;
int num = 10;
int rad = 10;
void setup() {
size(600, 400);
coords = new ArrayList();
smooth();
for (int inter = 0; inter < 300; inter+= 20) {
for (float a=0; a<=TWO_PI; a+=TWO_PI/num) {
coords.add(new PVector(cos(a)*(rad + inter) *(noise(a/10)), sin(a)*(rad + inter)*(noise(a/10))));
}
}
}
void draw()
{
background(255);
strokeWeight(2);
stroke(#8b8378);
fill(#ffefdb);
translate(width/2, height/2);
beginShape();
for (Iterator i = coords.iterator(); i.hasNext(); ) {
PVector p = (PVector)i.next();
curveVertex(p.x, p.y);
}
for (int i=0; i<3; i++) {
PVector p = (PVector)coords.get(i);
curveVertex(p.x, p.y);
}
endShape(CLOSE);
}
Thanks !
Answers
in draw() you were overthinking things a bit.
Since you add stuff to the coords, you can just read it from there and don't need a double for-loop in draw() anymore
main aspect was to get rid of CLOSE in
endShape();
I also told the ArrayList its type (
ArrayList<PVector> coords;
), so no need to cast itThanks for your answer ! But it still draws a spiral instead of multiple concentric and irregular circles... All I did between the beginShape() and and the endShape() was in order to have every circles to close...
doesn't work but should be the right idea....
I dont understand why, but it seems to display the whole thing way out of the screen and nothing like scale, constrain or map seems to work here.. I didn't know it would have been so difficult just to draw some irregular circles in processing !
The idea here is that you group content to circles here....
so when in draw(), you need to read them out group by group...
That's what I try here....
I understand the idea but I can't find a way to make it work...
you're adding 15 different rings' worth of coordinates to a single list.
and then, when you come to use them in draw(), you are treating the whole thing as one shape. hence the spiral.
i'd add the distinct rings to distinct lists (or arrays, given that you know the size) and then iterate over those in draw.
and then you'll realise that you only see the out loop because you're using fill() and that's overwriting the inner loops...
(and use noLoop() if the drawing doesn't change with time)
here i've gotten rid of the storing of the coords and just moved the callculations to the curvevertex call.
not sure yet why the circles are not circular, probably something to do with the noise.
ok, the curves aren't complete because the first and last control points are ignored, they just serve to set the curve at the ends.
https://processing.org/reference/curveVertex_.html
Thanks for your help koogs ! The issue is now to close smoothly each circle.. I want them to be irregular (with the noise) but not to be closed with a straight line ! And to do that, the last 3 curveVertex need to have the same coordinates as the first 3...
To control the coordinates of the 3 last vertex I think I will have no other choice than to store them in an array list...
I finally managed to do it, but the ridiculous way. Thank you both for your help, don't hesitate if you have ideas to make it shorter !
Here it is :
Thank you so much BarbaraAlmeida, that's exactly what I was looking for ! :)