External Exam Download Resources Web Applications Games Recycle Bin

Sine Wave


theory

Algorithm to take our sine wave from one side of the Scratch screen to the other, on repeat:

forever:
    let Θ = (angle)
    y = (amplitude) × sin Θ, for:
        -(screen_width)° ≤ Θ ≤ (screen_width)°
    if angle > screen_width, let Θ = -(screen_width)


implementation

implementation v2
with alternating speeds, start positions and amplitudes:


questions
1. Variable effects
Explain what happens if you increase or decrease the initial variables:
  1. screen_width
  2. amplitude
  3. speed
  4. angle

2. Gamify
Use this sine wave as patrol code for an emeny in a game of your choosing.