Lesson goal: Drawing lines with the mouse

Previous: Rescaling a result | Home | Next: Drawing circles with the mouse

In a previous lesson, you learned how to use the mouse() function to read the $(x,y)$ coordinate of a mouse click. Let's use this function and your newly found knowledge about how to draw lines to create a simple drawing program.

Since a line requires two points to draw between, say $(x_1,y_1)$ and $(x_2,y_2)$, let's write some code that makes two calls to the mouse() function. When run, you are to click on the drawing twice, once for each mouse() function call. After the second click, a line should appear between your two click points.

Now you try. Run this code several times, clicking on two points. Create a simple drawing!

Type your code here:


See your results here: