EVR.Level.Meter.Reading = function(container)
{
   EVR.Graphic.call(this, container, null, null, ALIGN_LEFT);
   this.span = METER_SPAN;
   this.remaining = METER_INITIAL_LEVEL;
   this.margin = METER_MARGIN;
   this.height = 1 - this.margin[1] * 2;
   this.set_color(METER_DISABLED_COLOR);
   this.set_proportions();
   this.append();
}
EVR.Level.Meter.Reading.prototype = new EVR.Graphic;
EVR.Level.Meter.Reading.prototype.set_proportions = function()
{
   var width = (1 * this.remaining) - this.margin[0] * 2;
   EVR.Graphic.prototype.set_proportions.call(this, width, this.height);
}
EVR.Level.Meter.Reading.prototype.adjust = function(amount)
{
   var remaining = this.remaining;
   remaining += amount / this.span;
   if (remaining < 0)
   {
      remaining = 0;
   }
   else if (remaining > 1)
   {
      remaining = 1;
   }
   if (remaining != this.remaining)
   {
      this.remaining = remaining;
      this.set_proportions();
      this.shape();
   }
}
EVR.Level.Meter.Reading.prototype.toString = function()
{
   return "[object EVR.Level.Meter.Reading]";
}
EVR.register_listener = function(name, procedure)
{
   if (!!document.all)
   {
      this[name] = function() { procedure(window.event) };
   }
   else
   {
      this[name] = procedure;
   }
}
if (!!document.all)
{
   var create_element_method = document.createElement;
   document.createElement = function(type)
   {
      var element = create_element_method(type);
      element["register_listener"] = EVR.register_listener;
      return element;
   }
}
else
{
   Element.prototype.register_listener = EVR.register_listener;
}
EVR.include("element/Text.js");
EVR.Component = function(container, type, sibling)
{
   this.container = container;
   this.sibling = sibling;
   this.element = document.createElement(type);
   this.css = this.element.style;
   this.attached = false;
}
EVR.Component.prototype.append = function()
{
   var parent_element = this.get_parent_element();
   var sibling = this.sibling != null ? this.sibling : null;
   parent_element.insertBefore(this.element, sibling);
   this.attached = true;
}
EVR.Component.prototype.remove = function()
{
   var parent_element = this.get_parent_element();
   parent_element.removeChild(this.element);
   this.attached = false;
}
EVR.Component.prototype.set_color = function(color)
{
   this.css.backgroundColor = color;
}
EVR.Component.prototype.get_color = function()
{
   return this.css.backgroundColor;
}
EVR.Component.prototype.set_text = function(text, font, color, size, relative)
{
   var text;
   if (!!!this.text)
   {
      this.text = new EVR.Text(this, text, font, color, size, relative);
   }
   else
   {
      this.text.set(text, font, color, size, relative);
   }
}
EVR.Component.prototype.set_z = function(z)
{
   this.css.zIndex = z || 0;
}
EVR.Component.prototype.get_z = function()
{
   return parseInt(this.css.zIndex);
}
EVR.Component.prototype.set_opacity = function(opacity)
{
   this.css.filter = "alpha(opacity=" + parseInt(opacity * 100) + ")";
   this.css.opacity = opacity;
}
EVR.Component.prototype.get_opacity = function()
{
   return this.css.opacity;
}
EVR.Component.prototype.set_dimensions = function(width, height)
{
   if (width != null)
   {
      this.css.width = Math.round(width) + "px";
   }
   if (height != null)
   {
      this.css.height = Math.round(height) + "px";
   }
}
EVR.Component.prototype.get_dimensions = function()
{
   var width = this.element.offsetWidth;
   var height = this.element.offsetHeight;
   return [width, height];
}
EVR.Component.prototype.set_coordinates = function(coordinates)
{
   if (coordinates[0] != null)
   {
      this.css.left = Math.round(coordinates[0]) + "px";
   }
   if (coordinates.length > 1)
   {
      this.css.top = Math.round(coordinates[1]) + "px";
   }
}   
EVR.Component.prototype.get_coordinates = function(ratio)
{
   var x = this.css.left ? parseFloat(this.css.left) : 0;
   var y = this.css.top ? parseFloat(this.css.top) : 0;
   if (ratio == true)
   {
      x = x / this.container.get_dimensions()[0];
      y = y / this.container.get_dimensions()[1];
   }
   return [x, y];
}
EVR.Component.prototype.get_parent_element = function()
{
   if (this.container == null)
   {
      return document.body;
   }
   if (this.container instanceof EVR.Component)
   {
      return this.container.element;
   }
   return this.container;
}
EVR.Component.prototype.toString = function()
{
   return "[object Component]";
}
EVR.Table = function(container, width, height)
{
   EVR.Component.call(this, container, "table");
   this.set_dimensions(width, height);
   this.set_margins();
   this.element.align = "center";
}
EVR.Table.prototype = new EVR.Component;
EVR.Table.prototype.set_dimensions = function()
{
   var css = this.css;
   if (!!arguments[0])
   {
      css.width = arguments[0];
   }
   if (!!arguments[1])
   {
      css.height = arguments[1];
   }
}
EVR.Table.prototype.set_margins = function()
{
   var element = this.element;
   element.cellSpacing = 0;
   element.cellPadding = 0;
}
EVR.Table.prototype.insert_row = function(index)
{
   var index = index == null ? -1 : index;
   return this.element.insertRow(index);
}
EVR.Table.prototype.insert_cell = function(row)
{
   if (!!!row)
   {
      row = this.row;
   }
   return row.insertCell(-1);
}
EVR.Table.prototype.get_rows = function()
{
   return this.element.rows;
}
EVR.Table.prototype.clear = function()
{
   while (this.element.rows.length > 0)
   {
      this.element.deleteRow(-1);
   }
}      
EVR.Table.prototype.toString = function()
{
   return "[object EVR.Table]";
}
184.73.55.221
184.73.55.221
184.73.55.221
 
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:


↠ RSS Feed ↞