# Set the stage to a winter scene stage.set_background("winter2") # Add a black square that is half-opaque so that the # white snowflakes will be more visible tint = codesters.Square(0, 0, 500, "black") tint.set_opacity(0.5) # Disable the floor - otherwise the snow will bounce! stage.disable_floor() # Create an empty list to store the snowflakes snow = [] # Create 30 snowflakes # Using a list that we cycle through means the program stays # pretty fast, since we never have more than 30 sprites to deal with for counter in range(30): rand_num = random.randint(1, 3) x = random.randint(-250, 250) snowflake = codesters.Sprite("snowflake"+str(rand_num), x, 350) snowflake.set_size(random.randint(3, 7)/10) snowflake.set_y_speed(random.randint(-5, -1)) snow.append(snowflake) # This interval event cycles through all the snowflakes and checks if # they are off the stage. If they are, the snowflake is sent to # a random point at the top of the stage and resized, and set to a # new speed. This gives the appearance of new snow! def interval(): for snowflake in snow: if snowflake.get_y() < -250: snowflake.go_to(random.randint(-250, 250), 350) # This resets the snowflake to it's original size snowflake.set_size(1/snowflake.get_size()) # Then we set it to a new smaller size. If we didn't set it # to its orignal size first, the snowflake would get # too small and disappear after a while! snowflake.set_size(random.randint(3, 7)/10) snowflake.set_y_speed(random.randint(-5, -1)) # add any other actions... stage.event_interval(interval, .5) logo_backdrop = codesters.Circle(-150, -200, 90, "white") logo = codesters.Sprite("codesters",-150,-200) logo_title = codesters.Text("C O D E S T E R S", 50,-180, "white") logo_title.set_text_size(35) logo_sub = codesters.Text("Coding in Your Classroom", -90,-220, "white") logo_sub.set_text_size(25) logo_sub.set_text_align("left")