<?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.57
216.73.216.57
216.73.216.57
 
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.