//Robert Oh
//Section C
//rhoh@andrew.cmu.edu
//Project-11-Composition
var turtle;
var fx = 240;
var fy = 240;
var diffX = 100;
var diffY = 100;
function setup() {
createCanvas(480, 480);
frameRate(30);
noStroke();
}
function draw() {
background(130, 255, 246);
fishDisplay(fx, fy);
diffX = mouseX - fx;
diffY = mouseY - fy;
if (diffX > 1 || diffX < -1){
fx = fx + (diffX)/30;
}
if (diffY > 1 || diffY < -1){
fy = fy + (diffY)/30
}
}
// drawing each fish
function fishDisplay(x, y) {
turtle = makeTurtle(x, y);
turtle.penDown();
turtle.face(270);
turtle.setColor(100);
turtle.setWeight(3);
//body
for (var i = 0; i < 360; i ++){
turtle.forward(.7);
turtle.right(1);
}
turtle.face(0);
turtle.penUp();
turtle.forward(80);
//tail
turtle.penDown();
turtle.face(30);
turtle.forward(40);
turtle.face(270);
turtle.forward(40);
turtle.face(150);
turtle.forward(40);
turtle.penUp()
turtle.face(180);
turtle.forward(60);
turtle.face(270);
turtle.forward(25);
//eye
turtle.penDown();
turtle.face(0);
for (var i = 0; i < 180; i ++){
turtle.forward(.2);
turtle.right(2);
}
}
function turtleLeft(d){this.angle-=d;}function turtleRight(d){this.angle+=d;}
function turtleForward(p){var rad=radians(this.angle);var newx=this.x+cos(rad)*p;
var newy=this.y+sin(rad)*p;this.goto(newx,newy);}function turtleBack(p){
this.forward(-p);}function turtlePenDown(){this.penIsDown=true;}
function turtlePenUp(){this.penIsDown = false;}function turtleGoTo(x,y){
if(this.penIsDown){stroke(this.color);strokeWeight(this.weight);
line(this.x,this.y,x,y);}this.x = x;this.y = y;}function turtleDistTo(x,y){
return sqrt(sq(this.x-x)+sq(this.y-y));}function turtleAngleTo(x,y){
var absAngle=degrees(atan2(y-this.y,x-this.x));
var angle=((absAngle-this.angle)+360)%360.0;return angle;}
function turtleTurnToward(x,y,d){var angle = this.angleTo(x,y);if(angle< 180){
this.angle+=d;}else{this.angle-=d;}}function turtleSetColor(c){this.color=c;}
function turtleSetWeight(w){this.weight=w;}function turtleFace(angle){
this.angle = angle;}function makeTurtle(tx,ty){var turtle={x:tx,y:ty,
angle:0.0,penIsDown:true,color:color(128),weight:1,left:turtleLeft,
right:turtleRight,forward:turtleForward, back:turtleBack,penDown:turtlePenDown,
penUp:turtlePenUp,goto:turtleGoTo, angleto:turtleAngleTo,
turnToward:turtleTurnToward,distanceTo:turtleDistTo, angleTo:turtleAngleTo,
setColor:turtleSetColor, setWeight:turtleSetWeight,face:turtleFace};
return turtle;}
For this project, I went back to data exam 1 once again and borrowed the fish design we had drawn. I wanted to revisit the data exam and had the fish follow the mouse cursor. Overall, I had a lot of fun recreating the fish (but with turtle-style drawing).