Sin and Cosine (or cos and sin in the script block) are simply curves. Yay! They are highly mystical and only for use by brilliant Scratchers, not!! The TINY amount of tinkering around below will get you acquainted with using them in minutes. Amaze your mother, win the envy of your peers...
make a new project, just use the cat sprite
make a new variable named oscillator
here is the script...
when green flag clicked
go to x:0 y:0
set oscillator to 0
repeat 360 times
change X by cos of oscillator
change oscillator by 1
Now run it and watch the cat move. Cool eh?
1) Did you notice the "360" repeat? There are 360 degrees in a circle. Hmmm?
2) Change that "360" repeat to a 180 and run it to see how the cat's motion changes. Try 90. Ahh.. so Cosine lets us move something in a circular motion! But you say, "Wait, that was just back and forth, not round?" Nope, it was round! Its just that we were looking directly at the side of the circle instead of looking down at it!!
But before we 'flip' it, lets use our current script again.
Set everything back to the very first script EXCEPT change the cos function to sin and run it.
What was different about the motion? What was the same?
Change the "360" repeats to "720" and run it. Did you think it was gonna do a circle again, what did it do instead?
________________________________________________________
So if you've had trouble before, forget the math of Cos and Sin and instead learn their mechanics in a Script. They are the OG tools for doing curves whether drawing or just moving sprites. Now lets rotate that lazy, sideways circle...
Reset your script again to the first version.
Add this block either just before or just after the "change X by cos of oscillator"...
change Y by sin of oscillator
run it
Hey, now our circle is standing up where we can see it! Wonder what you could do to make it an oval? What if you use 2 sines or 2 cosines? Try adjusting the "change oscillator by 1" to a different number. *note* if you want the cat to finish the circle where it started at, make sure that this number is always a factor/multiple of 3 such as 1, 1.5, 3, 6, 9, 15 etc, can be very important!
Peace and happy Scratching everyone!
Last edited by Locomule (2010-07-17 12:29:00)
Offline
This is great! So many people have been asking this question, it's great to have a definitive topic for it.
Maybe you could put instructions on how to make things like joints with it? That's probably the most widely used instance of the block. It's what I used to make my stickfigure animator
Offline
Actually, trig functions are useful in a variety of things but have much fewer practical applications in scratch. But for the purposes of scratch lets just say its only good for curvy lines and finding directions
Last edited by archmage (2010-07-17 12:34:36)
Offline
Yeah, I was just trying to make it simple, widely useful, and hands-on in a way that hopefully will encourage people to figure even more stuff out on their own by messing around under the hood. Thanks for the comments!
Offline
Not necessary Sunrise-Moon but thanks Love your animated sig btw!!
One day, many years ago, I was sitting around wondering what cos and sin do, cause I kept seeing them used in Basic programs. So I took a sheet of paper and wrote numbers in a column down the page, starting with one. Next I got a calculator and starting with one, I figured every number for both sin and cos and wrote the results beside the number. After a short while, you can figure out which numbers need to be figured cause only a few really do to see the pattern. Once you get the idea down, you can "see" the circular motion in the results.
Last edited by Locomule (2010-07-17 13:51:35)
Offline
Locomule wrote:
Not necessary Sunrise-Moon but thanks
Love your animated sig btw!!
Thanks . Could you do a tangent tutorial soon?
Offline
This doesn't really teach you about anything other than how to draw sin, cosine, and tan curves and they are all done in the same way.
If you want to learn how to use trig functions properly then try this link http://scratch.mit.edu/forums/viewtopic.php?id=5326
Last edited by archmage (2010-07-17 15:05:18)
Offline
Locomule wrote:
Sin and Cosine (or cos and sin in the script block) are simply curves. Yay! They are highly mystical and only for use by brilliant Scratchers, not!! The TINY amount of tinkering around below will get you acquainted with using them in minutes. Amaze your mother, win the envy of your peers...
make a new project, just use the cat sprite
make a new variable named oscillator
here is the script...
when green flag clicked
go to x:0 y:0
set oscillator to 0
repeat 360 times
change X by cos of oscillator
change oscillator by 1
Now run it and watch the cat move. Cool eh?
1) Did you notice the "360" repeat? There are 360 degrees in a circle. Hmmm?
2) Change that "360" repeat to a 180 and run it to see how the cat's motion changes. Try 90. Ahh.. so Cosine lets us move something in a circular motion! But you say, "Wait, that was just back and forth, not round?" Nope, it was round!Its just that we were looking directly at the side of the circle instead of looking down at it!!
But before we 'flip' it, lets use our current script again.
Set everything back to the very first script EXCEPT change the cos function to sin and run it.
What was different about the motion? What was the same?
Change the "360" repeats to "720" and run it. Did you think it was gonna do a circle again, what did it do instead?
_____________________________________________________________________________
So if you've had trouble before, forget the math of Cos and Sin and instead learn their mechanics in a Script. They are the OG tools for doing curves whether drawing or just moving sprites. Now lets rotate that lazy, sideways circle...
Reset your script again to the first version.
Add this block either just before or just after the "change X by cos of oscillator"...
change Y by sin of oscillator
run it
Hey, now our circle is standing up where we can see it! Wonder what you could do to make it an oval? What if you use 2 sines or 2 cosines? Try adjusting the "change oscillator by 1" to a different number. *note* if you want the cat to finish the circle where it started at, make sure that this number is always a factor/multiple of 3 such as 1, 1.5, 3, 6, 9, 15 etc, can be very important!
Peace and happy Scratching everyone!
cool!
Offline
Sorry, I got distracted, sorry? I am clueless on using Tangent in Scratch for anything except trig functions. So I would check out Archmage's suggestion. From what I have seen so far, like Archmage said in some post, the sensing functions available in Scratch such as Distance and Direction make it so you don't need the sin, cosine, and tangent functions as much. Hence my explanation of typical Scratch-related uses of sin and cos instead of explaining the math behind the functions.
What distracted me was the use of Tangents (the term not the Math function) to do collision detection around a convex polygon drawn by the user. I started working on a project for that and there went the day, lol. Will post it when finished.
Offline
Awesome, It worked on me too lol. I was up till 2:30am working on a new project that has math that is warping my mind.
Offline
pssst, here it is
Offline