Archive of ‘Uncategorized’ category

Winter Themed Artwork

My winter-themed artwork is interactive. It gives you a choice to pick from a Christmas themed artwork (spoiler: there is no Christmas artwork) or a New Year themed one (picture shown above). After that, it gives you a choice to draw it or make the computer draw it.

This is the first part of my code. It starts by just importing the random library and the turtle library. After that it asks you which holiday you want. If you choose Christmas it says, “Aww. you already want Christmas,” and then it asks you if you want to draw it or should the computer draw it. If you pick you can draw it, it says Too bad Christmas is done then it feels “guilty” and asks if you still want a picture. If you say yes, it says fine I’ll give you something better than a tree and draws the picture I first showed you (I’ll get to the code for that later).

This part is what happens if you say, “I will draw it.” The same code is used later again. The whole code for this part is in a loop since I don’t know how many times you want to turn or go forward. First, it has an input and asks if you want to go forward, turn right, or turn left. If you choose forward then it asks how much forward do you want to go. If you choose right then it asks how much you want to turn the same for left. After it goes through these if-then statements it asks if you are done yet. If you are, it says it’s so good. If you say no it moves forward a little and continues.

The next part of my code is what happens if you choose New Year. So if you picked New Year, it says the countdown and then asks if you want to draw it or should I, like last time. You already know what happens if you choose I’ll draw it so I won’t explain that again.

Here is the code for the fireworks. It appears if you choose that Christmas one and New Year (Fireworks work for both… I think). It first turns the background black and sets the speed of the turtle high so it goes fast. Then in a loop, it chooses a random integer for x and y then it pulls the pen up and moves to the coordinates it chooses. After it puts the pen down and chooses a random color and size (How much forward should the turtle go). Then it has another loop that goes forward, backward, then turns a little (this makes the actual fireworks). It makes five fireworks then stops.

I think the one thing that was hard for me during this project was making the code that allows you to draw. Otherwise, it was really fun. Also, I was in India when the class did this and I did not attend class so I had to make the code for this really fast. But I am really happy with what it is right now.

Turtle Maze

I did not get so far for this assignment because I was stuck after the first two lines. I probably could do it by bouncing of the walls of the maze but I wanted to challenge myself a little more.

The turtle maze challenge is where you have to get the turtle to go through the maze without crossing any lines. The thing is that the maze always changes. I got through the first two lines and had trouble with the rest.

How far I got

As you can see from the picture above, I got as far as the first two lines and then I could turn but that was it. I had a lot of trouble coming up with the code for the next parts.

This is my code (There are some other parts that are not my code that create the maze in the beginning). My code first starts with the turtle going forward randomr [i] + randomt [i]/2 (this is the first part of the list and it is a part of the code in the beginning, randomr is how far the first line of the maze goes, randomt is 800-randomr/2). It goes this forward because it has to go past randomr and half of the randomt mainly because randomt is repeated twice. The first time randomt is not seen (this forms the opening), the second time finishes of the first line of the maze. Then I make the turtle turn right because no matter what the turtle has to turn right in order for it to go straight into the maze. Next, the turtle goes forward 50 making it enter the maze. Then it has an if-then statement asking if randomr is greater than randomt. If it is then the turtle turns right because after it can go forward to the right to the opening. If it is not it has another if-then statement saying the exact opposite making it turn left. After it has another if-then statement, telling it how much much to go forward. After that is another if-then statement that determines which way to turn like the first two if-then statements. Then finally is a command that makes the turtle go forward. Next is another if-then statement that determines which way to go. That was all of the code I got to do and figured out.

I think what was really hard for me was figuring how much to go in front based on the turtle’s coordinates. Otherwise, it was a really fun project for me.

Turtle Race

My turtle race has two different races within it. The top one in the picture above is a race between a dog (square) and a cat (triangle). The bottom one is based on the story, “The Turtle and The Hare.” The race also features text in the box below.

The code first starts by setting up the characters and the board. As always the first two lines of code import different libraries (turtle and the random library). Next, I named different turtles so I could control the characters. Then, I gave different speeds to them all. The dog got a speed of 5, the cat got a speed of 2, the hare got a speed of 10, while the turtle got a speed of 1. Unfair right? After, I made the person set up the race board at a speed of 100. I changed the shape and the colors of the characters. In my code (but not in the picture of the code above) I also have code to position the characters) and that’s basically the first part of my code.

The first race

The second part of my race is the cat and the dog race. It starts with it printing, “Race one at ready,” then it prints 3, 2, 1… go in the text place under the race board. Then, in a repeat loop, I coded it to make the dog go forward a random integer from 3 to 5 then the cat goes a random integer from 2 to 5. The loop breaks if either the dog or cat passes the finish line. If one of them does, it says something like (*insert character who wins) wins RACE #1.

The third part of my code is the Turtle and the Hare race. This part follows the plot of the actual story. Like the other one, it starts with the text Race Two at Ready then it says 3,2,1, Go. Next, it starts with the regular loop where the turtle goes forward 2 while the hare goes forward a random number between 2 and 5. But this time, when the hare reaches x coordinate, 0, the loop breaks and it prints the text: Hare: ZZZ. Then the turtle moves forward 2 until it reaches the finish line and the loop breaks. Then it prints: “Turtle wins RACE 2”, “Referee: Ha, I guess the turtle was right… slow and steady does win the race”, “3 hours later…” After that text, the hare starts going forward until the finish line and figures out that he lost and yells no.

Race #2

I had a lot of fun doing this, I got to experience doing it the regular way and recreating a story using coding. The only thing that was hard was figuring out how to break the loops when the hare reaches a certain point and when the race ends. The text part was just extra but I am glad I added that, it mad the races so much more real.

About Me

My name is Sanvi, usually, I will post about CSAI but this post is for you to understand me. I like the color aqua and I like dogs. I have a dog named Spyro and he’s an Australian Labradoodle (He turns two in December). I also have a little sister named Sirah.

Picture of Spyro
Sirah’s in the corner

I like sports, math, choir, and art. I recently started Jui Jitsu which is a Brazilian martial art. It’s like wrestling and the best part of it, is you get to flip people over (Last time, I flipped my sister over multiple times). Here’s a video of what Jui Jitsu is.