Object Attraction: различия между версиями

Материал из Поле цифровой дидактики
 
(не показаны 4 промежуточные версии этого же участника)
Строка 9: Строка 9:
In '''Object Attraction''' two or more objects are attracted to each other; or are pulling on each other. This can also be referred to as gravity.
In '''Object Attraction''' two or more objects are attracted to each other; or are pulling on each other. This can also be referred to as gravity.


{{tip|Please remember to adjust the scripts shown in this tutorial as necessary to best fit your [[project]].}}
== Scratch ==


== Elliptical Orbit Method  ==
=== Elliptical Orbit Method  ===
One way to make one object attracted to another object is to make a sprite "Orbit" around the other object. This method is always 100% accurate and will automatically move when the object that it is being rotated about moves. Here is a script that creates an elliptical orbit:
One way to make one object attracted to another object is to make a sprite "Orbit" around the other object. This method is always 100% accurate and will automatically move when the object that it is being rotated about moves. Here is a script that creates an elliptical orbit:


Строка 34: Строка 34:
One example of the elliptical orbit method can be found [http://scratch.mit.edu/projects/dazman/1345968 here].
One example of the elliptical orbit method can be found [http://scratch.mit.edu/projects/dazman/1345968 here].


== Velocity Method ==
=== Velocity Method ===
Another method is to have a sprite change its velocity automatically based on its position. This method is very inaccurate however it can be very useful if your creating a game where you have to avoid multiple sprites. The Following scripts will be placed into the item that is "following" another sprite:
Another method is to have a sprite change its velocity automatically based on its position. This method is very inaccurate however it can be very useful if your creating a game where you have to avoid multiple sprites. The Following scripts will be placed into the item that is "following" another sprite:


Строка 62: Строка 62:
</scratchblocks>
</scratchblocks>


One example of the velocity method can be seen [http://scratch.mit.edu/projects/dazman/1346019 here].
; Пример проекта с притяжением объектов
: http://scratch.mit.edu/projects/dazman/1346019


== Trigonometric Method ==
<scratch project="1346019" />


{{main|Simulating Gravity}}
=== Trigonometric Method ===


== Direct Movement Method ==
* Simulating Gravity
 
==== Direct Movement Method ====
This method although far more basic than the previous methods, can be very useful in certain situations. This method is very accurate and will move automatically with the sprite. Here is an example script that would be place in the sprite that is "following" the other sprite:
This method although far more basic than the previous methods, can be very useful in certain situations. This method is very accurate and will move automatically with the sprite. Here is an example script that would be place in the sprite that is "following" the other sprite:


Строка 79: Строка 82:
</scratchblocks>
</scratchblocks>


One example of the direct movement method can be seen [http://scratch.mit.edu/projects/dazman/1346041 here].
<scratch project="1346041" />
: http://scratch.mit.edu/projects/dazman/1346041


== Wall Method ==
==== Wall Method ====
This method sort of has a fast wall attraction.
This method sort of has a fast wall attraction.


Строка 92: Строка 96:
</scratchblocks>
</scratchblocks>


== See Also ==
* [[Object Repulsion]]
* [[Simulating Gravity]]


[[Category:Physics Tutorials]][[Category:Scripting Tutorials]]
== StarLogo Nova==
[[ja:オブジェクト間の引力]]
 
 
[[Category:Scripting Tutorials]]

Текущая версия на 10:29, 2 мая 2024

Описание Как имитировать притяжение объектов друг к другу?
Область знаний Биология, Информатика, Физика
Область использования (ISTE) Computational Thinker
Возрастная категория 8


Поясняющее видео
Близкие рецепту понятия Преследовать другого агента
Среды и средства для приготовления рецепта: Scratch, Snap!, StarLogo Nova

In Object Attraction two or more objects are attracted to each other; or are pulling on each other. This can also be referred to as gravity.

Scratch

Elliptical Orbit Method

One way to make one object attracted to another object is to make a sprite "Orbit" around the other object. This method is always 100% accurate and will automatically move when the object that it is being rotated about moves. Here is a script that creates an elliptical orbit:

when green flag clicked
set [semi-major-axis v] to [110] //longest radius
set [semi-minor-axis v] to [50]  //shortest radius
set [t v] to [0] // current angle
set [inclination v] to [45] //inclination of the ellipse
forever
  repeat (360)
    set [x v] to ((([cos v] of (t)) * (semi-major-axis)) + ([x position v] of [Sprite3 v]))
    set [y v] to ((([sin v] of (t)) * (semi-minor-axis)) + ([y position v] of [Sprite3 v]))
    set x to (((x) * ([cos v] of (inclination))) - ((y) * ([sin v] of (inclination))))//tilt 'inclination' degrees. Trigonometric additive theorey
    set y to (((x) * ([sin v] of (inclination))) + ((y) * ([cos v] of (inclination))))
    change [t v] by (5)
  end
end

Remember that this script goes in the object that is being rotated.

One example of the elliptical orbit method can be found here.

Velocity Method

Another method is to have a sprite change its velocity automatically based on its position. This method is very inaccurate however it can be very useful if your creating a game where you have to avoid multiple sprites. The Following scripts will be placed into the item that is "following" another sprite:

when green flag clicked
set [y speed v] to [0]
set [x speed v] to [0]
forever
  if <([x position v] of [Sprite2 v]) < (x position)> then
    change [x speed v] by (-0.1)
  end
  if <([x position v] of [Sprite2 v]) > (x position)> then
    change [x speed v] by (0.1)
  end
  if <([y position v] of [Sprite2 v]) < (y position)> then
    change [y speed v] by (-0.1)
  end
  if <([y position v] of [Sprite2 v]) > (y position)> then
    change [y speed v] by (0.1)
  end
end

when green flag clicked
forever
  go to x: ((x position) + (x speed)) y: ((y position) + (y speed))
end
Пример проекта с притяжением объектов
http://scratch.mit.edu/projects/dazman/1346019

Trigonometric Method

  • Simulating Gravity

Direct Movement Method

This method although far more basic than the previous methods, can be very useful in certain situations. This method is very accurate and will move automatically with the sprite. Here is an example script that would be place in the sprite that is "following" the other sprite:

when green flag clicked
forever
  point towards [Sprite2 v]
  move (5) steps
end
http://scratch.mit.edu/projects/dazman/1346041

Wall Method

This method sort of has a fast wall attraction.

when green flag clicked
forever
  set x to ((10)*(mouse x))
  set y to ((10)+(mouse y))
end


StarLogo Nova