Sine Graph Slider

Comments

1 comment

  • Support Admin

    To control a component of the sine graph, you need to do a few things:

    1. Create variables for all the components that you want the user to be able to control
    2. Place your plot-drawing for-loop inside of a function
    3. Replace the numbers in your equation with the variables defined in step 1
    4. Create a slider whose value alters one of the variables defined in step 1
    5. When the slider is moved, call the function defined in step 2

    E.g.

    <script>
    local x, y;
    local sinePlot= myPlot.series;
    local amp = 5; -- variable to represent the amplitude of the sine wave

    local function redrawPlot() -- create function and put for-loop inside
    sinePlot:Clear()
    for x = -10,10, 0.1 do
    y = amp*math.cos((math.pi)*x)+5 -- replace amplitude number with variable name
    sinePlot:Add(x,y)
    end
    sinePlot:Update()
    end
    </script>

    <!-- Set amplitude variable to value of the slider, then redraw the plot -->
    <slider name="amplitudeSlider" min="0" max="5" value="5">
    <onValueChanged>
    amp = value
    redrawPlot()
    </onValueChanged>
    </slider>
    0
    Comment actions Permalink

Please sign in to leave a comment.