<?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]";
}