// Insptired by midpoints by Steve Phelps:
// geogebra.org/m/rqvdkvgk
// geogebra.org/m/m799zvtz
Log in to post a comment.
// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);
// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
turtle.goto(-50,-20);
turtle.pendown();
const aX = -85; // min=-95 max=95 step = 5
const aY = -85; // min=-95 max=95 step = 5
const bX = 85; // min=-95 max=95 step = 5
const bY = 85; // min=-95 max=95 step = 5
var cX = 0;
var cY = 0;
// Insptired by midpoints by Steve Phelps:
// https://www.geogebra.org/m/rqvdkvgk
// https://www.geogebra.org/m/m799zvtz
//todo add lables and equation on screen
drawCartesian();
// draw line
turtle.jump(aX,aY);
turtle.goto(bX,bY);
// add end points
centeredCircle(aX,aY, 2);
centeredCircle(bX,bY, 2);
calculateCenter(aX, aY, bX, bY)
function calculateCenter(ax, ay, bx, by){
var cx = (ax + bx)/2;
var cy = (ay + by) / 2;
centeredCircle(cx,cy, 2);
}
// draw Cartesian coordinates
function drawCartesian(){
// boundry
turtle.pendown();
turtle.jump(-95,-95);
for(var n=0; n<=4; n++){
turtle.forward(190);
turtle.right(90);
}
// X Axis
turtle.jump(-95,0);
turtle.seth(0)
turtle.forward(190);
// tick marks
turtle.jump(-95,0);
turtle.seth(0)
for(var n=0; n<=36; n++){
turtle.forward(5);
turtle.right(90);
turtle.forward(2);
turtle.back(4);
turtle.forward(2);
turtle.left(90);
}
// Y Axis
turtle.jump(0,-95);
turtle.seth(90)
turtle.forward(190);
// tick marks
turtle.jump(0,-95);
turtle.seth(90)
for(var n=0; n<=36; n++){
turtle.forward(5);
turtle.right(90);
turtle.forward(2);
turtle.back(4);
turtle.forward(2);
turtle.left(90);
}
}
// thanks to Reinder for this function
// Draws a circle centered a specific x,y location
// and returns the turtle to the original angle after it completes the circle.
function centeredCircle(x,y, radius, ext) {
turtle.penup();
turtle.goto(x,y);
turtle.backward(radius);
turtle.left(90);
turtle.pendown(); turtle.circle(radius, ext);
turtle.right(90); turtle.penup(); turtle.forward(radius); turtle.pendown();
}