Love What You Do, Do What You Love

Membuat Grafik Sin dan Cos menggunakan Delphi 7

Posted by : Unknown
Minggu, 30 Desember 2012

Pseudo Code:


BUTTON SUMBU KOORDINAT
Function SumbuX(LojikX:Double):Integer;
  begin
    result:=Round(LojikX + 400);
  end;

Function SumbuY(LojikY:Double):Integer;
  begin
    result:=Round(160 - LojikY);
  end;

begin
with image2.Canvas do
  begin
    pen.Width:=3;
    font.Size:=12;

    //sumbu x
    moveto(sumbuX(-300),sumbuY(0));
    lineto(sumbuX(300),sumbuY(0));
    textout(sumbuX(305),sumbuY(0),'sumbu x');

    //sumbu y
    moveto(sumbuX(0),sumbuY(-150));
    lineto(sumbuX(0),sumbuY(150));
    textout(sumbuX(0),sumbuY(150),'sumbu y');

    //keterangan
    font.Size:=9;
    textout(sumbuX(100),sumbuy(-5),'phi');
    textout(sumbuX(200),sumbuY(-5),'2phi');
    textout(sumbuX(-100),sumbuy(-5),'-phi');
    textout(sumbuX(-200),sumbuY(-5),'-2phi');
    textout(sumbuX(-10),sumbuY(80),'1');
    textout(sumbuX(-15),sumbuY(-75),'-1');
  end;
end;

BUTTON COS X
Function SumbuX(LojikX:Double):Integer;
  begin
    result:=Round(LojikX + 400);
  end;

Function SumbuY(LojikY:Double):Integer;
  begin
    result:=Round(160 - LojikY);
  end;

var i:real;
begin
with image2.Canvas do
  begin
     pen.Width:=3;
     font.size:=9;
     font.Color:=clred;

     i:=-200;
     while i<=200 do
        begin
          Pixels[sumbuX(i),sumbuY(80*Cos(i*2*3.14/200))]:=clred;
          i:=i+0.03;
          TextOut(sumbuX(200),sumbuY(80),'y = cos x');
        end;
     end;
  end;

BUTTON SIN X
Function SumbuX(LojikX:Double):Integer;
  begin
    result:=Round(LojikX + 400);
  end;

Function SumbuY(LojikY:Double):Integer;
  begin
    result:=Round(160 - LojikY);
  end;

var i:real;
begin
  with image2.Canvas do
  begin
  pen.Width:=4;
  font.Size:=9;
  font.Color:=clblue;

  i:=-200;
    while i<=200 do
      begin
        Pixels[sumbuX(i),sumbuY(80*Sin(i*2*3.14/200))]:=clblue;
        i:=i+0.03;
        TextOut(sumbuX(185),sumbuY(-40),'y = sin x');
      end;
    end;
end;


Semoga Bermanfaat :)

0 comments:

Copyright © 2012 Zuka Zuka World | Hatsune Miku Theme | Designed by Johanes DJ