int w = 10, h = 10,scl=60,r =10;
void setup() {
size(600,600);
}
void draw() {
background(0);
stroke(255);
for(int i = 0; i < w; i++) for(int j = 0; j < h; j++) {
float a = getRotation( (i+0.5)*scl, (j+0.5)*scl, mouseX,mouseY);
line( (i+0.5)*scl,(j+0.5)*scl,(i+0.5)*scl+cos(a)*r,(j+0.5)*scl+sin(a)*r);
}
circle(mouseX,mouseY,5);
}
float getRotation(float x,float y, float x2, float y2) {
return( atan2(y2-y,x2-x));
}
version 2: (following a circling dot)
int w = 30, h = 30,scl=20,r =10,cr = 200;
void setup() {
size(600,600);
}
void draw() {
background(0);
stroke(255);
float cx = width/2 + cos(TWO_PI/300*frameCount)*cr, cy= height/2 + sin(TWO_PI/300*frameCount)*cr;
for(int i = 0; i < w; i++) for(int j = 0; j < h; j++) {
float a = getRotation( (i+0.5)*scl, (j+0.5)*scl, cx,cy);
line( (i+0.5)*scl,(j+0.5)*scl,(i+0.5)*scl+cos(a)*r,(j+0.5)*scl+sin(a)*r);
}
circle(cx,cy,5);
}
float getRotation(float x,float y, float x2, float y2) {
return( atan2(y2-y,x2-x));
}