<?php

require_once "operations/file/find_file.php";

class Labeled_Segmented_Image extends Segmented_Image
{
   private $_labels;
   private $_font_name;
   private $_font_weight;
   private $_text_color;
   private $_font_size;
   private $_text_background;
   private $_text_horizontal_padding;
   private $_text_vertical_padding;
   private $_text_stroke_width;
   private $_text_stroke_color;
   private $_label_alignment;
   private $_labeled_segments_directory_path;

   public function __construct(
      $file_path, $labels, $width=null, $height=null, $cut_orientation=null,
      $text_color=null, $font_size=null, $font_name=null, $label_alignment=null,
      $segment_count=null)
   {
      $this->_labels = $labels;
      $this->_label_alignment = $label_alignment;
      $this->construct_parent(
         $file_path, $segment_count, $cut_orientation, $width, $height);
      $this->build_labeled_segments_directory();
      $this->draw_labels();
   }

   private function construct_parent(
      $file_path, $segment_count, $cut_orientation, $width, $height)
   {
      $segment_count = $this->determine_segment_count($segment_count);
      parent::__construct(
         $file_path, $segment_count, $cut_orientation, $width, $height);
   }


   private function determine_segment_count($segment_count)
   {
      if ($segment_count === null)
      {
         $segment_count = sizeof($this->_labels);
      }
      return $segment_count;
   }

   private function build_labeled_segments_directory()
   {
      $path = $this->_segments_directory_path . "/";
      $path .= $GLOBALS["LABELED_SEGMENTS_DIRECTORY_NAME"];
      if (!is_dir($path))
      {
         mkdir($path);
      }
      $this->_labeled_segments_directory_path = $path;
   }

   private function draw_labels()
   {
      $ii = 0;
      foreach ($this->_labels as $label)
      {
         $this->add_label_to_segment($label, $ii++);
      }
   }

   private function add_label_to_segment($label, $segment_index)
   {
      if ($label instanceof Entity)
      {
         $this->add_entity_to_segment($label, $segment_index);
      }
      else
      {
         $this->add_annotation_to_segment($label, $segment_index);
      }
   }

   private function add_entity_to_segment($entity, $segment_index)
   {
      $segment = $this->segments[$segment_index];
      $entity = $this->build_replacement_entity($entity, $segment);
      $this->segments[$segment_index] = $entity;
   }

   private function build_replacement_entity($label, $segment)
   {
      $file_path = $segment->path;
      $entity = new Div($segment->width, $segment->height);
      $entity->background = $file_path;
      $entity->content = $label;
      $entity->overflow = "hidden";
      if ($this->_cut_orientation == "vertical")
      {
         $entity->float = "left";
      }
      $label->line_height = $segment->height . "px";
      return $entity;
   }

   private function add_annotation_to_segment($text, $index)
   {
      $segment = $this->segments[$index];
      $annotation = $this->build_label($text);
      $labeled_segment_image = new Imagick($segment->path);
      $this->draw_annotation($labeled_segment_image, $annotation);
      $this->save_labeled_segment_image($labeled_segment_image, $index);
   }

   private function build_label($text)
   {
      $label = new Label(
         $text, null, $this->_font_size, $this->_font_weight,
         $this->_text_color, $this->_font_name, $this->_text_background,
         $this->_text_horizontal_padding, $this->_text_vertical_padding,
         $this->_stroke_width, $this->_stroke_color);
      return $label->_image;
   }

   private function draw_annotation($image, $annotation)
   {
      $x = $this->determine_annotation_horizontal_offset($image, $annotation);
      $y = $this->determine_annotation_vertical_offset($image, $annotation);
      $image->compositeImage($annotation, Imagick::COMPOSITE_DEFAULT, $x, $y);
   }

   private function determine_annotation_horizontal_offset($image, $annotation)
   {
      $offset = 0;
      $image_width = $image->getImageWidth();
      $annotation_width = $annotation->getImageWidth();
      if ($this->_label_alignment == "center")
      {
         $offset = $image_width/2 - $annotation_width/2;
      }
      elseif ($this->_label_alignment == "right")
      {
         $offset = $image_width - $annotation_width;
      }
      return $offset;
   }

   private function determine_annotation_vertical_offset($image, $annotation)
   {
      $offset = $image->getImageHeight()/2 - $annotation->getImageHeight()/2;
      return $offset;
   }

   private function save_labeled_segment_image($image, $index)
   {
      $path = $this->build_labeled_segment_path($index);
      $image->writeImage($path);
      $this->segments[$index]->path = $path;
   }

   private function build_labeled_segment_path($index)
   {
      return $this->_labeled_segments_directory_path . "/" . $index;
   }
}
<?php

define("LABEL_CONSTANT_PREFIX", "LABEL_");
define("LABEL_FONT_CONSTANT_SUFFIX", "_FONT");
define("LABEL_SIZE_CONSTANT_SUFFIX", "_SIZE");

class Navigation_Map extends Div
{
   private $labels = array();

   public function __construct()
   {
      parent::__construct();
      $this->import_labels();
      $this->segmented_image = new Labeled_Segmented_Image(
         "src/img/jimjilbbang.jpg", $this->labels, 400, 500, "horizontal");
      $this->width = 400;
      $this->text_align = "left";
      $this->margin = "20 auto";
   }

   private function import_labels()
   {
      for ($ii = 1; isset($GLOBALS[LABEL_CONSTANT_PREFIX . $ii]); $ii++)
      {
         $this->include_label($ii);
      }
   }

   private function include_label($ii)
   {
      $label_constant_name = LABEL_CONSTANT_PREFIX . $ii;
      $font_constant_name = $label_constant_name . LABEL_FONT_CONSTANT_SUFFIX;
      $size_constant_name = $label_constant_name . LABEL_SIZE_CONSTANT_SUFFIX;
      $text = $GLOBALS[$label_constant_name];
      $font = $this->get_constant_value($font_constant_name);
      $size = $this->get_constant_value($size_constant_name);
      $statement = new Statement($text, $size, "bold", null, "black", "white", $font);
      $statement->padding = 3;
/*       $statement = $text; */
      $this->labels[] = $statement;
   }

   private function get_constant_value($constant_name)
   {
      if (isset($GLOBALS[$constant_name]))
      {
         return $GLOBALS[$constant_name];
      }
      return null;
   }
}
3.129.68.127
3.129.68.127
3.129.68.127
 
August 12, 2013

I've been researching tartan/plaid recently for decoration in my updated version of Ball & Cup, now called Send. I want to create the atmosphere of a sports event, so I plan on drawing tartan patterns at the vertical edges of the screen as backgrounds for areas where spectator ants generate based on player performance. I figured I would make my own patterns, but after browsing tartans available in the official register, I decided to use existing ones instead.

I made a list of the tartans that had what I thought were interesting titles and chose 30 to base the game's levels on. I sequenced them, using their titles to form a loose narrative related to the concept of sending. Here are three tartans in the sequence (levels 6, 7 and 8) generated by an algorithm I inferred by looking at examples that reads a tartan specification and draws its pattern using a simple dithering technique to blend the color stripes.


Acadia


Eve


Spice Apple

It would be wasting an opportunity if I didn't animate the tartans, so I'm thinking about animations for them. One effect I want to try is making them look like water washing over the area where the ants are spectating. I've also recorded some music for the game. Here are the loops for the game over and high scores screens.

Game Over

High Scores