/* * MouseModulator * Version 1.0, 09/10/2001 * * Copyright (c) 2001 by Netzministerium.de * Written by Till Nagel and René Sander. * Distributed under the terms of the GNU Lesser General Public. (See licence.txt for details) */ // constants var MAX_FRAME_NUMBER = 15; var TEST_VALUES = new Array(1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1/1.05, 1/1.05, 1/1.05, 1/1.05, 1/1.05, 1/1.05, 1/1.05, 1/1.05); /* * Constructs a HeartBeatModulator. * This modulator returns a scale matrix depending on the heartbeat-function. * * Input Parameters: * String maxFrameNumber - The number of frames to run through the function * */ function HeartBeatModulator(maxFrameNumber) { // sets the properties this.frameNumber = 0; this.maxFrameNumber = maxFrameNumber ? maxFrameNumber : MAX_FRAME_NUMBER; this.matrix = new Matrix(); // calulates and stores the values this.values = new Array(); var t = 0; var dt = (2 * Math.PI) / this.maxFrameNumber; // <- function specific // renders only first values [0 - n/2] (sin is symmetric funtion) for (i = 0; i <= (this.maxFrameNumber/2); i++) { t += dt; this.values[i] = (Math.sin(t) * 0.1 + 1.0); // <- function specific } // renders second values [n/2 - n] for (i = 0; i <= (this.maxFrameNumber/2); i++) { // renders reciprocal values this.values[i + Math.round((this.maxFrameNumber/2))] = 1 / this.values[i]; // <- function specific } // sets the methods this.getMatrix = HeartBeatModulatorGetMatrix; this.animate = HeartBeatModulatorAnimate; // returns this modulator return this; } /* * Returns the (scaling) matrix to transform with. * * Return Value: * The matrix to transform with. */ function HeartBeatModulatorGetMatrix() { return this.matrix; } function HeartBeatModulatorAnimate() { // sets current frameNumber to go through the values if (this.frameNumber < this.maxFrameNumber) this.frameNumber++; else this.frameNumber = 0; // gets scale value from prerendered array //var value = this.values[this.frameNumber]; var value = TEST_VALUES[this.frameNumber]; //if (this.frameNumber == this.maxFrameNumber) status = this.frameNumber + " = " + value; // sets scale matrix this.matrix = new Matrix(); this.matrix.scale(value, value, value); }