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]";
}
23.20.219.0
23.20.219.0
23.20.219.0
 
January 28, 2014


E F F L U E N C E


↠ RSS Feed ↞