Skip to content

Instantly share code, notes, and snippets.

@alexpelan
Created February 5, 2017 02:40
Show Gist options
  • Select an option

  • Save alexpelan/4f096adc064c23c2331c0c0cc5cf8752 to your computer and use it in GitHub Desktop.

Select an option

Save alexpelan/4f096adc064c23c2331c0c0cc5cf8752 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=4f096adc064c23c2331c0c0cc5cf8752
<!DOCTYPE html>
<html>
<head>
<title>Tiny Turtle</title>
<script src="https://toolness.github.io/tiny-turtle/tiny-turtle.js"></script>
</head>
<body>
<h1>Tiny Turtle</h1>
<canvas></canvas>
<button class="change-color">Change color</button>
</body>
</html>
{"enabledLibraries":["jquery"]}
// Tiny Turtle Setup. Avoid modifying these lines of code!
var adjCanvasSize = document.getElementsByTagName('canvas')[0];
adjCanvasSize.width = 400;
adjCanvasSize.height = 400;
TinyTurtle.apply(window);
// Start here
// 1. Define a variable named sideLength and set it to 90
// 2. This value for a right angle is wrong - fix it so the
// variable 'rightAngle' is equal to the number of degrees
// in a right angle.
var rightAngle = 100;
penStyle = 'red';
// 3. We want to draw a square. Finish this code that
// draws the first side of the square so we get a
// complete square. You should only use variables
// as arguments to the functions
forward(sideLength);
right(rightAngle);
// 4. Change the length of the side by doubling the value
// of the variable sideLength. Go back up to 1. and change
// the value.
// 5. This code changes the color of the square to blue
// when the button is clicked. Change the code so it
// changes the color to green instead.
$(".change-color").click(function() {
penStyle = "green";
});
// 6. YOU DO: Draw another shape with 5 or more sides.
// You can only pass variables as arguments - there should
// not be any numbers. The shape can look however you want
// it to - so you may need several variables.
// penUp() and penDown() may be helpful if you want to move
// the pen to your starting place. stamp() will be helpful for
// troubleshooting.
canvas {
border: 1px solid black;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment