The order of the text in a program changes the order that things happen.
The order is sometimes important. Putting on socks should normally be done before putting on shoes. Sometimes it is not as important. Putting on a shirt or pants can be done in either order.
The following example shows that the circle is drawn before the rectangle. You can think of this like first paint the circle, then paint the rectangle on top of the circle.
In the following code, anything after a '#' is ignored by the computer when running the code. It is only meant to explain the code for anyone that is reading it.
The examples here can be run with Jupyter notebooks. To instead use them from a Python editor, install open-cv, and replace the "%run" line with "from LibGraphics.Graphics import *"
%run -i 'initGraphics.py' # Initialize the graphics package
# Create a window that will show on the screen.
# The size is 200 width and 150 height.
window = CreateWindow(150, 150)
# Draw a circle at X=60, Y=40, radius=25
DrawCircle(window, 60, 40, 25, 'yellow')
# Rectangle
DrawRectangle(window, 60, 40, 100, 80, 'blue')
WaitForMouseClickAndCloseWindow(window)
The following example shows that the rectangle is drawn before the circle.
%run -i 'initGraphics.py' # Initialize the graphics package
# Create a window that will show on the screen.
# The size is 200 width and 150 height.
window = CreateWindow(150, 150)
# Rectangle
DrawRectangle(window, 60, 40, 100, 80, 'blue')
# Draw a circle at X=60, Y=40, radius=25
DrawCircle(window, 60, 40, 25, 'yellow')
WaitForMouseClickAndCloseWindow(window)
The following example shows that both the rectangle and circle where the order doesn't matter.
%run -i 'initGraphics.py' # Initialize the graphics package
# Create a window that will show on the screen.
# The size is 200 width and 150 height.
window = CreateWindow(150, 150)
# Draw a circle at X=60, Y=40, radius=25
DrawCircle(window, 40, 40, 25, 'yellow')
# Rectangle
DrawRectangle(window, 80, 40, 120, 80, 'blue')
WaitForMouseClickAndCloseWindow(window)
Sometimes the results of steps cannot be seen.
Putting on a shirt and then putting on another shirt may make the first shirt invisible.
The following example shows first a smaller green circle (20) is drawn, then a larger yellow circle (25) is drawn.
%run -i 'initGraphics.py' # Initialize the graphics package
# Create a window that will show on the screen.
# The size is 200 width and 150 height.
window = CreateWindow(150, 150)
# Draw a circle at X=60, Y=40, radius=20
DrawCircle(window, 40, 40, 20, 'green')
# Draw a circle at X=60, Y=40, radius=25
DrawCircle(window, 40, 40, 25, 'yellow')
# Rectangle
DrawRectangle(window, 80, 40, 120, 80, 'blue')
WaitForMouseClickAndCloseWindow(window)
Put a '#' before the second draw circle, and the first circle will show.
The '#' is special and means ignore everything on the line after it.
Like:
#DrawCircle(window, 40, 40, 25, 'yellow')