I have drawn a turtle in procedural processing in this first bit of code (see code #1) but when I try to draw that turtle in the draw () function by calling it as a method, the stroke disappears around it (see code #2). What is the most efficient way to address this problem? I cannot do OOP for this right now, so I need to remain in procedural programming.
CODE #1:
// define the size and color of the program and call the turtle method
void setup () {
size(400, 400); // set canvas size
background(0, 170, 250); // set background color to a watery shade of blue
turtle (width/4, height/2); // call the turtle method and give it arguments that position
// it so that it seems roughly near the middle of the canvas
}
// Define the turtle procedure as a method in its own section
void turtle (float turtleX, float turtleY) { // create the turtle method
// assign parameters for the color and stroke of the solid turtle figure
fill (114, 188, 19); // set color of solid figure to a turtle-like green
smooth(); // set anti-aliased edges for the solid turtle figure
strokeWeight (3); // set the thickness of the stroke that delineated the solid turtle figure
//draw the rear legs of the turtle with triangle
triangle (turtleX+28, turtleY+18, turtleX+40, turtleY+10, turtleX, turtleY+4);
triangle (turtleX+28, turtleY+18, turtleX+22, turtleY+52, turtleX+52, turtleY+62);
// draw the top flapper underneath the body and head
beginShape();
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+128, turtleY+21);
curveVertex (turtleX+138, turtleY-8);
curveVertex (turtleX+115, turtleY-30);
curveVertex (turtleX+125, turtleY-15);
curveVertex (turtleX+113, turtleY+7);
curveVertex (turtleX+113, turtleY+7);
endShape(CLOSE);
// draw the bottom flapper underneath the body and head
beginShape();
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+136, turtleY+27);
curveVertex (turtleX+138, turtleY+42);
curveVertex (turtleX+130, turtleY+60);
curveVertex (turtleX+118, turtleY+85);
curveVertex (turtleX+119, turtleY+86);
curveVertex (turtleX+115, turtleY+78);
curveVertex (turtleX+124, turtleY+25);
curveVertex (turtleX+124, turtleY+25);
endShape(CLOSE);
// draw the body of the turtle with 11 curveVertices points
beginShape ();
//end of the turtle's tail
curveVertex (turtleX, turtleY+30);
curveVertex (turtleX, turtleY+30);
//top of turtle
curveVertex (turtleX+12, turtleY+20);
curveVertex (turtleX+50, turtleY+8);
curveVertex (turtleX+118, turtleY);
// head of turtle and twist in the turtle's neck
curveVertex (turtleX+152, turtleY+30);
curveVertex (turtleX+166, turtleY+8);
curveVertex (turtleX+146, turtleY+10);
//bottom of turtle
curveVertex (turtleX+126, turtleY+40);
curveVertex (turtleX+80, turtleY+52);
curveVertex (turtleX+20, turtleY+35);
// part of turtle's tail that connects to its end
curveVertex (turtleX+12, turtleY+25);
curveVertex (turtleX+12, turtleY+25);
endShape(CLOSE);
// draw the eye and the smile of the turtle
fill(232, 221, 7);
ellipse (turtleX+158, turtleY+14, 2, 2);
noStroke();
fill(93, 9, 0);
arc(turtleX+156, turtleY+24, 6, 6, QUARTER_PI, PI+QUARTER_PI);
}
END OF CODE #1
BEGINNING OF CODE #2 (the turtle to be animated)
/* Turtle animation */
void setup() {
size(1200, 800); // set the canvas size at 1200 pixels by 800 pixels
background(0, 170, 250); // set background color to the watery shade of blue
}
void draw() {
background(0, 170, 250); // recall the background color in setup during draw
turtle (width/4, height/2); // draw the turtle
}
// Define the turtle procedure as a method in its own section
void turtle (float turtleX, float turtleY) { // create the turtle method
// assign parameters for the color and stroke of the solid turtle figure
fill (114, 188, 19); // set color of solid figure to a turtle-like green
smooth(); // set anti-aliased edges for the solid turtle figure
strokeWeight (3); // set the thickness of the stroke that delineated the solid turtle figure
//draw the rear legs of the turtle with triangle
triangle (turtleX+28, turtleY+18, turtleX+40, turtleY+10, turtleX, turtleY+4);
triangle (turtleX+28, turtleY+18, turtleX+22, turtleY+52, turtleX+52, turtleY+62);
// draw the top flapper underneath the body and head
beginShape();
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+128, turtleY+21);
curveVertex (turtleX+138, turtleY-8);
curveVertex (turtleX+115, turtleY-30);
curveVertex (turtleX+125, turtleY-15);
curveVertex (turtleX+113, turtleY+7);
curveVertex (turtleX+113, turtleY+7);
endShape(CLOSE);
// draw the bottom flapper underneath the body and head
beginShape();
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+136, turtleY+27);
curveVertex (turtleX+138, turtleY+42);
curveVertex (turtleX+130, turtleY+60);
curveVertex (turtleX+118, turtleY+85);
curveVertex (turtleX+119, turtleY+86);
curveVertex (turtleX+115, turtleY+78);
curveVertex (turtleX+124, turtleY+25);
curveVertex (turtleX+124, turtleY+25);
endShape(CLOSE);
// draw the body of the turtle with 11 curveVertices points
beginShape ();
//end of the turtle's tail
curveVertex (turtleX, turtleY+30);
curveVertex (turtleX, turtleY+30);
//top of turtle
curveVertex (turtleX+12, turtleY+20);
curveVertex (turtleX+50, turtleY+8);
curveVertex (turtleX+118, turtleY);
// head of turtle and twist in the turtle's neck
curveVertex (turtleX+152, turtleY+30);
curveVertex (turtleX+166, turtleY+8);
curveVertex (turtleX+146, turtleY+10);
//bottom of turtle
curveVertex (turtleX+126, turtleY+40);
curveVertex (turtleX+80, turtleY+52);
curveVertex (turtleX+20, turtleY+35);
// part of turtle's tail that connects to its end
curveVertex (turtleX+12, turtleY+25);
curveVertex (turtleX+12, turtleY+25);
endShape(CLOSE);
// draw the eye and the smile of the turtle
fill(232, 221, 7);
ellipse (turtleX+158, turtleY+14, 2, 2);
noStroke();
fill(93, 9, 0);
arc(turtleX+156, turtleY+24, 6, 6, QUARTER_PI, PI+QUARTER_PI);
}
END OF CODE #2
CODE #1:
// define the size and color of the program and call the turtle method
void setup () {
size(400, 400); // set canvas size
background(0, 170, 250); // set background color to a watery shade of blue
turtle (width/4, height/2); // call the turtle method and give it arguments that position
// it so that it seems roughly near the middle of the canvas
}
// Define the turtle procedure as a method in its own section
void turtle (float turtleX, float turtleY) { // create the turtle method
// assign parameters for the color and stroke of the solid turtle figure
fill (114, 188, 19); // set color of solid figure to a turtle-like green
smooth(); // set anti-aliased edges for the solid turtle figure
strokeWeight (3); // set the thickness of the stroke that delineated the solid turtle figure
//draw the rear legs of the turtle with triangle
triangle (turtleX+28, turtleY+18, turtleX+40, turtleY+10, turtleX, turtleY+4);
triangle (turtleX+28, turtleY+18, turtleX+22, turtleY+52, turtleX+52, turtleY+62);
// draw the top flapper underneath the body and head
beginShape();
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+128, turtleY+21);
curveVertex (turtleX+138, turtleY-8);
curveVertex (turtleX+115, turtleY-30);
curveVertex (turtleX+125, turtleY-15);
curveVertex (turtleX+113, turtleY+7);
curveVertex (turtleX+113, turtleY+7);
endShape(CLOSE);
// draw the bottom flapper underneath the body and head
beginShape();
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+136, turtleY+27);
curveVertex (turtleX+138, turtleY+42);
curveVertex (turtleX+130, turtleY+60);
curveVertex (turtleX+118, turtleY+85);
curveVertex (turtleX+119, turtleY+86);
curveVertex (turtleX+115, turtleY+78);
curveVertex (turtleX+124, turtleY+25);
curveVertex (turtleX+124, turtleY+25);
endShape(CLOSE);
// draw the body of the turtle with 11 curveVertices points
beginShape ();
//end of the turtle's tail
curveVertex (turtleX, turtleY+30);
curveVertex (turtleX, turtleY+30);
//top of turtle
curveVertex (turtleX+12, turtleY+20);
curveVertex (turtleX+50, turtleY+8);
curveVertex (turtleX+118, turtleY);
// head of turtle and twist in the turtle's neck
curveVertex (turtleX+152, turtleY+30);
curveVertex (turtleX+166, turtleY+8);
curveVertex (turtleX+146, turtleY+10);
//bottom of turtle
curveVertex (turtleX+126, turtleY+40);
curveVertex (turtleX+80, turtleY+52);
curveVertex (turtleX+20, turtleY+35);
// part of turtle's tail that connects to its end
curveVertex (turtleX+12, turtleY+25);
curveVertex (turtleX+12, turtleY+25);
endShape(CLOSE);
// draw the eye and the smile of the turtle
fill(232, 221, 7);
ellipse (turtleX+158, turtleY+14, 2, 2);
noStroke();
fill(93, 9, 0);
arc(turtleX+156, turtleY+24, 6, 6, QUARTER_PI, PI+QUARTER_PI);
}
END OF CODE #1
BEGINNING OF CODE #2 (the turtle to be animated)
/* Turtle animation */
void setup() {
size(1200, 800); // set the canvas size at 1200 pixels by 800 pixels
background(0, 170, 250); // set background color to the watery shade of blue
}
void draw() {
background(0, 170, 250); // recall the background color in setup during draw
turtle (width/4, height/2); // draw the turtle
}
// Define the turtle procedure as a method in its own section
void turtle (float turtleX, float turtleY) { // create the turtle method
// assign parameters for the color and stroke of the solid turtle figure
fill (114, 188, 19); // set color of solid figure to a turtle-like green
smooth(); // set anti-aliased edges for the solid turtle figure
strokeWeight (3); // set the thickness of the stroke that delineated the solid turtle figure
//draw the rear legs of the turtle with triangle
triangle (turtleX+28, turtleY+18, turtleX+40, turtleY+10, turtleX, turtleY+4);
triangle (turtleX+28, turtleY+18, turtleX+22, turtleY+52, turtleX+52, turtleY+62);
// draw the top flapper underneath the body and head
beginShape();
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+122, turtleY+25);
curveVertex (turtleX+128, turtleY+21);
curveVertex (turtleX+138, turtleY-8);
curveVertex (turtleX+115, turtleY-30);
curveVertex (turtleX+125, turtleY-15);
curveVertex (turtleX+113, turtleY+7);
curveVertex (turtleX+113, turtleY+7);
endShape(CLOSE);
// draw the bottom flapper underneath the body and head
beginShape();
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+131, turtleY+23);
curveVertex (turtleX+136, turtleY+27);
curveVertex (turtleX+138, turtleY+42);
curveVertex (turtleX+130, turtleY+60);
curveVertex (turtleX+118, turtleY+85);
curveVertex (turtleX+119, turtleY+86);
curveVertex (turtleX+115, turtleY+78);
curveVertex (turtleX+124, turtleY+25);
curveVertex (turtleX+124, turtleY+25);
endShape(CLOSE);
// draw the body of the turtle with 11 curveVertices points
beginShape ();
//end of the turtle's tail
curveVertex (turtleX, turtleY+30);
curveVertex (turtleX, turtleY+30);
//top of turtle
curveVertex (turtleX+12, turtleY+20);
curveVertex (turtleX+50, turtleY+8);
curveVertex (turtleX+118, turtleY);
// head of turtle and twist in the turtle's neck
curveVertex (turtleX+152, turtleY+30);
curveVertex (turtleX+166, turtleY+8);
curveVertex (turtleX+146, turtleY+10);
//bottom of turtle
curveVertex (turtleX+126, turtleY+40);
curveVertex (turtleX+80, turtleY+52);
curveVertex (turtleX+20, turtleY+35);
// part of turtle's tail that connects to its end
curveVertex (turtleX+12, turtleY+25);
curveVertex (turtleX+12, turtleY+25);
endShape(CLOSE);
// draw the eye and the smile of the turtle
fill(232, 221, 7);
ellipse (turtleX+158, turtleY+14, 2, 2);
noStroke();
fill(93, 9, 0);
arc(turtleX+156, turtleY+24, 6, 6, QUARTER_PI, PI+QUARTER_PI);
}
END OF CODE #2
1