attribute vec4 vStartPosition; attribute vec4 vEndPosition; attribute vec4 vColor; uniform float percent; varying vec4 f_Color; void main() { float fixedPct; fixedPct = clamp(percent, 0.0, 1.0); gl_Position = mix(vStartPosition, vEndPosition, fixedPct); f_Color = vColor; }
Animate <label class="switch"> <input type="checkbox" onclick="ChangeAnimationState(canvas)"> </label>
AnimationStep: function() { this.pct += this.pctStep; if (this.pct >= 1.0) { this.pct = 1.0; this.pctStep *= -1; } if (this.pct <= 0.0) { this.pct = 0.0; this.pctStep *= -1; } this.gl.uniform1f(this.pctLoc, this.pct); this.Redisplay(); },
var cheatContext; function MakeCanvas(width, height, locID) {
cheatContext = this; return this; }
function ChangeAnimationState() { cheatContext.animationState = !cheatContext.animationState; if (cheatContext.animationState) { setTimeout(NextAnimationStep, 20); } }; function NextAnimationStep() { cheatContext.AnimationStep(); if (cheatContext.animationState) { var delay = Math.abs(cheatContext.pct-0.5); setTimeout(NextAnimationStep, 20+150*delay); } };
// this is new. Get the location to send pct this.pctLoc = gl.getUniformLocation(program, "percent"); this.pct = 0; this.pctStep = 0.01; gl.uniform1f(this.pctLoc, this.pct);