Merry Christmas

merry-christmasFor this challenge we are going to create Christmas Cards using Python turtle.

We will use the random library to create unique cards.

Starry Night


Our first card consists of creating a starry night scene.

This card is using:

  1. A function called draw_star() that takes five parameters: myPen, colour code, x position, y position and size of the star,
  2. Iteration: A for loop to create 15 stars,
  3. x and y coordinates to position the stars on the canvas,
  4. The random library, using the randint() function to randomly position the stars on the canvas.

(X,Y) Coordinates


The canvas we are drawing on (using Python Turtle) is 400 pixels wide by 400 pixels high.
Look at the canvas below to understand how (x,y) coordinates work:

Christmas Tree


Our second card consists of creating a Christmas Tree.

This card is using:

  1. A function called draw_rectangle() that takes six parameters: myPen, colour code, x position, y position, width and height of the rectangle,
  2. Iteration: A while loop to add more layers to the tree till we reach a thin enough top layer,
  3. x and y coordinates to position the rectangles on the canvas,
  4. The random library, using the randint() function to randomly set the width and height the rectangles on the canvas.

Tweak this card:
What’s about adding 20 snowflakes behind this tree, using the draw_circle() function.
Make sure the snowflakes are randomly positioned on the canvas.

Your Challenge


Your challenge consists of creating one of the following three Christmas cards:
xmas-cards

Make sure that your code uses:

  1. The randint() function from the random library to make sure each snowman, tree or hat is unique,
  2. A loop to reduce the number of instructions in your code.

Share Button
Posted in Computer Science, Python - Beginner, Python Challenges Tagged with: , ,

Our Latest Book