We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello there, I am trying to achieve the effect in the picture using processing but somehow it is not working properly. The lines aren't getting distributed perfectly. why?
void setup() {
size(400, 400);
}
int N = 8;
void draw() {
background(0);
stroke(-1);
strokeWeight(2);
translate(width>>1, height>>1);
for (int j=1; j<10; j++) {
int M = N*j;
float ang = 360/M;
float R = 20*j;
// pushMatrix(); // trying to fix the rotation
// rotate((j%2==0)?radians(ang/2):0); // trying to fix the rotation
for (int i=0; i<M; i++) {
float x = R*cos(radians(ang)*i);
float y = R*sin(radians(ang)*i);
pushMatrix();
translate(x, y);
rotate(radians(ang)*i);
line(-10, 0, 10, 0);
popMatrix();
}
// popMatrix();
}
}
Answers
I believe the problem lies @
float ang = 360/M;
. :-\"In Java when both operands in a division operation are of integer types, the result is also integer, w/o any fractional part! :-SS
Here's my attempt. Still not straight lines. But it's a beginning. >-)
You are creating the rays from smaller segments which will be difficult to line up. The alternative would be to calculate the start and end of each ray then draw the ray in one piece.
This program does that
@GoToLoop Thank for the effort. I am certainly gonna use your code.
@quark Thanks for the effort but I am actually trying to implement this animation in processing ...
The trick here is to think in terms of 'rings' where each ring has a number of properties
This is enough information to draw the stationary image. To do the animation would also require
You will also need a master controller variable [t] which is used to determine the stage of the animation. The value of t will vary from 0-1 and the actual angle for each ring will be
t * dir * deltaA
.Notes
The next step is to decide on how to represent the data that define the rings.
This animation looked challenging so I decided to have a go myself based on my previous post.
I have managed to produce an almost exact copy of the gif animation in under 100 lines of code. I can post it here if you want but I understand that you might want to try it yourself.
@quark thanks for the comment. I have done the same thing as you have mentioned. I have created the ring of lines but the problem is lines are not getting distributed properly. That was my only concern. And thanks for the animation trick. I will definitely try that.
As for now don't post the code. I want to try first :)
One of the problems in your original code is that you define the position of the line by its centre and then rotate about that position. Unfortunately the rotation should be about the pattern centre. It would be better if you define each line segment by its inner radius, outer radius and the angle about the pattern centre.
Unfortunately there is no simple fix to your original code to align the segments.
The code below is very basic and draws 3 rings showing how to align the line segments. It is only to get you started and you can ignore the code if you want but a full solution including animation will still require a lot more work on your part.
@xenomorph -- did you ever get that full animated radial effect to align correctly? I would be interested in seeing the resulting sketch if you are willing to share it -- and/or willing to let @quark share his.
It seems floats are more imprecise than I thought they were.
floats are accurate to 6/7 digits so are good enough for most things. The errors only become apparent under certain circumstances and sometimes they can be avoided by modifying the calculation algorithm.
The full solution simply involves adding extra calls to drawRing although I did an OO version which allows rings to have different colours. I will have a look for it when I get a chance.
And that's what you did.
So will you post the solution here?
If I still have the solutions, then yes I will post them but not until the weekend as I am away from home.
@quark reminder to self
@Lord_of_the_Galaxy
Here is the non OO version.
And here is the OO version
@quark Thanks!
@quark -- thank you so much for digging this up and sharing it.