1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | // $Id: canvaspiralex1.php,v 1.1 2002/10/26 11:35:42 aditus Exp $ |
---|
3 | require_once ('jpgraph/jpgraph.php'); |
---|
4 | require_once ('jpgraph/jpgraph_canvas.php'); |
---|
5 | |
---|
6 | |
---|
7 | if( empty($_GET['r']) ) |
---|
8 | $r = 0.44; |
---|
9 | else |
---|
10 | $r = $_GET['r']; |
---|
11 | |
---|
12 | if( empty($_GET['w']) ) |
---|
13 | $w=150; |
---|
14 | else |
---|
15 | $w = $_GET['w']; |
---|
16 | |
---|
17 | if( empty($_GET['h']) ) |
---|
18 | $h=240; |
---|
19 | else |
---|
20 | $h = $_GET['h']; |
---|
21 | |
---|
22 | if( $w < 60 ) $w=60; |
---|
23 | if( $h < 60 ) $h=60; |
---|
24 | |
---|
25 | |
---|
26 | function SeaShell($img,$x,$y,$w,$h,$r,$n=12,$color1='navy',$color2='red') { |
---|
27 | |
---|
28 | $x += $w; |
---|
29 | $w = (1-$r)/$r*$w; |
---|
30 | |
---|
31 | $sa = 0; |
---|
32 | $ea = 90; |
---|
33 | |
---|
34 | $s1 = 1; |
---|
35 | $s2 = -1; |
---|
36 | $x_old=$x; $y_old=$y; |
---|
37 | for($i=1; $i < $n; ++$i) { |
---|
38 | $sa += 90; |
---|
39 | $ea += 90; |
---|
40 | if( $i % 2 == 1 ) { |
---|
41 | $y = $y + $s1*$h*$r; |
---|
42 | $h = (1-$r)*$h; |
---|
43 | $w = $w / (1-$r) * $r ; |
---|
44 | $s1 *= -1; |
---|
45 | $img->SetColor($color1); |
---|
46 | $img->Line($x,$y,$x+$s1*$w,$y); |
---|
47 | } |
---|
48 | else { |
---|
49 | $x = $x + $s2*$w*$r; |
---|
50 | $w = (1-$r)*$w; |
---|
51 | $h = $h / (1-$r) * $r; |
---|
52 | $s2 *= -1; |
---|
53 | $img->SetColor($color1); |
---|
54 | $img->Line($x,$y,$x,$y-$s2*$h); |
---|
55 | } |
---|
56 | $img->SetColor($color2); |
---|
57 | $img->FilledRectangle($x-1,$y-1,$x+1,$y+1); |
---|
58 | $img->Arc($x,$y,2*$w+1,2*$h+1,$sa,$ea); |
---|
59 | $img->Arc($x,$y,2*$w,2*$h,$sa,$ea); |
---|
60 | $img->Arc($x,$y,2*$w-1,2*$h-1,$sa,$ea); |
---|
61 | $img->Line($x_old,$y_old,$x,$y); |
---|
62 | $x_old=$x; $y_old=$y; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | $g = new CanvasGraph($w,$h); |
---|
67 | //$gr = 1.61803398874989484820; |
---|
68 | |
---|
69 | $p = SeaShell($g->img,0,20,$w-1,$h-21,$r,19); |
---|
70 | $g->img->SetColor('black'); |
---|
71 | $g->img->Rectangle(0,20,$w-1,$h-1); |
---|
72 | $g->img->SetFont(FF_FONT2,FS_BOLD); |
---|
73 | $g->img->SetTextAlign('center','top'); |
---|
74 | $g->img->StrokeText($w/2,0,"Canvas Spiral"); |
---|
75 | |
---|
76 | $g->Stroke(); |
---|
77 | ?> |
---|
78 | |
---|