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
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
Offline
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
Offline
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
Last edited by ErnieParke (2013-04-25 18:49:02)
Offline
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)
Offline