W1503 Lines and Ellipses
Prerequisites[edit]
Research[edit]
- Examine the back of a dollar bill. Note the pyramid on the left-hand side.
Prepare[edit]
Create a new Scenes shell project within your Experiences directory:
Enter the Sources/ScenesShell directory of the new project:
![]() |
Run the program.
ty-cam@codermerlin:~/Experiences/W1503/Sources/ScenesShell$ run
|
Open a browser (or use a new tab on an already-open browser). Then, go to the URL: https://www.codermerlin.com/igis/user-name/
![]() |
Caution |
|
You'll know you're successful if you see the title bar change to "Coder Merlin: IGIS". (The browser window will be blank because we haven't added any graphics yet.)
![]() |
Helpful Hint |
It's useful to bookmark this page in your browser. |
Experiment[edit]
![]() |
Stop the running program.
Return to the console and press CONTROL-C |
Render a Line[edit]
Open the file Background.swift in emacs.
Add a new method (below init) as follows:
override func setup(canvasSize:Size, canvas:Canvas) {
let lineWidth = LineWidth(width:3)
canvas.render(lineWidth)
let blue = StrokeStyle(color:Color(red:100, green:100, blue:255))
canvas.render(blue)
let lines = Lines(from:Point(x:110, y:150), to:Point(x:200, y:150))
canvas.render(lines)
}
Remember to save the file, then suspend emacs.
![]() |
Helpful Hint |
An online tool to determine color values is available here. Use the RGB values in the following constructor to generate any custom color: Color(red:UInt8, green:UInt8, blue:UInt8)
|
![]() |
Run the program and refresh the browser page. |
![]() |
Observe, Ponder, and Journal : Section 1 |
|
![]() |
Stop the running program. |
Render a Triangle[edit]
Resume emacs and edit the setup function so it appears as follows:
1 override func setup(canvasSize:Size, canvas:Canvas) {
2 let lineWidth = LineWidth(width:3)
3 canvas.render(lineWidth)
4
5 let blue = StrokeStyle(color:Color(red:100, green:100, blue:255))
6 canvas.render(blue)
7
8 let lines = Lines(from:Point(x:110, y:150), to:Point(x:200, y:150))
9 lines.lineTo(Point(x:155, y:250))
10 lines.lineTo(Point(x:110, y:150))
11 canvas.render(lines)
12 }
![]() |
Run the program and refresh the browser page. |
![]() |
Observe, Ponder, and Journal : Section 2 |
|
![]() |
Stop the running program. |
Circumscribe the Triangle with an Ellipse[edit]
Resume emacs and add the following lines so that the entire function appears as:
1 override func setup(canvasSize:Size, canvas:Canvas) {
2 let lineWidth = LineWidth(width:3)
3 canvas.render(lineWidth)
4
5 let blue = StrokeStyle(color:Color(red:100, green:100, blue:255))
6 canvas.render(blue)
7
8 let lines = Lines(from:Point(x:110, y:150), to:Point(x:200, y:150))
9 lines.lineTo(Point(x:155, y:250))
10 lines.lineTo(Point(x:110, y:150))
11 canvas.render(lines)
12
13 let violet = StrokeStyle(color:Color(.blueviolet))
14 canvas.render(violet)
15
16 let ellipse = Ellipse(center:Point(x:155, y:200), radiusX:120, radiusY:55)
17 canvas.render(ellipse)
18 }
![]() |
Observe, Ponder, and Journal : Section 3 |
|
Exercises[edit]
![]() |
Exercises |
|