Skip to content

Commit

Permalink
turtle color matches pen color
Browse files Browse the repository at this point in the history
  • Loading branch information
ToonTalk committed Nov 14, 2024
1 parent 2caa8b4 commit fdb62ba
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion apps/learn-javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>A JavaScript Playground</h1>
<!-- Simple Turtle SVG -->
<svg id="turtle-svg" viewBox="0 0 100 100">
<!-- Triangle pointing upward by default -->
<polygon points="50,15 85,85 15,85" fill="green" />
<polygon id="turtle-body" points="50,15 85,85 15,85" fill="green" />
</svg>
</div>

Expand All @@ -92,6 +92,7 @@ <h1>A JavaScript Playground</h1>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const turtleSVG = document.getElementById('turtle-svg');
const turtleBody = document.getElementById('turtle-body'); // Reference to the triangle element
let turtle = {
x: canvas.width / 2,
y: canvas.height / 2,
Expand Down Expand Up @@ -125,6 +126,7 @@ <h1>A JavaScript Playground</h1>
},
setcolor: function(color) {
this.color = color;
turtleBody.setAttribute("fill", color); // Update the turtle color
},
reset: function() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
Expand All @@ -133,6 +135,7 @@ <h1>A JavaScript Playground</h1>
this.angle = 270; // Reset to facing north (upwards)
this.penDown = true;
this.color = '#000';
turtleBody.setAttribute("fill", this.color); // Reset the turtle color
updateTurtlePosition();
}
};
Expand Down

0 comments on commit fdb62ba

Please sign in to comment.