W2261 Paths
Prerequisites[edit]
Introduction[edit]
We're able to construct many graphic compositions using the tools that we've learned earlier; however, we'll need additional tools to build more complex shapes. Paths enable us to meet this need.
Complex Shapes Using Paths[edit]
Arbitrarily complex shapes may be constructed using Paths. Paths are built of primitives enabling us to add straight lines or curves. Programmatically, there are several steps to rendering a path:
- Create a new path
- Use primitives to add lines and curves to the path
- Render the path
![]() |
Helpful Hint |
Practice the below using the Igis Path Demo
Try it now in a separate window.
|
Adding Shapes Comprised of Straight Lines[edit]
To add a series of points forming one or more lines, we have the option to use two different primitives, moveTo and lineTo. Each of these primitives will update the current context position to the specified point.
- To move to a new position without drawing a line, we use the moveTo() method on a path.
- To draw a line to from the current context position to a new position we use the lineTo() method on a path.
![]() |
Open your browser to Igis Path Demo |
![]() |
Observe, Ponder, and Journal : Section 1 |
Use the moveTo(point:Point) and lineTo(point:Point) primitives to:
|
Adding Rectangles[edit]
Rather than use a moveTo() followed by four lineTo()s, we can create a rectangle with a single primitive, rect().
- This primitive ignores the current context position and begins drawing the rectangle at the specified position (topLeft), and then updates the current context position to the same point.
![]() |
Open your browser to Igis Path Demo |
![]() |
Observe, Ponder, and Journal : Section 2 |
Use the moveTo(point:Point),lineTo(point:Point), and rect(rect:Rect) primitives to:
|
Adding Curves[edit]
There a several primitives available which enable us to easily draw curves. Curves rely on one or more control points and flow along the existing path from the current context position to an end point. The end point may be explicitly specified or it may be calculated as part of the curve. There are four primitives for curves: quadratic curve, Beziér curve, arc, and arcTo.
Quadratic (Beziér) Curve[edit]
A quadratic curve is technically known as a quadratic Beziér curve. The quadratic curve flows from the current context position to an explicitly specified end point. A single control point serves to pull the curve toward itself. As a starting point, consider a control point located along a straight line from the current context position to the end point:
Observe what happens when we move the control point straight up:
Note that the curve did not move up to the control point, but only towards the control point. To better understand how the control point influences the curve, carefully observe this annotated version which includes green lines between the control point and the other points:
Note that the curve is tangent to the annotation line between the points moveTo and control and again between control and end. Carefully observe an alternative case:
We'll draw annotation lines between the points moveTo and control and again between control and end. We again see that the curve is tangent to both of these lines.
Here's an animated diagram demonstrating this curve:
(Cubic) Beziér Curve[edit]
A Beziér curve is technically known as a cubic Beziér curve. It's very similar to a quadratic Beziér curve but has an additional control point:
With additional control points, we're able to create more complex shapes. We're able to use both control points on the same side of the line:
But we're also able to use the control points on opposite sides of the line:
Here's an animated diagram demonstrating this curve:
![]() |
Open your browser to Igis Path Demo |
![]() |
Observe, Ponder, and Journal : Section 3 |
Use one or more of the moveTo(point:Point), quadraticCurveTo(controlPoint:Point, endPoint:Point) and bezierCurveTo(controlPoint1:Point, controlPoint2:Point, endPoint:Point) primitives to create the following shapes:
|
Arc[edit]
An arc flows from the current context position around an arc with the specified center and radius, beginning with the specified startAngle around to the specified endAngle. As an example, consider:
It's important to note that the end point is not explicitly specified but derived from the other parameters. Also, consistent with other angle specifications, angles are measured in radians from the 3 o'clock position clockwise.
ArcTo[edit]
The arcTo primitive flows from the current context position toward the first control point and then turns toward the second control point such that the specified radius of the arc is met.
Observe the annotated versions below and compare the different radii:
![]() |
Open your browser to Igis Path Demo |
![]() |
Observe, Ponder, and Journal : Section 4 |
Use one or more of the moveTo(point:Point), arc(center:Point, radius:Int, startAngle:Double, endAngle:Double, antiClockwise:Bool) and arc(center:Point, radius:Int, startAngle:Double, endAngle:Double, antiClockwise:Bool) primitives to create the following shapes:
|
Key Concepts[edit]
![]() |
Key Concepts |
|
Exercises[edit]
![]() |
Exercises |
Making use of your accumulated knowledge to date (both coding and graphics) and using only path primitives:
Getting started: john-williams@codermerlin:~/Projects$ git clone https://github.com/TheCoderMerlin/IgisShellD W2261
To compile: john-williams@codermerlin:~/Projects/W2261$ ./make.sh
To execute: john-williams@codermerlin:~/Projects/W2261$ ./run.sh
Your associated url will be: http://www.codermerlin.com/users/john-williams/dyn/index.html |