Lissajous图PHP

时间:2013-06-08 07:50:57

标签: php dynamic figure

我在PHP中写了一个lissajous图,但是我希望通过实现zip来动态更改a1,a2 T1,T2值。有人可以帮我这么做吗?这是我的意思的类似例子

http://www.scottlogic.co.uk/blog/colin/2009/06/dependency-property-performance-and-lissajous-figures/

这是我的代码:

<?php
 header ("Content-type: image/png");
///x = a1 * cos(t/T1);
/// y = a2 * sin(t/T2);
$T1 = 20;
$T2 = 30;

$myImage = @imagecreatetruecolor(640, 480)
       or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($myImage, 255, 255, 224);
$poly_color = imagecolorallocate($myImage, 124, 120, 224);

//calculate x-value and y-value point by point
$points = array();
 for ($i=0; $i<1000; $i=$i+1)
 {
     //define curve's function
     $x = 310*cos($i/$T1); //define x-value
     $y = 230*sin($i/$T2);//define y-value

     //move the coordinate, append a point's x-value and y-value
     $points[] = 320+$x; //x-value
     $points[] = 240-$y;  //y-value
}

//count points
$totalPoints = count($points)/2;

//drawing title
$title = "Final Plot ($totalPoints points)";
imagestring($myImage, 3, 5, 5,  $title, $text_color);

/** drawing points one by one, notice if there 
  * are 10 points, we need to draw 9 lines: 
  * 1) point 0 to 1; 
  * 2) point 1 to 2;
  * ...
  * ...
  * 9) point 8 to 9; 
  */
for ($i=0; $i<$totalPoints-1; $i++)
 {
     imageLine($myImage, $points[2*$i], $points[1+2*$i], $points[2+2*$i], $points[3+2*$i], $poly_color);    
 }

//finalizing
imagepng($myImage);
imagedestroy($myImage);
?>

1 个答案:

答案 0 :(得分:0)

嗯....你可以先从简单的文字输入开始...... 将其作为html添加到该文件的底部....

<form id="yourform" action="" method="post">
 <input name="t1" type="text"/>
  <input name="t2" type="text"/>
 <input type="submit" name="submit">
</form>

然后在文件的顶部....

 If(isset($_POST)){
 $T1 = $_POST['t1'];
 $T2 = $_POST['t2'];} else {
 $T1=20; $T2=30;}

现在,您可以在文本框中输入值并将其传递给图像进行处理。 然后,您可以使用JQuery ui将这些输入更改为滑块。

http://jqueryui.com/slider/#rangemax

此外,您可以进行一些验证,以便只允许整数。 但我不会在这里这样做......

希望这足以让你开始:)