Hello everyone!
This week we worked on creating holiday cards using Python turtles. I used coordinates extensively, along with while loops and the random library. I had to create 3 cards: a starry card, a Christmas tree, and one of my choice from this website, which was a snowman. This website also provided important starting codes, including defining functions to draw stars, rectangles, and circles. This was really helpful because I didn't have to go through the long detailed coding every time I wanted a filled in shape.
1. The first card that I made was a Christmas tree card. Here is the link: https://trinket.io/python/0d41eca6b7
The information website gave me the base for the code, including the trunk, randomly sized generated branches, a gold star at the top, and "Merry Christmas" at the bottom. I added randomly generated snowballs. Below is the code for the snowflakes:
Another thing that I learned was that you need to do the randomly placed objects FIRST, because they are apart of the background. I learned this because I had originally put it at the end, and the snowballs ended up covering my Christmas tree (which was not the effect I was going for).
This code was the easiest code, as it was only really 3 commands.
3. The last card that I made was a snowman card. Here is the link: https://trinket.io/python/0743cd2186
I really like experimenting with the colors of things. For snowman balls, I made them 'snow' colored, which I liked.
I had to create the 3 balls for the base of the snowman (which took a lot of experimenting), the black circle eyes, the buttons, and the mouth. The mouth was interesting to make, as I had to make a small red circle, and then a slightly larger snow colored circle to cover the majority of the red circle, to make it look like a smiling mouth. The hardest part was creating the small, thin, brown twig arms. Although they are simple rectangles, I had to heavily experiment with the angles that I had to move the turtle, so that the arms didn't look weird. Lastly, I added a simple black hat! Go look at my code to see what I mean!
I had to randomize something on this card (and I didn't know that the snowballs counted), so i randomized the black buttons on the snowman.
#draw 5 random black buttons
buttons = 0
while buttons < 6:
draw_circle(myPen, "black", 0, randint(-150, 30), 5)
buttons = buttons + 1
All in all, these were pretty easy and fun to do. I became more confident in the random function and while loops. I also liked experimenting with the colors.
I learned that the more snowflakes, the better it looks.
I want to learn how to restrict the range of the random function into something other than a square block of space (with simple x & y coordinate restrictions). For example, if I wanted to use the blue circular card (like the snowman), and I wanted to put random colored dots only on the blue circle. I got away with this this time because the snowballs were white, which were the same color as the background, so the snowballs on the background you can't see.
Below are screenshots of versions of my cards (as they all have randomized elements) and the links to their trinkets!
This week we worked on creating holiday cards using Python turtles. I used coordinates extensively, along with while loops and the random library. I had to create 3 cards: a starry card, a Christmas tree, and one of my choice from this website, which was a snowman. This website also provided important starting codes, including defining functions to draw stars, rectangles, and circles. This was really helpful because I didn't have to go through the long detailed coding every time I wanted a filled in shape.
1. The first card that I made was a Christmas tree card. Here is the link: https://trinket.io/python/0d41eca6b7
The information website gave me the base for the code, including the trunk, randomly sized generated branches, a gold star at the top, and "Merry Christmas" at the bottom. I added randomly generated snowballs. Below is the code for the snowflakes:
#add 20 snowflakes behind tree
snowflake = 0
while snowflake < 50:
draw_circle(myPen, "white", randint(-200,200), randint(-200,200), 4)
snowflake = snowflake + 1
I used this while loop for the rest of the cards, for creating more random snowballs or random stars or random dots. I now feel really comfortable using these, because I understand better how it works, like logically.
I also used the random function, randint. With this, you set a range that the computer can choose a point in that range. Through trial and error, I learned that you have to set a randint for both the x coordinate and the y coordinate, both ranging from -200 to 200. This allows for the snowballs (or stars or dots) to be randomly created all over the 400x400 pixel grid. At first I only did (0,200) for both x and y, and the snowballs were only in the first quadrant.
Another neat fact that I learned was that if you set the turtle speed to a big negative number (I did -500), then the turtle goes much much faster than if you set it to 0
2. The second card that I made was a starry card. Here is the link: https://trinket.io/python/f108dd85b1
For this one, I used the already defined 'draw_rectangle' function to make a black background. Then I used a while loop for stars, with stars = 0 to start. For each loop, I made it create a randomly placed red star and a randomly placed green star. I did this until stars = 20. I then used another while loop for dots, creating small white and gold dots. I then finished with the turtle write code, for it to write "Merry Christmas" in the middle in white.This code was the easiest code, as it was only really 3 commands.
3. The last card that I made was a snowman card. Here is the link: https://trinket.io/python/0743cd2186
I really like experimenting with the colors of things. For snowman balls, I made them 'snow' colored, which I liked.
I had to create the 3 balls for the base of the snowman (which took a lot of experimenting), the black circle eyes, the buttons, and the mouth. The mouth was interesting to make, as I had to make a small red circle, and then a slightly larger snow colored circle to cover the majority of the red circle, to make it look like a smiling mouth. The hardest part was creating the small, thin, brown twig arms. Although they are simple rectangles, I had to heavily experiment with the angles that I had to move the turtle, so that the arms didn't look weird. Lastly, I added a simple black hat! Go look at my code to see what I mean!
I had to randomize something on this card (and I didn't know that the snowballs counted), so i randomized the black buttons on the snowman.
#draw 5 random black buttons
buttons = 0
while buttons < 6:
draw_circle(myPen, "black", 0, randint(-150, 30), 5)
buttons = buttons + 1
All in all, these were pretty easy and fun to do. I became more confident in the random function and while loops. I also liked experimenting with the colors.
I learned that the more snowflakes, the better it looks.
I want to learn how to restrict the range of the random function into something other than a square block of space (with simple x & y coordinate restrictions). For example, if I wanted to use the blue circular card (like the snowman), and I wanted to put random colored dots only on the blue circle. I got away with this this time because the snowballs were white, which were the same color as the background, so the snowballs on the background you can't see.
Below are screenshots of versions of my cards (as they all have randomized elements) and the links to their trinkets!
Hope you had a great Thanksgiving, and I can't wait for Christmas break now!
-Mimi
Comments
Post a Comment