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

#1 2013-04-24 16:44:45

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Migrating Sprite

In Scratch, I am making a diagram of an atom. However, when one of the electrons, while rotating, hits an outer edge, it gets out of place compared to the other electrons. Here is the code:
when space key pressed
go to x 200 y 0
point in direction 0
forever
move 4 steps
turn counterclockwise 1 degrees
end forever

In an effort to stop the problem, I added this code:
when space key pressed
forever
if <touching edge ?>
hide
else
show
end if
end forever

However, the problem was still there. What can I do to fix it? Thanks in advance!

Offline

 

#2 2013-04-24 17:58:34

Pilplup
New Scratcher
Registered: 2013-04-22
Posts: 14

Re: Migrating Sprite

What you are asking is sort of confusing. What is it that you are asking for?

Offline

 

#3 2013-04-24 19:19:59

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

When an orbiting electron hits an edge, it goes forward or backward a little, not staying in line.

Offline

 

#4 2013-04-24 19:26:26

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: Migrating Sprite

Maybe make the path smaller so that it doesn't the edge?

Lower the amount of steps and increase the turn blocks so that it does not hit the edge nor the nucleus of the atom.  smile

Offline

 

#5 2013-04-24 21:12:01

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Migrating Sprite

mjcox2000 wrote:

When an orbiting electron hits an edge, it goes forward or backward a little, not staying in line.

Ah, I see. As laptop97 suggested, you can always make the orbit smaller, or you can go with other methods. Would it be okay with you if trigonometry is used? Also, is this by chance a school assignment? You don't have to answer; I'm just curious.

Anyway, hello mjcox2000 and welcome to Scratch! I wish you a smooth road to learning how to program!

With regards,

ErnieParke


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2013-04-25 07:15:44

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

The problem with making the orbit smaller is that I have to then change it for 36 other electrons.

Yes, this is a school project.

Offline

 

#7 2013-04-25 17:38:36

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Migrating Sprite

mjcox2000 wrote:

The problem with making the orbit smaller is that I have to then change it for 36 other electrons.

Yes, this is a school project.

Well then, I'm guessing this atom has 5 shells of electrons? I can't tell for sure because I've only been taught about the first three, though 5 should be around the ball-park.

Anyway, one last question. Are you comfortable working with parametric equations, or do you have no clue what they are?

With regards,

ErnieParke


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2013-04-25 17:46:35

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

No, it has 4 shells-- it is rubidium. If it is helpful, here is a link to the file: http://goo.gl/LHep3

I have no idea what parametric equations are, but I'll google them now.

Offline

 

#9 2013-04-25 17:55:38

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

Oops-- correction: it does have 5 shells. I'll have to take down the link and fix it.

Offline

 

#10 2013-04-25 18:04:47

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

Here: http://goo.gl/qgX5a

I added another shell, and am still facing the same problem.

Offline

 

#11 2013-04-25 18:47:45

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Migrating Sprite

mjcox2000 wrote:

Here: http://goo.gl/qgX5a

I added another shell, and am still facing the same problem.

Well, that's because sprites can't go offscreen, and so when you tell an electron to do that, it just goes to the bottom edge of the screen; not as far as you want.

Anyway, seeing as it's the easiest method, I'll go ahead with parametrics.

Here's a script that you could use:

when gf clicked
set [x position* v] to (3.1415)//Position
set [y position* v] to (0)
set [radius v] to ([sqrt v] of (((x position*) * (x position*)) + ((y position*) * (y position*))))
if <(x position*) > (0)>
 set [T v] to ([asin v] of ((y position*) / (radius)))
else
 set [T v] to ((180) - ([asin v] of ((y position*) / (radius))))
end
forever
 set y to (([sin v] of (T)) * (radius))
 set x to (([cos v] of (T)) * (radius))
 change [T v] by (0.1)//Rotation Speed

This nice, though somewhat math-complicated script keeps track of an object's position and will make sure that it's always centered around the origin. Just enter the sprite's position and you should be good to go.

That actually brings up a good point. If you want to, you can get rid of the two position variables, though then you'll have to substitute their values into the equations of the script. And, if you go far enough, you can even remove the variable "radius", though then you'd have to substitute it's value into where it used to be.

Well, I hope that this helps!

With regards,

ErnieParke

Last edited by ErnieParke (2013-04-25 18:49:02)


http://i46.tinypic.com/35ismmc.png

Offline

 

#12 2013-04-25 19:10:34

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

Thanks! 1 thing-- is there a way to copy and paste in scratch, so I don't need to write that 37 times?

Offline

 

#13 2013-04-25 21:03:54

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Migrating Sprite

mjcox2000 wrote:

Thanks! 1 thing-- is there a way to copy and paste in scratch, so I don't need to write that 37 times?

Yes, there is. Just right click what you want to copy, and click duplicate. So, if you wanted to duplicate a script, all you'd have to do is right click the hat block and hit duplicate.

Oh, and by the way, you're welcome.

With regards,

ErnieParke

Last edited by ErnieParke (2013-04-25 21:04:32)


http://i46.tinypic.com/35ismmc.png

Offline

 

#14 2013-04-26 07:06:44

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

The final version of the file can be found at http://goo.gl/OMSUU
Again, thank you so much for your help.

Offline

 

#15 2013-04-26 07:30:42

mjcox2000
New Scratcher
Registered: 2013-04-24
Posts: 9

Re: Migrating Sprite

Edit: it is at http://goo.gl/hdhpO

Offline

 

Board footer