Difference between revisions of "W1502 Object Attributes"
(Updated formatting) |
|||
Line 3: | Line 3: | ||
= Research = | = Research = | ||
* Predefined color names may be found here: [https://www.w3.org/wiki/CSS/Properties/color/keywords CSS Color Keywords], or, colors may be created by their RGB values using the constructor Color(red:UInt8, green:UInt8, blue:UInt8) | * Predefined color names may be found here: [https://www.w3.org/wiki/CSS/Properties/color/keywords CSS Color Keywords], or, colors may be created by their RGB values using the constructor: | ||
<syntaxhighlight lang="swift"> | |||
Color(red:UInt8, green:UInt8, blue:UInt8) | |||
</syntaxhighlight> | |||
= Experiment = | = Experiment = | ||
Line 23: | Line 26: | ||
let rectangle = Rectangle(rect:rect) | let rectangle = Rectangle(rect:rect) | ||
let fillStyle = FillStyle(color:Color(.blue)) | let fillStyle = FillStyle(color:Color(.blue)) | ||
canvas. | canvas.render(fillStyle) | ||
canvas. | canvas.render(rectangle) | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Remember to save the file, then suspend emacs. | |||
. | {{RunProgram|Run the program and refresh the browser page.}} | ||
{{StopProgram|Stop the running program.}} | |||
Let's stroke the rectangle in green instead of filling it. Interrupt the running program and then resume emacs and edit the setup function so it appears as follows: | Let's stroke the rectangle in green instead of filling it. Interrupt the running program and then resume emacs and edit the setup function so it appears as follows: | ||
Line 41: | Line 43: | ||
let rectangle = Rectangle(rect:rect, fillMode:.stroke) | let rectangle = Rectangle(rect:rect, fillMode:.stroke) | ||
let strokeStyle = StrokeStyle(color:Color(.green)) | let strokeStyle = StrokeStyle(color:Color(.green)) | ||
canvas. | canvas.render(strokeStyle) | ||
canvas. | canvas.render(rectangle) | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Remember to save the file, then suspend emacs. | |||
. | {{RunProgram|Run the program and refresh the browser page.}} | ||
{{StopProgram|Stop the running program.}} | |||
Let's thicken the stroke line. Interrupt the running program and then resume emacs and add the following lines so that the entire function appears as: | Let's thicken the stroke line. Interrupt the running program and then resume emacs and add the following lines so that the entire function appears as: | ||
Line 60: | Line 61: | ||
let strokeStyle = StrokeStyle(color:Color(.green)) | let strokeStyle = StrokeStyle(color:Color(.green)) | ||
let lineWidth = LineWidth(width:5) | let lineWidth = LineWidth(width:5) | ||
canvas. | canvas.render(strokeStyle) | ||
canvas. | canvas.render(lineWidth) | ||
canvas. | canvas.render(rectangle) | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Remember to save the file, then suspend emacs. | |||
. | {{RunProgram|Run the program and refresh the browser page.}} | ||
{{StopProgram|Stop the running program.}} | |||
Finally, let's both stroke and fill simultaneously. Interrupt the running program and then resume emacs and add the following lines so that the entire function appears as: | Finally, let's both stroke and fill simultaneously. Interrupt the running program and then resume emacs and add the following lines so that the entire function appears as: | ||
Line 81: | Line 81: | ||
let strokeStyle = StrokeStyle(color:Color(.blue)) | let strokeStyle = StrokeStyle(color:Color(.blue)) | ||
let lineWidth = LineWidth(width:5) | let lineWidth = LineWidth(width:5) | ||
canvas. | canvas.render(fillStyle) | ||
canvas. | canvas.render(strokeStyle) | ||
canvas. | canvas.render(lineWidth) | ||
canvas. | canvas.render(rectangle) | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Remember to save the file, then suspend emacs. | |||
. | {{RunProgram|Run the program and refresh the browser page.}} | ||
{{StopProgram|Stop the running program.}} | |||
== Exercises == | == Exercises == | ||
{{Exercises| | |||
Continuing your previous project of (at least) three skyscrapers: | Continuing your previous project of (at least) three skyscrapers: | ||
# Color the sky and ground | # Color the sky and ground | ||
Line 102: | Line 102: | ||
When done, you must have at least seven different colors on your canvas. | When done, you must have at least seven different colors on your canvas. | ||
}} |
Revision as of 23:49, 5 December 2019
Prerequisites[edit]
Research[edit]
- Predefined color names may be found here: CSS Color Keywords, or, colors may be created by their RGB values using the constructor:
Color(red:UInt8, green:UInt8, blue:UInt8)
Experiment[edit]
Enter into the Sources/IgisShellD directory of the W1501 experience.
cd ~/Experiences/W1501/Sources/IgisShellD
Open main.swift in emacs.
emacs main.swift
Find the function within the Painter object named "setup". Edit the contents as follows to specify the fill color of the rectangle:
func setup(canvas:Canvas) {
let rect = Rect(topLeft:Point(x:100, y:50), size:Size(width:200, height:300))
let rectangle = Rectangle(rect:rect)
let fillStyle = FillStyle(color:Color(.blue))
canvas.render(fillStyle)
canvas.render(rectangle)
}
Remember to save the file, then suspend emacs.
Run the program and refresh the browser page. |
Stop the running program. |
Let's stroke the rectangle in green instead of filling it. Interrupt the running program and then resume emacs and edit the setup function so it appears as follows:
func setup(canvas:Canvas) {
let rect = Rect(topLeft:Point(x:100, y:50), size:Size(width:200, height:300))
let rectangle = Rectangle(rect:rect, fillMode:.stroke)
let strokeStyle = StrokeStyle(color:Color(.green))
canvas.render(strokeStyle)
canvas.render(rectangle)
}
Remember to save the file, then suspend emacs.
Run the program and refresh the browser page. |
Stop the running program. |
Let's thicken the stroke line. Interrupt the running program and then resume emacs and add the following lines so that the entire function appears as:
func setup(canvas:Canvas) {
let rect = Rect(topLeft:Point(x:100, y:50), size:Size(width:200, height:300))
let rectangle = Rectangle(rect:rect, fillMode:.stroke)
let strokeStyle = StrokeStyle(color:Color(.green))
let lineWidth = LineWidth(width:5)
canvas.render(strokeStyle)
canvas.render(lineWidth)
canvas.render(rectangle)
}
Remember to save the file, then suspend emacs.
Run the program and refresh the browser page. |
Stop the running program. |
Finally, let's both stroke and fill simultaneously. Interrupt the running program and then resume emacs and add the following lines so that the entire function appears as:
func setup(canvas:Canvas) {
let rect = Rect(topLeft:Point(x:100, y:50), size:Size(width:200, height:300))
let rectangle = Rectangle(rect:rect, fillMode:.fillAndStroke)
let fillStyle = FillStyle(color:Color(.green))
let strokeStyle = StrokeStyle(color:Color(.blue))
let lineWidth = LineWidth(width:5)
canvas.render(fillStyle)
canvas.render(strokeStyle)
canvas.render(lineWidth)
canvas.render(rectangle)
}
Remember to save the file, then suspend emacs.
Run the program and refresh the browser page. |
Stop the running program. |
Exercises[edit]
Continuing your previous project of (at least) three skyscrapers:
- Color the sky and ground
- Color the body of each skyscraper in a different color
- Color various aspects of your skyscraper (e.g. windows, doors) in different colors
When done, you must have at least seven different colors on your canvas.