Code
Light the First Pixel
Every picture on a screen is made of tiny coloured squares called pixels. PyQuest has a pixel canvas you can paint with Python!
from pyquest import Canvas
c = Canvas(8, 8, background="night")
c.set(3, 1, "gold")
c.rect(2, 2, 4, 3, "orange")
c.show()
Canvas(8, 8, ...)makes a grid 8 pixels wide and 8 tall.- Every pixel has an address
(x, y).xcounts columns from the left.ycounts rows from the top. Both start at 0, so the top-left pixel is(0, 0). c.set(x, y, color)paints one pixel.c.rect(x, y, width, height, color)paints a filled rectangle whose top-left corner is(x, y).c.show()puts the picture on screen.
Colours can be names like "gold", "orange", "brown",
"sky" and "grass", or hex codes like "#ff8800".
Pip tip: Painting the same pixel twice is fine. The last colour wins, just like real paint.
Assignment
Paint the Guild's first lantern on the 8 × 8 night canvas c:
- Paint two
"gold"flame pixels at(3, 1)and(4, 1)withc.set. - Paint the
"orange"body:c.rect(2, 2, 4, 4, "orange"). - Paint a
"brown"base withc.rect: top-left at(1, 6), 6 wide and 1 tall. - Keep the
c.show()at the end.
Paint the Guild's first lantern on the 8 × 8 night canvas c:
- Paint two
"gold"flame pixels at(3, 1)and(4, 1)withc.set. - Paint the
"orange"body:c.rect(2, 2, 4, 4, "orange"). - Paint a
"brown"base withc.rect: top-left at(1, 6), 6 wide and 1 tall. - Keep the
c.show()at the end.
main.py Python sleeping
Press Run to try your code, then Check to test it.