Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Waveform graph

Mk. IIMk. II Member Posts: 16
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...

Comments

  • zibadianzibadian Member Posts: 6,349
    : 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.
  • Mark StrijbosMark Strijbos Member Posts: 82

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

    thanks! i'll try this out ASAP


  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _______ || http://forcoder.org || free video tutorials and ebooks about \ MATLAB, Python, C#, R, Swift, PHP, Delphi, Visual Basic .NET, Visual Basic, Assembly, Java, Ruby, PL/SQL, Objective-C, Perl, Go, C, JavaScript, C++, Scratch VBScript, D, COBOL, Crystal, Transact-SQL, Hack, Kotlin, Scala, Fortran, Clojure, ML, Lisp, LabVIEW, SAS, Bash, Scheme, Dart, Erlang, Ada, Awk, Lua, Alice, Prolog, Logo, Rust, Apex, F#, ABAP, Julia, FoxPro \ _________

Sign In or Register to comment.