//function for transform
var vertices,gl,buffer,shaderProgram;
function dotimer()
{ dorotate();
requestAnimationFrame(dotimer);
}
function doreset()
{
var elements = document.getElementsByTagName("input");
for (var ii=0; ii < elements.length; ii++) {
if (elements[ii].type == "text") {
elements[ii].value = "";
}
}
main();
}
function doscale()
{
// creating new vertices
var dx= parseFloat(document.getElementById("sx").value);
var dy= parseFloat(document.getElementById("sy").value);
for(i=0;i<6;i+=2)
{
vertices[i]*=dx;
vertices[i+1]*=dy;
}
main("transform",vertices)
}
function dotransform()
{
// creating new vertices
var dx= parseFloat(document.getElementById("x").value);
var dy= parseFloat(document.getElementById("y").value);
for(i=0;i<6;i+=2)
{
vertices[i]+=dx;
vertices[i+1]+=dy;
}
main("transform",vertices)
}
// function for rotation
function dorotate()
{
console.log("rotate");
var deg = parseFloat(document.getElementById("angle").value);
// console.log("rotate "+deg);
var radian = Math.PI * (deg/180.0);
for(i=0;i<6;i+=2)
{
var ox = vertices[i];
var oy = vertices[i+1];
var newv[];
newv[i] =ox +ox*Math.cos(radian) - oy*Math.sin(radian);
newv[i+1] = oy +ox*Math.sin(radian) + oy*Math.cos(radian);
}
console.log(newv);
main("rotate",newv) ;
}
function main(type,newvertices)
{
// Configure the canvas to use WebGL
//
var canvas = document.getElementById('mainCanvas');
try {
gl = canvas.getContext('experimental-webgl');
} catch (e) {
throw new Error('no WebGL found');
}
// Copy an array of data points forming a triangle to the
// graphics hardware
//
vertices = [
0.0, 0.0,
-0.5, 0.5,
-0.5, -0.5
];
buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
if (type!= null)
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.