All Right.
Cheers for doing this memo.
Looks good but the jitter is a bit annoying
Your second solution was the one that we were trying to do but we didn't have any success. I coding isn't that good.
We are trying with curveVertex and some tan function to draw the snake. But know we have to find a way to rewrite our collision function
and that going to be really @*&ing hard.
CURVE VERTEX:
Quote:
static final int V_MAX = 20; // Max nb of vertices
static final float L_MAX = 500.0; // Max length
float[] X = new float[V_MAX];
float[] Y = new float[V_MAX];
float[] V = new float[V_MAX];
float[] W = new float[V_MAX];
float len;
int lastV;
float detail, weight = 20;
int type;
void setup() {
size(500, 500);
}
void draw() {
smooth();
background(255);
fill(0);
stroke(0);
X[0] = mouseX;
Y[0] = mouseY;
if ( mouseX != pmouseX || mouseY != pmouseY){
for (int i = V_MAX-1; i > 0; i--) {
X[i] = X[i-1];
Y[i] = Y[i-1];
}
len = 0.0;
lastV = 1;
for (; lastV < V_MAX; lastV++) {
float d = dist(X[lastV], Y[lastV], X[lastV - 1], Y[lastV - 1]);
if (len + d > L_MAX)
break;
len += d;
}
}
for (int i = 1; i < lastV-1; i++) {
println(i);
if (i==2 || i==lastV-3){
weight = 0;
}
else{
weight = 10;
}
V[i] = thicknessX(X[i-1], X[i], X[i+1], Y[i-1], Y[i], Y[i+1], weight);
W[i] = thicknessW(X[i-1], X[i], X[i+1], Y[i-1], Y[i], Y[i+1], weight);
}
// println(W);
noFill();
curveTightness(0);
beginShape();
for (int i = 1; i < lastV-1; i++) {
strokeWeight(1);
curveVertex(X[i], Y[i]);
}
endShape();
beginShape();
for (int i = 1; i < lastV-1; i++) {
strokeWeight(1);
curveVertex(V[i], W[i]);
}
endShape();
}
/*The parrallel line fuctions*/
float thicknessX(float Xa, float Xb, float Xc, float Ya, float Yb, float Yc, float h){
float T = atan2(Ya-Yc, Xa-Xc);
float V = Xb+h*cos(T+HALF_PI);
return V;
}
float thicknessW(float Xa, float Xb, float Xc, float Ya, float Yb, float Yc, float h){
float T = atan2(Ya-Yc, Xa-Xc);
float W = Yb+h*sin(T+HALF_PI);
return W;
}
the weight variable is here to adjust the thickness of the snake.
I have to leave the office now, but I will be back tomorrow morning and I will look at the forum this evening.
Thanks a lot to everyone, it just helps lot to have different point of view or people reinforcing your idea.