3 Replies - 4264 Views - Last Post: 06 June 2019 - 06:00 PM Rate Topic: -----

#1 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 562
  • View blog
  • Posts: 1,798
  • Joined: 27-December 13

Christmas Card Coding Challenge

Post icon  Posted 23 November 2018 - 07:31 AM

Christmas Card Coding Challenge

This is the third and last Christmas Challenge that I have planned for 2018.

This challenge is not so much about coding skills as it is about creativity.

Write code that generates a Christmas Card.

The graphics can be
  • in the Console (ASCII picture), Turtle, using Pygame or the Graphics module or whatever you like.
  • The card can be a static picture or a dynamic animation.
  • The motif must have something to do with Christmas: Snow, Santa Claus, Reindeer, Christmas Threes, Gifts, etc.
  • The more stereotypical the better..!

The general rules:
• Python is the preferred language, but the challenge is open to all.
• Please comment the code/algorithm.
• There are no prizes, - it’s purely a friendly competition; hopefully with some learning…

Please upload both code and a screenshot.

Happy Christmas Coding.

Included is a small code for inspiration. This code has been used before; in my tutorials and in forum responses.
import pygame, random

X = 600
Y = 600

WHITE = (255, 255, 255)
BG = (128, 128, 255)

screen = pygame.display.set_mode((X, Y))

class Snow():
    def __init__(self):
        self.yPos = 1
        self.xPos = random.randint(2, X-2)
        self.radius = random.randint(2, 4)

    def fall(self):
        self.yPos += self.radius-1

    def draw(self):
        pygame.draw.circle(screen, WHITE, (self.xPos, self.yPos), self.radius, 0)

def gradient(y):
    return [int(color * (1 + y / Y) * 0.5) for color in BG]

# background with gradient
background = pygame.Surface((X, Y))
for y in range(Y):
    pygame.draw.line(background, gradient(y), (0, y), (X, y), 1)    

allSnow = []
run = True

while run:
    screen.blit(background, (0, 0))
    allSnow.append(Snow())  # make a new snowflake
    for snow in allSnow:
        if snow.yPos > Y:
            allSnow.remove(snow)  # remove at bottom of screen


    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False


Posted Image

Is This A Good Question/Topic? 1
  • +

Replies To: Christmas Card Coding Challenge

#2 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 797
  • Joined: 15-December 14

Re: Christmas Card Coding Challenge

Posted 27 November 2018 - 04:00 PM

This is my Christmas card for the challenge...

import pygame, random

black = (0, 0, 0)
white= (255, 255, 255)
green = (0, 255, 0)

size = (900, 700)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Christmas card 2018")
font = pygame.font.Font(None, 30)

snow_list = []

def Poem():
    txt = []
    poem = ["'Twas the night before Christmas, when all through the house",
            "Not a creature was stirring, not even a mouse;",
            "The stockings were hung by the chimney with care,",
            "In hopes that St. Nicholas soon would be there;",
            "The children were nestled all snug in their beds;",
            "While visions of sugar-plums danced in their heads;",
            "And mamma in her kerchief, and I in my cap,",
            "Had just settled our brains for a long winter's nap,",
            "When out on the lawn there arose such a clatter,",
            "I sprang from my bed to see what was the matter.",
            "Away to the window I flew like a flash,",
            "Tore open the shutters and threw up the sash.",
            "The moon on the breast of the new-fallen snow,",
            "Gave a lustre of midday to objects below,",
            "When what to my wondering eyes did appear,",
            "But a miniature sleigh and eight tiny rein-deer,",
            "With a little old driver so lively and quick,",
            "I knew in a moment he must be St. Nick.",
            "More rapid than eagles his coursers they came,",
            "And he whistled, and shouted, and called them by name:",
            "Now, Dasher! now, Dancer! now Prancer and Vixen!",
            "On, Comet! on, Cupid! on, Donner and Blitzen!",
            "To the top of the porch! to the top of the wall!",
            "Now dash away! dash away! dash away all!",
            "As leaves that before the wild hurricane fly,",
            "When they meet with an obstacle, mount to the sky;",
            "So up to the housetop the coursers they flew",
            "With the sleigh full of toys, and St. Nicholas too",
            "And then, in a twinkling, I heard on the roof",
            "The prancing and pawing of each little hoof.",
            "As I drew in my head, and was turning around,",
            "Down the chimney St. Nicholas came with a bound.",
            "He was dressed all in fur, from his head to his foot,",
            "And his clothes were all tarnished with ashes and soot;",
            "A bundle of toys he had flung on his back,",
            "And he looked like a pedler just opening his pack.",
            "His eyes how they twinkled! his dimples, how merry!",
            "His cheeks were like roses, his nose like a cherry!",
            "His droll little mouth was drawn up like a bow,",
            "And the beard on his chin was as white as the snow;",
            "The stump of a pipe he held tight in his teeth,",
            "And the smoke, it encircled his head like a wreath;",
            "He had a broad face and a little round belly",
            "That shook when he laughed, like a bowl full of jelly.",
            "He was chubby and plump, a right jolly old elf,",
            "And I laughed when I saw him, in spite of myself;",
            "A wink of his eye and a twist of his head",
            "Soon gave me to know I had nothing to dread;",
            "He spoke not a word, but went straight to his work,",
            "And filled all the stockings; then turned with a jerk,",
            "And laying his finger aside of his nose,",
            "And giving a nod, up the chimney he rose;",
            "He sprang to his sleigh, to his team gave a whistle,",
            "And away they all flew like the down of a thistle.",
            "But I heard him exclaim, ere he drove out of sight...",
            "'Happy Christmas to all, and to all a good night!'"
    return poem
recty = 750

def draw(recty):
    for i, v in enumerate(poem):
        text = font.render(v,True,green)
        screen.blit(text,[100,400 + recty + i * 40])
for i in range(50):
    x = random.randrange(0, 900)
    y = random.randrange(0, 700)
    snow_list.append([x, y])

poem = Poem()
clock = pygame.time.Clock()
done = False
clock = pygame.time.Clock()

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
    recty -=5
    for i in range(len(snow_list)):
        pygame.draw.circle(screen, white, snow_list[i], 2)
        snow_list[i][1] += 1
        if snow_list[i][1] > 700:
            y = random.randrange(-50, -10)
            snow_list[i][1] = y
            x = random.randrange(0, 900)
            snow_list[i][0] = x


Was This Post Helpful? 1
  • +
  • -

#3 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 797
  • Joined: 15-December 14

Re: Christmas Card Coding Challenge

Posted 22 April 2019 - 11:13 PM

I really enjoy your challenges. When you have time would you please make more challenges?.
Was This Post Helpful? 2
  • +
  • -

#4 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 562
  • View blog
  • Posts: 1,798
  • Joined: 27-December 13

Re: Christmas Card Coding Challenge

Posted 06 June 2019 - 06:00 PM

ok albert003, I just did - inspired by your post :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1