Computer Science
Grade 9
20 min
Drawing with Computers
Drawing with Computers
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Explain the difference between raster and vector graphics.
Describe how a Cartesian coordinate system is used to position objects on a digital canvas.
Use RGB color codes to define and apply colors to shapes.
Write code to draw primitive shapes like rectangles, circles, and lines at specific coordinates.
Combine multiple primitive shapes to create a more complex drawing, such as a simple house or character.
Debug common errors in their drawing code, such as incorrect coordinates or color settings.
Ever wondered how video game characters are drawn or how your favorite animated movies are made? 🎨 It all starts with telling a computer exactly where to put every single dot and line!
In this lesson, you'll learn the fundamental computer science concepts...
2
Key Concepts & Vocabulary
TermDefinitionExample
PixelThe smallest single point of color on a digital screen. Your entire screen is a giant grid of these tiny dots.A screen with a resolution of 1920x1080 has 1,920 pixels horizontally and 1,080 pixels vertically, for a total of over 2 million pixels.
Coordinate SystemA grid system used to define the position of any point on the screen. In most computer graphics, the point (0, 0) is at the top-left corner.To place a dot in the exact center of a 400x400 pixel canvas, you would use the coordinates (200, 200).
RGB Color ModelA method for creating colors by mixing different amounts of Red, Green, and Blue light. Each color component has a value, typically from 0 (none) to 255 (maximum).RGB(255, 0, 0) is pure red. RGB(0, 255, 0) is pure green. RGB(255, 255, 0) is yellow....
3
Core Syntax & Patterns
Drawing a Rectangle
drawRectangle(x, y, width, height)
Use this command to draw a rectangle. 'x' and 'y' are the coordinates of the top-left corner. 'width' and 'height' define its size in pixels.
Drawing a Circle
drawCircle(centerX, centerY, radius)
Use this command to draw a circle. 'centerX' and 'centerY' are the coordinates of the circle's center. 'radius' is the distance from the center to the edge.
Setting Fill Color
setFillColor(r, g, b)
Use this command *before* drawing a shape to set the color it will be filled with. 'r', 'g', and 'b' are the red, green, and blue values (0-255).
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
You are building the three-segment snowman on a 400x600 canvas. The bottom circle is `drawCircle(200, 500, 60)`. To make the middle circle sit perfectly on top of it with a radius of 40, what should its `drawCircle` command be?
A.drawCircle(200, 460, 40)
B.drawCircle(200, 400, 40)
C.drawCircle(200, 500, 40)
D.drawCircle(200, 440, 40)
Challenging
A programmer writes the following code, expecting a green square, but nothing appears on their white canvas. What is the critical error? `drawRectangle(50, 50, 100, 100); setFillColor(0, 255, 0);`
A.The `setFillColor` command was called after `drawRectangle`, so the rectangle was drawn with the default white color, making it invisible on the white background.
B.The RGB code for green is incorrect.
C.The rectangle's coordinates are off-screen.
D.The width and height are zero, so the rectangle has no size.
Challenging
You've drawn the base of a house with `drawRectangle(100, 200, 200, 150)`. You want to add a door that is 40 pixels wide and 70 pixels tall, centered at the bottom of the house. What is the correct `drawRectangle` command for the door?
A.drawRectangle(100, 280, 40, 70)
B.drawRectangle(200, 350, 40, 70)
C.drawRectangle(180, 280, 40, 70)
D.drawRectangle(180, 350, 40, 70)
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free