<?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;
   }
}
44.223.39.67
44.223.39.67
44.223.39.67
 
September 13, 2013

from array import array
from time import sleep

import pygame
from pygame.mixer import Sound, get_init, pre_init

class Note(Sound):

    def __init__(self, frequency, volume=.1):
        self.frequency = frequency
        Sound.__init__(self, self.build_samples())
        self.set_volume(volume)

    def build_samples(self):
        period = int(round(get_init()[0] / self.frequency))
        samples = array("h", [0] * period)
        amplitude = 2 ** (abs(get_init()[1]) - 1) - 1
        for time in xrange(period):
            if time < period / 2:
                samples[time] = amplitude
            else:
                samples[time] = -amplitude
        return samples

if __name__ == "__main__":
    pre_init(44100, -16, 1, 1024)
    pygame.init()
    Note(440).play(-1)
    sleep(5)

This program generates and plays a 440 Hz tone for 5 seconds. It can be extended to generate the spectrum of notes with a frequency table or the frequency formula. Because the rewards in Send are idealized ocean waves, they can also be represented as tones. Each level has a tone in its goal and a tone based on where the player's disc lands. Both play at the end of a level, sounding harmonic for a close shot and discordant for a near miss. The game can dynamically create these tones using the program as a basis.

I'm also building an algorithmically generated song: Silk Routes (Scissored). Here is an example of how it sounds so far.