Using Sine and Cosine to Draw Ovals
In this tutorial, I will be showing you what all of the numbers mean when you put a sine or cosine block into your code, and how to use them. Without further ado -- here it is!
Today we will be making something like this -
Although the code may look complex at first, once you understand what all of the numbers do, it will seem (and be) easy!
Step 1. First we will put some code in telling the text object that will draw the oval where to go. This is super simple.
Then, add in a repeat 80 times block, and a draw a trail block. Set the color to anything, mine is just purple.
Don't worry about everything inside
the draw a trail block. Just replicate the repeat block with the draw a trail inside, and delete the move forward block.
Step 2. Now add a set position block inside the draw a trail block. Put the math operator called cosine (cos) in the X position slot, and sine (sin) in the Y slot. Now let's talk about what sine and cosine do. Take a look at this zoomed-in photo of the block inside the draw a trail block.
The third number in the X slot represents where the oval starts. I want mine to be in the middle, so I put 500 there. The first number is how wide the oval is going to be. I want my oval to be tall and skinny, so I set it to only 100. The second number has a variable in it.
Step 3. Let's talk about this variable. It increases by somewhere between 1 and 10 each repeat. Why does it have to increase? To keep the item that is creating the trail art moving. If you didn't change this, the object would just stay in the same spot!
Step 4. The same applies to the sine block. The first number is how tall your oval is, the second is the same variable, and the third is where on the Y axis the center of the oval will be. Below is a picture.
Step 5. Finally, put an increase variable block in, as shown in the photo below.
Now test it out. Try altering the numbers to see what happens! Have fun!
- Make a project using sine and cosine
- Figure out how to fill the center in my project here. You will need to tap the screen to get it to draw the oval.