I have what i can only imagine to be an archaic solution to this problem, but i believe it can be done better somehow.
with a certain degree of research i have arrived at this. Here is a simple animation showcasing my solution, also the graphic is relevant to my project so if you feel you can draw a better "tadpole" please do.
Simply change "v1" to any coordinate and the tadpole will face that direction. also you can change the "size" of the tadpole too if you would like.
If you have any improvements please help.
- float render,rotate,size;
- PVector v1,v2;
- public void setup()
- {
- render=4;
- size=10;
- v1= new PVector(200,0);
- v2= new PVector(200,200);
- frameRate(30);
- size(400,400,P2D);
- noStroke();
- fill(0,60,10,40);
- }
- public void draw()
- {
- background(255);
- //pushMatrix();
- render =(abs(render%2)==1) ? render-2 : render+2;
- render =(render==-7) ? -6:render;
- render =(render==6) ? 5:render;
- PVector tempVEC= new PVector(v2.x-v1.x,v2.y-v1.y);
- translate(200,200);
- println(tempVEC);
- if(tempVEC.x<0)
- {
- rotate(PVector.angleBetween(tempVEC,new PVector(0,1)));
- }
- else
- {
- rotate(-PVector.angleBetween(tempVEC,new PVector(0,1)));
- }
- println(degrees(PVector.angleBetween(tempVEC,new PVector(0,1))));
- beginShape();
- curveVertex(0,-1.7*size);
- curveVertex(0,-1.7*size);
- curveVertex(-.9*size,-1.3*size);
- curveVertex(-1.5*size,0);
- curveVertex(-1.1*size,1.3*size);
- curveVertex(-.2*size,1.7*size);
- //tail
- //-6
- curveVertex((render/10)*size,3.0*size);
- curveVertex((render/10)*size,4.3*size);
- curveVertex((-render/5)*size,5.5*size);
- curveVertex((render/10+.25)*size,4.3*size);
- curveVertex((render/10+.3)*size,3.0*size);
-
- curveVertex(.2*size,1.7*size);
- curveVertex(1.1*size,1.3*size);
- curveVertex(1.5*size,0);
- curveVertex(.9*size,-1.3*size);
- curveVertex(0,-1.7*size);
- curveVertex(0,-1.7*size);
- endShape(CLOSE);
- //popMatrix();
- }