Ini nih.. hasil belajar ku.. dengan utak atikan versi Uliya.. hehe.. Chek this out..
Kalo pengen liat outputnya, jangan lupa aktifin dulu 'xampp'nya.. ato kalo ga punya, bisa pake 'wamp server'.. Selamat mencoba.. :-)
//nilai besaran
$h=0.01;
$m=1;
$k=1;
$c=0.1;
$t=0;
$v=0;
$x=1;
//membuat kanvas bidang gambar :
//ukuran panjang, lebar
$aa=800;
$bb=600;
$xmin=-2;
$xmax=50;
$ymin=-1.5;
$ymax=1.5;
$k1=$aa/($xmax-$xmin);
$k2=-$aa*$xmin/($xmax-$xmin);
$k3=$bb/($ymin-$ymax);
$k4=-$bb*$ymax/($ymin-$ymax);
//menampilkan kanvas
$gb=ImageCreate ($aa,$bb);
//membuat warna
$pink=ImageColorAllocate($gb,150,125,168);
$warna1=ImageColorAllocate($gb,200,200,200);
$warna2=ImageColorAllocate($gb,255,0,0);
$biru=ImageColorAllocate($gb,0,0,255);
$kuning=ImageColorAllocate($gb,255,255,0);
//perumusan
for ($t=0;$t<=50;$t+=$h){
$a=-($k/$m*$x)-($c/$m*$v);
//menampilkan grafik
ImageSetPixel($gb,$t*$k1+$k2,$x*$k3+$k4,$warna2);
Imageline($gb,($xmin+1)*$k1+$k2,0*$k3+$k4,$xmax*$k1+$k2,0*$k3+$k4,$biru);
ImageLine($gb,0*$k1+$k2,($ymin+5)*$k3+$k4,0*$k1+$k2,($ymax-50)*$k3+$k4,$biru);
//menampilkan tulisan
imagestring($gb,5,46*$k1+$k2,-1.2*$k3+$k2,'t(s)',$kuning);
imagestring($gb,5,-1.1*$k1+$k2,1.1*$k3+$k4,'x(m)',$kuning);
imagestring($gb,15,11*$k1+$k2,1.3*$k3+$k4,'Grafik Hubungan Posisi (x) terhadap Waktu (t)',$kuning);
//perulangan skala & angka pada sumbu-x
for($aa=0;$aa<=100;$aa+=2){
//angka
imagestring($gb,3,$aa*$k1+$k2,-0.05*$k3+$k4,$aa,$biru);
//skala
imagestring($gb,3,$aa*$k1+$k2,0.03*$k3+$k4,"|",$biru);
}
//perulangan skala & angka pada sumbu-y
for($bb=-1;$bb<=1;$bb+=0.2){
//angka
imagestring($gb,3,0.01*$k1*$k2,$bb*$k3+$k4,$bb,$biru);
//skala
imagestring($gb,3,-0.04*$k1+$k2,$bb*$k3+$k4,"-",$biru);
}
$v=$v+$a*$h;
$x=$x+$v*$h;
}
//kaki
Header("Content-Type:Image/Jpeg");
ImageJPEG($gb);
ImageDestroy($gb);
?>
Tidak ada komentar :
Posting Komentar