예제 #1
0
	 function ellipseRadialGradient($gradient, $x1, $y1, $x2, $y2) {
	
		if($y1 - $y2 > 0) {
	
			if($y1 - $y2 != $x2 - $x1) {
				trigger_error("Radial gradients are only implemented on circle, not ellipses");
			}
			
			$c = new awPoint($x1 + ($x2 - $x1) / 2, $y1 + ($y2 - $y1) / 2); 
			$r = ($x2 - $x1) / 2;
			$ok = array();
			
			// Init gradient
			$this->init($gradient, $r);
			
			for($i = 0; $i <= $r; $i += 0.45) {
			
				$p = ceil((2 * M_PI * $i));
				
				if($p > 0) {
					$interval = 360 / $p;
				} else {
					$interval = 360;
				}
				
				$color = $this->color($i);
				
				for($j = 0; $j < 360; $j += $interval) {
				
					$rad = ($j / 360) * (2 * M_PI);
					
					$x = round($i * cos($rad));
					$y = round($i * sin($rad));
					
					$l = sqrt($x * $x + $y * $y);
					
					if($l <= $r) {
					
						if(
							array_key_exists((int)$x, $ok) === FALSE or
							array_key_exists((int)$y, $ok[$x]) === FALSE
						) {
						
							// Print the point
							$this->drawer->point($color, new awPoint($c->x + $x, $c->y + $y));
							
							$ok[(int)$x][(int)$y] = TRUE;
						
						}
						
					}
				
				}
				
				$color->free();
				unset($color);
			
			}
		
		}
	
	}