# Waveform graph

I need a way to display a saw waveform that morphs into a triangle based on a x & y equation. i've managed to write something that will display 1 wavecycle but i need something that will fill the paintbox with a series of waves.
[code]
for x := 1 to Paintbox.Width do
begin
rx := ( ( 1 / Paintbox.Width ) * x );
GraphIt( rx, ry );
y := Round( ( 1 - (ry/1) ) * Paintbox.Height);
if x = 1 then
Paintbox.Canvas.MoveTo( x, y )
else
Paintbox.Canvas.LineTo( x, y );
end;

procedure GraphIt(X: Real; var Y: Real);
var
slope: double;
tmp: integer;
begin
// As shape increases, the wave gets steeper. Sawtooth has
// slope 1, increasing to slope 2 for triangle.
slope := (PatBuf[oDCO1_WAVESHAPE] + 63.0) / 63.0;
tmp := round(X / slope);
Y := (X - (tmp * slope) ) * slope;
// But output > 1 gets folded back.
if Y > 0.5 then Y := 1 - Y;
end;
[/code]

any help would be much appreciated...

• : I need a way to display a saw waveform that morphs into a triangle based on a x & y equation. i've managed to write something that will display 1 wavecycle but i need something that will fill the paintbox with a series of waves.
: [code]
[b]for ystep := 1 to (Paintbox.Height div 4) do[/b]
: for x := 1 to Paintbox.Width do
: begin
: rx := ( ( 1 / Paintbox.Width ) * x );
: GraphIt( rx, ry );
: y := Round( ( 1 - (ry/1) ) * Paintbox.Height);
: if x = 1 then
: Paintbox.Canvas.MoveTo( x, y [b]+ ystep*4[/b] )
: else
: Paintbox.Canvas.LineTo( x, y [b]+ ystep*4[/b] );
: end;
:
: procedure GraphIt(X: Real; var Y: Real);
: var
: slope: double;
: tmp: integer;
: begin
: // As shape increases, the wave gets steeper. Sawtooth has
: // slope 1, increasing to slope 2 for triangle.
: slope := (PatBuf[oDCO1_WAVESHAPE] + 63.0) / 63.0;
: tmp := round(X / slope);
: Y := (X - (tmp * slope) ) * slope;
: // But output > 1 gets folded back.
: if Y > 0.5 then Y := 1 - Y;
: end;
: [/code]
:
: any help would be much appreciated...
:
:
I've changed your code, so it will draw 1 wave every 4 pixels. You can change this easily, should the result be too weird. This won't fill the corners of the paintbox and the wave. That needs tome more range checking before the MoveTo() and LineTo() calls.

• : I've changed your code, so it will draw 1 wave every 4 pixels.

thanks! i'll try this out ASAP