User Tools

Site Tools


4rpl:commands:signalgenerator

This is an old revision of the document!


SignalGenerator

SignalGenerator(<-interval <-sigFrequency <-phaseShift false <-signalType) ->sigValue

Description

Computes the value for a given signal waveform and pushes it to the stack.

A function to derive the y-coordinate for a given x-co-ordiante on a graph line following one of the indicated wave patterns. Uselful to animate an object or to a given pattern over time. Could be used for instance to vary output from an emitter. Oscillating rightness of light source or beacon; Oscillating strength of an emitter over time - both of these can be thought of as a a use case for this function.

Arguments and type in order: 1: Integer. the X coordinate in the waveform (Eg. time) \
2: Float. Frequency of the waveform \
3: Float. PhaseShift of the waveform \
4: Bool. invert the waveform \  5: Integer. Signal type (0 to 6 in types, below) \

Signal types. 0 = NONE <br/> 1 = SINE <br/> 2 = SQUARE <br/> 3 = TRIANGLE <br/> 4 = SAWTOOTH <br/> 5 = RANDOM <br/> 6 = CONSTANT <br/>

Examples

#  On a map with terrain of 200 in X direction and at least 150 in Z direction (3D coordinates)
# generate a sine wave of creeper across the map.
200    ->numFrames
      ->frequency (1 div (AsFloat (<-numFrames)))
0     ->phaseShift
false ->invert
1     ->signalType #sine
 
do  (<-numFrames 0)
    SignalGenerator(I <-frequency <-phaseShift <-invert <-signalType )  ->sigValue
    round (<-sigValue) 2) ->sigValue
    print3 (I " : " <-sigValue )
    SetCreeper(I 75 add (<-sigValue mul (50)) 15 true)
loop
4rpl/commands/signalgenerator.1555877062.txt.gz · Last modified: 2019/04/21 16:04 by 127.0.0.1