We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I was attempting to make a little sketch to divide a circle into rings of equal area. I first wrote this in Processing:
// Circular rings of equal area
// D = diameter of the widest circle
// rings = number of rings we want
int D = 100;
float A = PI*D*D/4;
int rings = 3;
void setup(){
size(800,800, OPENGL);
smooth();
strokeWeight(1);
}
void draw(){
int D = 100;
float A = PI*D*D/4;
background(255);
for(int y = 0; y < rings; y++){
float r = random(255);
float g = random(255);
float b = random(255);
float R = D/2;
// fill(r, g, b);
ellipse(width/2, height/2, D, D);
D += 2*A/PI/R;
}
}
I wanted each ring to have its own color but either I'm tired or just not very good and I can't do it. But the 3 rings draw. Another thing is that I want it to stop after creating the set number of rings, yet at the same time I want to be able to use mousepressed() to capture images with save() or saveFrame(), but I don't get the interaction with noLoop();. Anyways, I've removed that now to focus on the basics. So I'm trying this in p5.js:
function setup(){
createCanvas(800,800);
smooth();
strokeWeight(1);
}
function draw(){
var D = 100;
var rings = 3;
var A = PI * D * D / 4;
background(255);
for(var y = 0; y < rings; y++){
var r = random(255);
var g = random(255);
var b = random(255);
var R = D / 2;
// fill(r, g, b);
ellipse(width / 2, height / 2, D, D);
D += 2 * A / PI / R;
}
}
But this draws one circle only. What is it I'm not doing right here? If I put something like var A = PI * D * D / 4;
before draw() and setup(), I get ReferenceError: PI is not defined but it's a constant so I must be handling something incorrectly...
Looking at this further I think I'm drawing this from the center outward... is my math even right??... investigating.
Answers
Your Processing sketch is buggy! It only works when renderer is P3D/OPENGL! 8-}
In order to fix it, you should include noFill(), so it stops the bigger ellipses "devouring" the smaller 1s!
Here's a fixed version which should work in whatever renderer:
And while I was at it, I did a p5.js version of it as well: :-bd
Thank you!! You must have thought that because the thickness of the rings varied that it was a bug, or where you talking about all the other numerous bugs I have loll. No, actually I want the rings to be of equal surface/area, not thickness!! See for instance this. In that context all thicknesses are different as its the area of the ring that is equal... I think I'm going to have to sit down with the math... but thanks for the equal rings and the port, I appreciate!
So I think the following is very close - Processing:
p5.js
I'm taking screenshots and I'm measuring that to make sure it complies lolll. As you can see, it draws outward; I'm thinking about whether it's possible to reverse that to make it more predictable! Thank you for your help!
This might help
Thank you, your version works and also helps confirm that mine works too! After many hours and bugs!! The thing is I wish it were more predictable for graphic design usage i.e. I would like to specify the widest circle as value and have the circles drawn outside in and not inside out... it's all lots of fun! Thank you!
Actually, let me make sure my stuff really matches. I can't integrate it for now but it looked pretty close running both side by side. I'll check it out. Also, yes, TWO_PI etc. lots of tidbits to learn from. Thanks again!
WIP - see this.
That is easy enough but the radii of the inner circles will depend on the number of them so you would have to specify both the maximum rasius and the number of circles.
Thank you for your advice. I'm very much a beginner. The link I provided in the post above shows you the solution I try to use to leverage the same values to generate both inward and outward circles, but in the former case, I can't draw the first ring but the ones that follow seem fine. Otherwise it seems ok. I'll try to implement text with measurements like you showed and I'll see if I'm off!
So I am off, by 10px loll. I have lots to learn! Thanks again!
p.s. finally funkier than I thought; when I pasted the PS and p5.js examples above yours(@quark), finally I had not noticed but the PS one lines up perfectly with yours graphically... whereas the p5.js version I made from it 10px off.
This version starts with a fixed size circle. Change the number of inner circles with the n and m keys
Thanks for the top notch answers, just tried this last one! This is really a blast! Can I select 2 answers, let me try that lolll.(yep). This will be useful! I will backtrack to my unsuccessful port and try to make it happen! Thanks for you help!