Eyes on Me 123 · Year 7–8 Digital Technology · Student Edition

Draw with JavaScript

Khan Academy Drawing Basics & Colours · Three lessons

Lesson 1 / Drawing basics

Draw with coordinates

Position, size and drawing order

Learning intention

Use x and y coordinates and shape commands to build a picture.

Success criteria

  • I can predict where a rectangle or ellipse will appear.
  • I can use at least three kinds of shape commands.
  • I can explain what changed when I moved a command.

Do Now · 5 minutes

  1. On a 400 × 400 canvas, which is closer to the bottom: (60, 90) or (60, 300)?
  2. Which number changes to move a shape right without moving it down?
  3. Predict where the top-left corner of rect(40, 80, 120, 60) will be.

Code lab

Move a rectangle

Predict what the x slider will change. Test it. Then move the rectangle by changing y. Turn on the grid to check its top-left corner.

Code reference

Open a command to see what each part does.

rect(x, y, w, h)

Draws from its top-left corner. The last two numbers are width and height.

rect(40, 80, 120, 60);
ellipse(x, y, w, h)

Draws around its centre. Equal width and height make a circle.

ellipse(290, 130, 80, 80);
line(x1, y1, x2, y2)

Joins two points. Give the x and y of each end.

line(60, 260, 340, 260);
triangle(x1, y1, x2, y2, x3, y3)

Joins three corner points in order.

triangle(130, 330, 200, 270, 270, 330);
// comment

JavaScript skips text after // on that line. Use it to explain part of a picture.

// Draw the main shape

Try a worked example

Swap the first rectangle and the door line. Run it. What happened to the door, and why?

Predict first, then change the example and run it. Use the result to explain what the code did.

Choose a project

Choose one level. Meet all three requirements and test a change before you export.

Starter

Robot ID card

Design a friendly robot that would fit on an ID card.

  1. Draw a rectangular head and body, two matching ellipse eyes and a line mouth.
  2. Use at least two more shapes for arms, buttons or an antenna. Keep the drawing inside the canvas.
  3. Move the face feature you noticed first. Run both versions and describe the visible change.
Show a hint

Place one eye, then keep its y and size when you make the other eye.

Core

Reporoa bus stop

Draw a roadside scene with a shelter, a road and a bus.

  1. Use a rectangle for the shelter and a triangle for its roof. Add a post and a sign.
  2. Build a bus from a body, three windows and two ellipse wheels. Put the windows after the body so they show.
  3. Add road markings using lines. Use 12 or more drawing commands and check that the bus looks grounded.
Show a hint

Keep the two wheels at the same y, then use the grid to align the windows.

Advanced

Mini skatepark plan

Make a readable top-down layout with different zones.

  1. Include a ramp, bowl, rails, entry and seating using at least 16 drawing commands and all four shape types.
  2. Use the 200-pixel centreline to align a mirrored pair of features. Add a foreground detail that overlaps a larger shape on purpose.
  3. Write three comments marking the zones. Test swapping the draw order of an overlap and explain why you chose your final order.
Show a hint

For matching features, try centres at x = 100 and x = 300 with the same y value.

Code editor

400 × 400 canvas. The top left is (0, 0). The grid is a guide and stays out of exported images. Commands in this reference run here, including simple JavaScript loops.

Preview

Drafts autosave in this browser when available. Download a copy before changing devices. Use Ctrl/⌘ + Enter to run from the editor.

Exit ticket

Explain where ellipse(100, 240, 40, 60) is centred, then describe one change you tested.

For submission, turn in your code file, preview image and response file where your teacher has set the assignment.

Khan Academy: Intro to JS course · ProcessingJS documentation