User Tools

Site Tools


4rpl:commands:signalgenerator

This is an old revision of the document!


Index

SignalGenerator

SignalGenerator(<-interval <-frequency <-phaseShift <-invert <-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-coordinate on a graph line following one of the indicated wave patterns.

Useful to animate an object or to produce a pattern over time. For instance, could be used to vary the strength of an emitter over time, or to “pulse” (oscillate) the brightness of light source or beacon.

Arguments and type in order:

  • interval: (integer vale) X coordinate in the waveform Eg.time (or how long one repetition of the effect lasts)
  • frequency: (floating point number) The number of values to generate over the Interval (stepsize) of the waveform
  • phaseShift: (floating point number) An offset from the origin value of the waveform (See Notes)
  • invert: (true/false) inverts the waveform
  • signalType: (0 to 6)
    • 0 = NONE
    • 1 = SINE
    • 2 = SQUARE
    • 3 = TRIANGLE
    • 4 = SAW - TOOTH
    • 5 = RANDOM
    • 6 = CONSTANT

Notes

Phase Shift

The phase difference, or phase shift as it is also called, of a Sinusoidal Waveform is the angle Φ(Greek letter Phi), in degrees or radians that the waveform has shifted from a certain reference point along the horizontal zero axis. In other words phase shift is the lateral difference between two or more waveforms along a common axis. Sinusoidal waveforms of the same frequency can have a phase difference.

The phase difference, Φ of an alternating waveform can vary from between 0 to its maximum time period, T of the waveform during one complete cycle and this can be anywhere along the horizontal axis between, Φ = 0 to 2π(radians) or Φ = 0 to 360o depending upon the angular units used.

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.
# 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.
 
180 ->numFrames 			# at 30 frames a sec, cycle every 6 seconds.
1 <-numFrames asFloat div ->frequency	#stepsize
0 ->phaseShift
false ->invert
1 ->signalType 				#sine
 
do (<-numFrames 0)
    SignalGenerator(I <-frequency <-phaseShift <-invert <-signalType) ->sigValue
    Round(<-sigValue 2) ->sigValue
    TraceAllSp (I " : " <-sigValue)
    SetCreeper(I 75 add(<-sigValue mul(50)) 15 true)
loop

The above command generated this sinusoidal creeper pattern on a map

Index

4rpl/commands/signalgenerator.1621694600.txt.gz · Last modified: 2021/05/22 10:43 by Karsten75