Minggu, 26 Mei 2013

Syntak PHP : Grafik Benda Jatuh dengan Hambatan

Nah.. udah lama ga nge-blog tentang komputasi nih.. oke.. ini tak tampilin lagi syntak PHP tentang grafik benda jatuh versi Uliya tentunya. hehe..
Siapkan xampp dan nyalakan!!!!
siap?? Cchek this out..



$a=500;
$b=500;
$xmin=-30;
$xmax=150;
$ymin=-30;
$ymax=150;
$k1=$a/($xmax-$xmin);
$k2=$a*$xmin/($xmin-$xmax);
$k3=$b/($ymin-$ymax);
$k4=$b*$ymax/($ymax-$ymin);

//background
$gb=imagecreate($a,$b);

$pink=ImageColorAllocate($gb,159,57,168);
$merah=ImageColorAllocate($gb,177,0,0);
$biru=ImageColorAllocate($gb,0,0,255);
$kuning=ImageColorAllocate($gb,255,255,0);

//grafik
$m=0.01;
$r=0.01;
$c=0.46;
$rho=1.2;
$pi=3.14;
$g=9.8;
$h=0.01;

$t=0;
$v=0;

for($t=0;$t<=100;$t=round($t+$h,2)){
    $a=$g-(0.5*$c*$pi*$rho*$r*$r*$v*$v/$m);
    $v=$v+$a*$h;
    $t=$t+$h;

ImageSetPixel($gb,$t*$k1+$k2,$v*$k3+$k4,$merah);}
Imageline($gb,($xmin+10)*$k1+$k2,0*$k3+$k4,($xmax-10)*$k1+$k2,0*$k3+$k4,$kuning);
ImageLine($gb,0*$k1+$k2,($ymin+10)*$k3+$k4,0*$k1+$k2,($ymax-40)*$k3+$k4,$kuning);

//menampilkan tulisan
imagestring($gb,5,135*$k1+$k2,-125*$k3+$k2,'t(s)',$kuning);
imagestring($gb,5,-25*$k1+$k2,110*$k3+$k4,'v(m/s)',$kuning);

imagestring($gb,10,-15*$k1+$k2,10*$k3+$k2,'Grafik Hubungan Kecepatan (v) terhadap Waktu (t)',$biru);

for($a=10;$a<=120;$a+=10){
imagestring($gb,4,$a*$k1+$k2,-5*$k3+$k4,$a,$kuning);
imagestring($gb,2,$a*$k1+$k2,3*$k3+$k4,"|",$kuning);
}

for($b=10;$b<=100;$b+=10){
imagestring($gb,4,0.25*$k1*$k2,$b*$k3+$k4,$b,$kuning);
imagestring($gb,4,-1*$k1+$k2,$b*$k3+$k4,"-",$kuning);
}

header ("Content-type: image/jpeg");
ImageJpeg($gb);
ImageDestroy($gb);

?>

Tidak ada komentar :

Posting Komentar