This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-07-17 12:24:17

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

cos and sin made so easy it is Loco!!

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!  smile  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)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#2 2010-07-17 12:29:44

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: cos and sin made so easy it is Loco!!

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  big_smile

Offline

 

#3 2010-07-17 12:34:09

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: cos and sin made so easy it is Loco!!

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  smile

Last edited by archmage (2010-07-17 12:34:36)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#4 2010-07-17 13:24:08

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: cos and sin made so easy it is Loco!!

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!


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#5 2010-07-17 13:32:49

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: cos and sin made so easy it is Loco!!

OMG THANK YOU! THANK YOU! THANK YOU!

(thank you x3)


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#6 2010-07-17 13:50:39

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: cos and sin made so easy it is Loco!!

Not necessary Sunrise-Moon but thanks  smile  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)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#7 2010-07-17 14:10:42

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: cos and sin made so easy it is Loco!!

Locomule wrote:

Not necessary Sunrise-Moon but thanks  smile  Love your animated sig btw!!

Thanks  smile . Could you do a tangent tutorial soon?


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#8 2010-07-17 15:04:53

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: cos and sin made so easy it is Loco!!

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)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#9 2010-07-17 16:48:02

jman13
Scratcher
Registered: 2009-12-09
Posts: 65

Re: cos and sin made so easy it is Loco!!

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!  smile  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

 

#10 2010-07-17 18:20:23

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: cos and sin made so easy it is Loco!!

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.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#11 2010-07-18 05:23:09

orangeoz
Scratcher
Registered: 2010-02-18
Posts: 100+

Re: cos and sin made so easy it is Loco!!

Thanks So Much This Really Helps!!!!!!!!!!!!!!!


http://i1187.photobucket.com/albums/z393/OrangeOz/orangeozsig.png

Offline

 

#12 2010-07-18 08:21:05

HD123
Scratcher
Registered: 2009-12-05
Posts: 500+

Re: cos and sin made so easy it is Loco!!

thanks a lot I want to look at other trig functions now


~~HD123~~
Treat others as you want to be treated. |  big_smile  | http://i.imgur.com/OaNrY.gif | http://blocks.scratchr.org/libstatus.php?user=HD123&online=http://lemonfanatic.webs.com/ONLINE.png&offline=http://lemonfanatic.webs.com/OFFLINE.png

Offline

 

#13 2010-07-18 08:22:48

HD123
Scratcher
Registered: 2009-12-05
Posts: 500+

Re: cos and sin made so easy it is Loco!!

you have inspired me


~~HD123~~
Treat others as you want to be treated. |  big_smile  | http://i.imgur.com/OaNrY.gif | http://blocks.scratchr.org/libstatus.php?user=HD123&online=http://lemonfanatic.webs.com/ONLINE.png&offline=http://lemonfanatic.webs.com/OFFLINE.png

Offline

 

#14 2010-07-18 10:48:17

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: cos and sin made so easy it is Loco!!

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.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#15 2010-07-18 17:53:16

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: cos and sin made so easy it is Loco!!

pssst, here it is


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer