EZ Math Movie, Tutorials, Simple Graphics, Drawing a Line Segment

Drawing a line segment

Here we will learn how to draw a line segment between two points. We will call the first point (x1, y1), and we will call the second point (x2, y2). Our new command:

drawLineSegment(x1, y1, x2, y2);

The following line of code would draw a line segment from point (3, 5) to point (6, 8):

drawLineSegment(3, 5, 6, 8);

We will use setupGraph, which sets the line thickness to 2 and it's color to black.

Line segment coordinates

Here is a picture that shows how the drawLineSegment command states the endpoint coordinates.

Line segment coordinates, (x1, y1) and (x2, y2)

drawLineSegment(-5, -3, 6, 4);

drawLineSegment(-5, -3, 6, 4)

Running the example program

Our example program shows how to use the drawLineSegment command to create a simple design.

The example program

Angle measurement: Degrees Radians

Go on input

Sorry, apparently this browser does not support HTML 5 canvas tag graphics.

Edit: Runtime          View: Starter Suggestion

To runtime:


Editor width: Normal Wide








Next tutorial: Drawing a rectangle


Here is a link to a related article at EZ Programing Demos:

Plotting a line

All contents of EZ Math Movie are copyrighted: Copyright 2011, Edward A. Zobel. All rights reserved.

Other sites you may find interesting

Zona Land Education Like Math and Physics?

Zona Land Education offers explanations, diagrams, and animations on these topics.
And it is all presented in a clear and casual manner.

Here is the link: zonalandeducation.com

EZ Programing Demos Want to learn about programing computers?

EZ Programing Demos has an animated, slow motion, interactive programing language demonstrator.
The site presents basic ideas at a beginner's level.

Here is the link: ezprogramingdemos.com

Custom Search