<?php

function include_configuration_file($file_path, $languages="all")
{
   if (!file_exists($file_path)) return;

   $content = file($file_path);
   $operations = array("define_in_php", "write_to_javascript_file");

   if ($languages == "all" || $languages == "javascript")
   {
      erase_file_contents(JAVASCRIPT_CONFIG_FILE_PATH);
   }

   switch ($languages)
   {
      case "php":
         return parse_configuration($content, $operations[0]);
      case "javascript":
         return parse_configuration($content, $operations[1]);
      default:
         return parse_configuration($content, $operations);
   }
}

function parse_configuration($body, $operations=NULL)
{
   $operations = (!is_array($operations)) ? array($operations) : $operations;
   foreach ($body as $line)
   {
      if (preg_match("/^ *#.*$/", $line) || trim($line) == "") continue;
      $equality = explode("=", $line, 2);
      $variable = strtoupper(trim($equality[0]));
      $variable = str_replace(" ", "_", $variable);
      $value = trim($equality[1]);
      foreach ($operations as $operation)
      {
         call_user_func($operation, $variable, $value);
      }
   }
}

function write_to_javascript_file($variable, $value)
{
   $equality = "var " . $variable . " = \"" . $value . "\";\n";
   file_put_contents(JAVASCRIPT_CONFIG_FILE_PATH, $equality, FILE_APPEND);
}

function define_in_php($variable, $value)
{
   $GLOBALS[$variable] = $value;
}

function erase_file_contents($file_path)
{
   $fp = fopen($file_path, 'w');
   fclose($fp);
}
<?php
namespace type;

function convert_to_array($item)
{
   if (is_array($item) == False)
   {
      return array($item);
   }

   return $item;
}
<?php
namespace sort;

function quick_sort(array &$array, $comparer=null, $left=0, $right=null)
{
   $right = set_right_index($right, $array);
   if ($right > $left)
   {
      $pivot = calculate_pivot_index($left, $right);
      $new_pivot = partition($array, $comparer, $left, $right, $pivot);
      quick_sort($array, $comparer, $left, $new_pivot - 1);
      quick_sort($array, $comparer, $new_pivot + 1, $right);
   }
}

function set_right_index($index, $array)
{
   if (is_null($index))
   {
      $index = count($array) - 1;
   }
   return $index;
}

function calculate_pivot_index($left_index, $right_index)
{
   $pivot_index = $right_index - ($right_index - $left_index) / 2;
   return $pivot_index;
}

function partition(&$array, $comparer, $left, $right, $pivot_index)
{
   $pivot_value = $array[$pivot_index];
   swap($array, $right, $pivot_index);
   $current = $left;
   for ($ii = $left; $ii < $right; $ii++)
   {
      $comparison = make_comparison($comparer, $array[$ii], $pivot_value);
      if ($comparison === True)
      {
         swap($array, $ii, $current++);
      }
   }
   swap($array, $current, $right);
   return $current;
}

function swap(&$array, $index_1, $index_2)
{
   $value = $array[$index_1];
   $array[$index_1] = $array[$index_2];
   $array[$index_2] = $value;
}

function make_comparison($comparer, $value_1, $value_2)
{
   if (!is_null($comparer))
   {
      $comparison = call_user_func($comparer, $value_1, $value_2);
   }
   else
   {
      $comparison = ($value_1 < $value_2);
   }
   return $comparison;
}
<?php
namespace file;

function count_depth($path)
{
   $stripped_path = trim($path, "/");
   return sizeof(explode("/", $path));
}
<?php

function remove_directory($directory_path, $remove_self=True)
{
   $directory_path = rtrim($directory_path, "/") . "/";
   $directory = opendir($directory_path);
   while ($file = readdir($directory))
   {
      if ($file[0] == '.') continue;
      
      $relative_path = $directory_path . $file;
      if (is_dir($relative_path))
      {
         remove_directory($relative_path);
         continue;
      }
      unlink($relative_path);
   }
   if ($remove_self) rmdir($directory_path);
}
<?php
namespace file;

function is_directory_empty($directory_path)
{
   $files = scandir($directory_path);
   return count($files) > 2;
}
<?php

function print_file_range($fp, $start, $end)
{
   fseek($fp, $start);
   echo "$start - $end\n";
   echo fread($fp, $end-$start) . "\n";
   
}
<?php

function build_path($directory_path, $file_path)
{
   $directory_path = rtrim($directory_path, "/") . "/";
   $path = $directory_path . $file_path;
   return $path;
}
216.73.216.60
216.73.216.60
216.73.216.60
 
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