All pastes #268230 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-05 14:07 UTC
rendered paste body
<?php

class Gtk2_Map extends GtkImage {
	
	protected $earth;
	protected $locations = array();

	public function __construct() {
		parent::__construct();
		parent::set_from_file('earth.jpg');
		$this->earth = parent::get_pixbif();
	}

	protected function get_location_coords($lat, $lon) {
		$pixbuf = parent::get_pixbuf();
		$width = $pixbuf->get_width();
		$height = $pixbuf->get_height();
		$x = (($lon + 180) * ($width / 360));
		$y = ((($lat * -1) + 90) * ($height / 180));
		return array("x"=>round($x),"y"=>round($y));
	}

	public function set_location($lat, $lon, $red, $green, $blue, $alpha) {
		$x_y = $this->get_location_coords($lat, $lon);
		$this->put_pixel($x_y['x'], $x_y['y'], $red, $green, $blue, $alpha);
		$id = count($this->locations);
		$this->locations[$id]['x'] = $x_y['x'];
		$this->locations[$id]['x'] = $x_y['y'];
		$this->locations[$id]['red'] = $red;
		$this->locations[$id]['green'] = $green;
		$this->locations[$id]['blue'] = $blue;
		$this->locations[$id]['alpha'] = $alpha;
		return $id;
	}
	
	public function put_pixel($x, $y, $red, $green, $blue, $alpha) {
		$pixbuf = parent::get_pixbuf();
		$pixbuf->put_pixel($x, $y, $red, $green, $blue, $alpha);
		parent::set_from_pixbuf($pixbuf);
	}
	
	public function reset_map() {
		parent::set_from_pixbuf($this->earth);
	}
	
	public function unset_location($id) {
		unset ($this->locations[$id]);
		foreach ($this->locations as $location) {
			$this->put_pixel($location['x'],$location['y'],$location['red'],$location['green'],$location['blue'],$location['alpha']);
		}
	}

}

?>