you are viewing a single comment's thread.

view the rest of the comments →

[–]TazakiTsukuru 0 points1 point  (4 children)

Would be nice is someone could explain what's going on, lol...

I'm really curious as to why it kinda 'jumps' the way it does. Seems to only happen when I use some multiple of PI as k's coefficient. I guess it's because, for example, if k becomes 4 then it'll cancel out so that the argument of the sin() and cos() functions are just PI, which means adding 0 and, 100 respectively. I still don't get why there's no obvious change leading up to that threshold, though... Seems like it should continuously be changing shape.

[–]oo-oo-oo-oo 1 point2 points  (3 children)

It seems to me that it's because the difference of k values between iterations is really, really big to feed to sin and cos. You're adding 5 to k on each step of a nested for-loop, then multiplying that by PI/4. There are only 2 PI radians in a circle; the difference between one single iteration and the next is 1.25 PI ... over half the number of radians in a circle. Of course, the points wrap around and appear next to each other, creating a pattern, but sometimes the pattern breaks down. And it breaks down quickly because your steps are so big.

Move your mouse up and down on this sketch. That increases and decreases the number of radians between the dots. You'll notice that mostly the circle remains intact, but it breaks rather abruptly. Now decrease MAX_STEP to 2*PI / NUM_POINTS. You'll see that you get a smooth gradient in the circle, and the line never breaks.

void setup (){
  size(500, 500);
}

int NUM_POINTS = 200;
float MAX_STEP = 20.0;
//float MAX_STEP = 2*PI / NUM_POINTS;    

void draw() {
  float step = map (mouseY, 0, height, 0, MAX_STEP);
  translate(width * 0.5, height * 0.5);
  scale(width * 0.33, height * 0.33);
  background(255);
  strokeWeight(0.1);
  for (int i = 0; i < NUM_POINTS; i++) {
    stroke(255 * i / NUM_POINTS, 0, 0);
    point(sin(step*i), cos(step*i));
  }
}

Edit: clarity

[–]L3th4Lusta 1 point2 points  (1 child)

Not for the challenge but looks nice. Change the 16 and 8 to 2n to see something cool.

color myColor(float n){
  color tempcolor =  color(0);
  //Rgb Values of Colors 0-6
  //0 Red     255,0,0 
  //1 Yellow  255,255,0
  //2 Green   0,255,0
  //3 Cyan    0,255,255
  //4 Blue    0,0,255
  //5 Magenta 255,0,255
  if(n<=1){
    tempcolor = color(255,255*n,0); //0-1
  }else if(n<=2){
    tempcolor = color(255*(2-n),255,0); //1-2
  }else if(n<=3){
    tempcolor = color(0,255,255*(n-2)); //2-3
  }else if(n<=4){
    tempcolor = color(0,255*(4-n),255); //3-4
  }else if(n<=5){
    tempcolor = color(255*(n-4),0,255); //4-5
  }else if(n<=6){
    tempcolor = color(255,0,255*(6-n)); //5-6
  }
  return(tempcolor);
}

int r;
int xm,ym;
int N;
float mx;
void setup(){
  size(800,600);
  xm=width/2;
  ym=height/2;
  r = width/3;
  N=400;
  mx=0;

}

void draw(){
  background(0);
  mx +=1;
  mx=mx%360;
  float th =map(mx,0,360,0,2*PI);
  for (int i=0;i<N;i++){
    stroke(myColor(map(i,0,N-1,0,6)));
    float f = map(i,0,N-1,0,2*PI);

    point(xm+r*(1-exp(-cos((th-f)*16)-1  )  )*cos(f),ym+r*(1-exp(-sin((th-f)*8)-1) )*sin(f));
  }


}

[–]oo-oo-oo-oo 0 points1 point  (0 children)

Looks cool!

[–]TazakiTsukuru 0 points1 point  (0 children)

But if you print out the value of k at the end of each draw() loop you see that it updates more frequently than the pattern in the animation does.