webgl动画小测试
// MultiPoint.js (c) 2012 matsuda
// Vertex shader program
var VSHADER_SOURCE =
'attribute vec4 a_Position;\n' +
'void main() {\n' +
' gl_Position = a_Position;\n' +
' gl_PointSize = 10.0;\n' +
'}\n'; // Fragment shader program
var FSHADER_SOURCE =
'precision mediump float;\n' +
'void main() {\n' + // Center coordinate is (0.5, 0.5)
' float d = distance(gl_PointCoord, vec2(0.5, 0.5));\n' +
' if(d < 0.6) {\n' + // Radius is 0.5
' gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n' +
' } else {discard;}\n' +
'}\n'; function main() {
// Retrieve <canvas> element
var canvas = document.getElementById('webgl'); // Get the rendering context for WebGL
var gl = getWebGLContext(canvas);
if (!gl) {
console.log('Failed to get the rendering context for WebGL');
return;
} // Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
console.log('Failed to intialize shaders.');
return;
} // Write the positions of vertices to a vertex shader
var n = initVertexBuffers(gl);
if (n < 0) {
console.log('Failed to set the positions of the vertices');
return;
} // Specify the color for clearing <canvas>
gl.clearColor(0, 0, 0, 1); // Clear <canvas>
gl.clear(gl.COLOR_BUFFER_BIT); // Draw three points var g_init = Date.now();
var speed = 20;
function pointCount() {
var now = Date.now();
var count = (now - g_init) * (speed * 0.001 )
if (count > n) {
return n
}
else if (count<1){
return 1;
}
else {
return count;
}
} var tick = function() {
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.POINTS, 0, pointCount());
requestAnimationFrame(tick);
};
tick();
} function initVertexBuffers(gl) {
var vertices = new Float32Array([
-0.9, 0.0, -0.8, 0.0, -0.7, 0.0,
-0.6, 0.0, -0.5, 0.0, -0.4, 0.0,
-0.3, 0.0, -0.2, 0.0, -0.1, 0.0,
0.0, 0.0,
0.0, -0.1, 0.0, -0.2, 0.0, -0.3,
0.0, -0.4, 0.0, -0.5, 0.0, -0.6,
0.0, -0.7, 0.0, -0.8, 0.0, -0.9
]);
var n = 19; // The number of vertices // Create a buffer object
var vertexBuffer = gl.createBuffer();
if (!vertexBuffer) {
console.log('Failed to create the buffer object');
return -1;
} // Bind the buffer object to target
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
// Write date into the buffer object
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); var a_Position = gl.getAttribLocation(gl.program, 'a_Position');
if (a_Position < 0) {
console.log('Failed to get the storage location of a_Position');
return -1;
}
// Assign the buffer object to a_Position variable
gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0); // Enable the assignment to a_Position variable
gl.enableVertexAttribArray(a_Position); return n;
}
webgl动画小测试的更多相关文章
- CSS3、SVG、Canvas、WebGL动画精选整理
一.CSS3动画 名称 用途 链接 阴影波纹特效 1.元素hover效果 2.突出表现效果 http://www.jq22.com/code80 横板导航菜单动画 导航菜单 http://www.jq ...
- WebGL入门教程(三)-webgl动画
前面文章: WebGL入门教程(一)-初识webgl WebGL入门教程(二)-webgl绘制三角形 WebGL动画有移动.旋转和缩放,我们将移动.旋转和缩放图形,然后将其绘制到屏幕上,称为变换(tr ...
- Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试
CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果, ...
- shell脚本动画小工具
shell脚本动画小工具 看gif图: shell脚本版 脚本内容如下: #!/usr/bin/env bash ## ---------------------------------------- ...
- python 程序小测试
python 程序小测试 对之前写的程序做简单的小测试 ... # -*- encoding:utf-8 -*- ''' 对所写程序做简单的测试 @author: bpf ''' def GameOv ...
- PHP中使用PDO操作事务的一些小测试
关于事务的问题,我们就不多解释了,以后在学习 MySQL 的相关内容时再深入的了解.今天我们主要是对 PDO 中操作事务的一些小测试,或许能发现一些比较好玩的内容. 在 MyISAM 上使用事务会怎么 ...
- webGL动画
在做这个项目之前,我也和很多人的想法一样觉得:H5做动画性能不行,只能完成简单动画,可是事实并非如此.所以借此篇分享振奋下想在H5下做酷炫游戏的人心. 体验游戏请长按二维码识别: 好吧,知道你懒.不想 ...
- HTTP性能小测试
一直说node.js如何如何好,就来测试一下吧~~ 首先接受一个小工具 Apache Bench简称ab 可以用来测试http性能 利用Apache Bench测试Web引擎性能关于此工具的详细介绍参 ...
- iOS开发——UI进阶篇(十八)核心动画小例子,转盘(裁剪图片、自定义按钮、旋转)图片折叠、音量震动条、倒影、粒子效果
一.转盘(裁剪图片.自定义按钮.旋转) 1.裁剪图片 将一张大图片裁剪为多张 // CGImageCreateWithImageInRect:用来裁剪图片 // image:需要裁剪的图片 // re ...
随机推荐
- Dagger2系列之使用方法
本系列只讲使用方法和使用中遇到的问题,如果还对dagger2还不了解的童鞋儿可以参考文章: http://www.jianshu.com/p/cd2c1c9f68d4 http://www.jians ...
- 代码的坏味道(5)——数据泥团(Data Clumps)
坏味道--数据泥团(Data Clumps) 特征 有时,代码的不同部分包含相同的变量组(例如用于连接到数据库的参数).这些绑在一起出现的数据应该拥有自己的对象. 问题原因 通常,数据泥团的出现时因为 ...
- oracle函数案例以及分页案例
--日期函数select sysdate from dual--返回两个日期select months_between(to_date('2017-1-7','yyyy-mm-dd'),to_date ...
- Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端
0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...
- SQL Server Management Studio 无法修改表,超时时间已到 在操作完成之前超时时
在修改表时,保存的时候显示:无法修改表,超时时间已到 在操作完成之前超时时间已过或服务器未响应 这是执行时间设置过短的原因,可以修改一下设置便能把执行时间加长,以便有足够的时间执行完修改动作. 在 S ...
- asp.net DataTable导出Excel 自定义列名
1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...
- MongoDB初识
参考: MongoDB资料汇总专题:
- 【转译】加入ZigBee联盟,共画物联网的未来
Zigbee联盟是物联网全球革命的领导者,创造了随心控制的时代.Zigbee简化了无线产品的整合.加快了市场化,同时让那些希望引入高能效的无线控制的厂商,降低了成本和风险.我们的联盟成员在开放的全球环 ...
- SPI 2分频MOSI实现
module spi_25M(input clk,input rst_n,output reg sdin,output reg sclk,output reg cs);reg [7:0]cnt;reg ...
- Struts2框架深入详解版
一.认识Struts2 1. 什么是Web框架? 1.1 模型1 1.2 模型2 和MVC 1.3 Web框架的诞生 2. Struts1 到Struts2 2.1 其他 Web框架 2.2 ...