EVR.include("level/road/racer/flame/Graphic.js");
EVR.Level.Road.Racer.Flame = function(racer)
{
   this.racer = racer;
   this.last_show = false;
   this.last_speed = 0;
   this.palette = FLAME_PALETTE;
   this.addGraphics();
}
EVR.Level.Road.Racer.Flame.prototype.addGraphics = function()
{
   var graphics = [];
   var count = this.palette.length;
   for (var ii = 0; ii < count; ii++)
   {
      graphics.push(
	 new EVR.Level.Road.Racer.Flame.Graphic(
	    this.racer, this.palette[ii], ii + 1, count));
   }
   this.graphics = graphics;
}
EVR.Level.Road.Racer.Flame.prototype.update = function(show, speed)
{
   if (show != this.last_show || speed != this.last_speed)
   {
      var graphics = this.graphics;
      for (var ii = 0; ii < graphics.length; ii++)
      {
	 graphics[ii].display(show, speed);
      }
      this.last_show = show;
      this.last_speed = speed;
   }
}
EVR.Level.Road.Racer.Flame.prototype.draw = function()
{
   var graphics = this.graphics;
   for (var ii = 0; ii < graphics.length; ii++)
   {
      graphics[ii].draw();
   }
}
EVR.Level.Road.Racer.Flame.Graphic = function(racer, color, index, count)
{
   EVR.Graphic.call(this, racer.avatar, RATIO_HEIGHT);
   this.racer = racer;
   this.color = color;
   this.index = index;
   this.count = count;
   this.last_offset = 0;
   this.width = FLAME_GRAPHIC_WIDTH;
   this.initializeAttributes();
   this.append();
}
EVR.Level.Road.Racer.Flame.Graphic.prototype = new EVR.Graphic;
EVR.Level.Road.Racer.Flame.Graphic.prototype.initializeAttributes = function()
{
   this.set_proportions(0, 1);
   this.set_color(this.color);
   var max = this.count + 1;
   this.set_opacity((max  - this.index) * (1 / max));
}
EVR.Level.Road.Racer.Flame.Graphic.prototype.display = function(show, speed)
{
   if (show)
   {
      var width = this.width;
      var offset = this.index * width;
      this.set_proportions(width);
      this.shape();
      this.place(-offset);
   }
   else
   {
      this.set_proportions(0);
      this.shape();
      this.place(0);
   }
}
EVR.include("level/road/racer/player/Painter.js");

EVR.Level.Road.Racer.Player = function(container, level)
{
   EVR.Level.Road.Racer.call(this, container, level);
   this.initialize_avatar();
   this.set_step();
   this.place();
   this.update_dimensions();
   this.painter = new EVR.Level.Road.Racer.Player.Painter(
      this.avatar, level.beams);
}

EVR.Level.Road.Racer.Player.prototype = new EVR.Level.Road.Racer;

EVR.Level.Road.Racer.Player.prototype.initialize_avatar = function()
{
   EVR.Level.Road.Racer.prototype.initialize_avatar.call(this);
   this.flame = new EVR.Level.Road.Racer.Flame(this);
   this.flash = new EVR.Level.Road.Racer.Flash(this);
//    this.avatar.set_opacity(PLAYER_OPACITY);
}

EVR.Level.Road.Racer.Player.prototype.add_color = function(index, expected)
{
   this.painter.add_color(index, expected);
}

EVR.Level.Road.Racer.Player.prototype.draw = function()
{
   EVR.Level.Road.Racer.prototype.draw.call(this);
   this.flame.draw();
   this.flash.draw();
}

EVR.Level.Road.Racer.Player.prototype.remove = function()
{
   EVR.Level.Road.Racer.prototype.remove.call(this);
   // this.flash.strip.removeCachedStrip();
}

EVR.Level.Road.Racer.Player.prototype.toString = function()
{
   return "[object EVR.Level.Road.Racer.Player]";
}
EVR.Level.Road.Racer.Player.Painter = function(avatar, colors)
{
   this.avatar = avatar;
   this.histogram = [];
   this.set_palette(colors);
   this.initialize_histogram();
}
EVR.Level.Road.Racer.Player.Painter.prototype.set_palette = function(colors)
{
   var palette = [];
   for (var ii = 0, len = colors.length; ii < len; ii++)
   {
      palette.push(new EVR.Color(colors[ii]));
   }
   this.palette = palette;
}
EVR.Level.Road.Racer.Player.Painter.prototype.initialize_histogram = function()
{
   var palette = this.palette;
   var histogram = [];
   for (var ii = 0, len = palette.length; ii < len; ii++)
   {
      histogram.push([0, 0]);
   }
   this.histogram = histogram;
}
EVR.Level.Road.Racer.Player.Painter.prototype.add_color = function(
   index, expected)
{
   this.histogram[index][0]++;
   this.histogram[expected][1]++;
   this.paint(this.blend());
}
EVR.Level.Road.Racer.Player.Painter.prototype.blend = function(index)
{
   var index = index || 0;
   var histogram = this.histogram;
   var palette = this.palette;
   var greatest = this.find_greatest_frequency(index);
   var color, count, proportion, blend = [0, 0, 0];
   for (var ii = 0, len = histogram.length; ii < len; ii++)
   {
      color = palette[ii];
      count = histogram[ii][index];
      proportion = count / greatest;
      blend[0] = Math.max(blend[0], proportion * color.rgb[0]);
      blend[1] = Math.max(blend[1], proportion * color.rgb[1]);
      blend[2] = Math.max(blend[2], proportion * color.rgb[2]);
   }
   return new EVR.Color(blend);
}
EVR.Level.Road.Racer.Player.Painter.prototype.find_greatest_frequency =
   function(index)
{
   var histogram = this.histogram;
   var color, max = 0;
   for (var ii = 0, len = histogram.length; ii < len; ii++)
   {
      frequency = histogram[ii][index];
      if (frequency > max)
      {
	 max = frequency;
      }
   }
   return max;
}
EVR.Level.Road.Racer.Player.Painter.prototype.paint = function(color)
{
   var color = color.get_string();
   this.avatar.set_color(color);
}
EVR.Level.Road.Racer.Player.Painter.prototype.toString = function()
{
   return "[object EVR.Level.Road.Racer.Player.Painter]";
}
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.