<?php
namespace structures\html;

class Image extends Element
{
   public function __construct($src, $id=null, $class=null)
   {
      parent::__construct("img", $id, $class, false);
      $this->add_attribute("src", $src);
   }
}
<?php
namespace structures\html;

class Meta extends Element
{
   public function __construct($content, $name=null, $http_equiv=null)
   {
      parent::__construct("meta", null, null, false);
      $this->add_attribute("name", $name);
      $this->add_attribute("http-equiv", $http_equiv);
      $this->add_attribute("content", $content);
   }
}
Animation = function(rate, skip_frames, buffer)
{
   this.rate = rate;
   this.playing = false;
   this.deviation = 0;
   this.skip_frames = skip_frames || false;
   this.buffer = buffer || false;
}

Animation.prototype.play = function(method_name, delay)
{
   if (method_name == null)
   {
      method_name = "sequence";
   }
   var parameters = this.extract_parameters(arguments);
   var current = this;
   this.reset_last_ms(delay);
   this.interval = window.setTimeout(
      function()
      {
	 current.playing = true;
	 current.loop(method_name, parameters);
      }, delay);
}

Animation.prototype.reset_last_ms = function(delay)
{
   if (this.skip_frames)
   {
      this.last_ms = +new Date - this.rate;
      if (delay)
      {
	 this.last_ms += delay;
      }
   }
}

Animation.prototype.loop = function(method_name, parameters)
{
   var frames = 1;
   if (this.skip_frames)
   {
      frames += this.measure_deviation();
       console.log(frames);
   }
   var current = this;
   for (var ii = 0; ii < frames; ii++)
   {
      current[method_name].apply(current, parameters);
   }
   if (this.playing)
   {
      this.interval = window.setTimeout(
	 function()
	 {
	    current.loop(method_name, parameters);
	 }, this.rate - this.buffer);
   }
}

Animation.prototype.measure_deviation = function()
{
   var count = 0;
   var time = +new Date;
   var difference = time - this.last_ms;
   var overflow = difference - this.rate;
   this.deviation += overflow;
   this.last_ms = time;
   if (this.deviation < -this.rate)
   {
      this.deviation += this.rate;
      count--;
   }
   else
   {
      while (this.deviation > this.rate)
      {
	 this.deviation -= this.rate;
	 count++;
      }
   }
   return count;
}

Animation.prototype.stop = function()
{
   window.clearInterval(this.interval);
   this.playing = false;
}

Animation.prototype.extract_parameters = function(list)
{
   if (list.length > 2)
   {
      list = Array.prototype.slice.call(list);
      return list.slice(2);
   }
   return [null];
}

Animation.prototype.toggle = function()
{
   if (this.playing)
   {
      this.stop();
   }
   else
   {
      this.play();
   }
}

Animation.prototype.toString = function()
{
   return "[object Animation]";
}
window.getSize = function()
{
    if (window.innerWidth != undefined)
    {
	return {width: window.innerWidth, height: window.innerHeight};
    }
    var body = document.body;
    var document_element = document.documentElement;
    return {width: Math.max(body.clientWidth, document_element.clientWidth),
	    height: Math.max(body.clientHeight, document_element.clientHeight)};
}
Color = function()
{
   this.setRGB.apply(this, arguments);
}

Color.prototype.setRGB = function()
{
   if (arguments.length > 1)
   {
      this.rgb = [arguments[0], arguments[1], arguments[2]];
   }
   else if (arguments.length > 0)
   {
      var color = arguments[0];
      if (color instanceof Array)
      {
	 this.rgb = color;
      }
      else if (color.slice(0, 3) == "rgb")
      {
	 this.rgb = this.extractRGBFromTuple(color);
      }
      else
      {
	 this.rgb = this.extractRGBFromHexString(color);
      }
   }
   else
   {
       this.randomize();
   }
}

Color.prototype.extractRGBFromTuple = function(color)
{
   var rgb = color.match(/\d+/g);
   return [+rgb[0], +rgb[1], +rgb[2]];
}

Color.prototype.extractRGBFromHexString = function(color)
{
   var r = parseInt(color.slice(1, 3), 16);
   var g = parseInt(color.slice(3, 5), 16);
   var b = parseInt(color.slice(5, 7), 16);
   return [r, g, b];
}

Color.prototype.randomize = function(min, max)
{
    this.rgb = this.buildRandomRGB(min, max);
}

Color.prototype.buildRandomRGB = function(min, max)
{
    var min = min || 0;
    var max = max || 255;
    var r = this.getRandomInteger(min, max);
    var g = this.getRandomInteger(min, max);
    var b = this.getRandomInteger(min, max);
    return [r, g, b];
}

Color.prototype.getRandomInteger = function(min, max)
{
   return Math.floor(Math.random() * (max - min + 1)) + min;
}

Color.prototype.getString = function()
{
   var r = parseInt(this.rgb[0]);
   var g = parseInt(this.rgb[1]);
   var b = parseInt(this.rgb[2]);
   return "rgb(" + r + "," + g + "," + b + ")";
}

Color.prototype.changeBrightness = function(factor)
{
    for (var ii = 0; ii < this.rgb.length; ii++)
    {
	this.rgb[ii] += factor;
    }
}

Color.prototype.toString = function()
{
   return "[object Color]";
}
3.145.119.199
3.145.119.199
3.145.119.199
 
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.