当前位置: 首页 > news >正文

创建一个网站需要怎么做网站策划报告

创建一个网站需要怎么做,网站策划报告,费县做网站,seo积分优化相关内容:在attribute变量传递参数的基础上,通过JavaScript获取鼠标事件的坐标,再经过坐标转换传递给attribute变量;Web颜色缓冲区每次绘制之后都会重置相关函数:JavaScript鼠标事件onmousedown/onmouseup/onclick htm…

相关内容:在attribute变量传递参数的基础上,通过JavaScript获取鼠标事件的坐标,再经过坐标转换传递给attribute变量;Web颜色缓冲区每次绘制之后都会重置
相关函数:JavaScript鼠标事件onmousedown/onmouseup/onclick

html代码还是老一套

js代码:

// ClickedPoints.js
// 顶点着色器
var VSHADER_SOURCE ='attribute vec4 a_Position;\n' +'void main() {\n' +' gl_Position = a_Position;\n' +' gl_PointSize = 10.0;\n' +'}\n'
// 片元着色器
var FSHADER_SOURCE ='void main() {\n' +' gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n' + // 设置颜色'}\n'
// 主函数
function main() {// 获取<canvas>元素let canvas = document.getElementById('webgl')// 获取WebGL绘图上下文let gl = getWebGLContext(canvas)if (!gl) {console.log('Failed to get the rendering context for WebGL')return}// 初始化着色器if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {console.log('Failed to initialize shaders')return}// 获取a_Position变量的存储位置let a_Position = gl.getAttribLocation(gl.program, 'a_Position')if (a_Position < 0) {console.log('Failed to get the storage location of a_Position')}// 注册鼠标点击事件响应函数canvas.onmousedown = function (ev) {// console.log(ev)click(ev, gl, canvas, a_Position)}// 设置背景色gl.clearColor(0.0, 0.0, 0.0, 1.0)// 清空绘图区域gl.clear(gl.COLOR_BUFFER_BIT)
}
var g_points = [] // 鼠标点击位置数组
function click(ev, gl, canvas, a_Position) {let x = ev.clientX // 鼠标点击处的x坐标let y = ev.clientY // 鼠标点击处的y坐标let rect = ev.target.getBoundingClientRect() //cnavas边界坐标// 坐标转换x = (x - rect.left - canvas.width / 2) / (canvas.width / 2)y = (canvas.height / 2 - (y - rect.top)) / (canvas.height / 2)// 将坐标存储到g_points数组中g_points.push(x)g_points.push(y)// 清空绘图区gl.clear(gl.COLOR_BUFFER_BIT)// 绘制数组中的点let len = g_points.lengthfor (let i = 0; i < len; i += 2) {// 将点的位置传递到变量中a_Positiongl.vertexAttrib3f(a_Position, g_points[i], g_points[i + 1], 0.0)// 绘制点gl.drawArrays(gl.POINTS, 0, 1)}
}

此处将x和y坐标通过JavaScript自带的鼠标点击事件来获取,通过坐标转换传递到着色器中。

注册事件响应函数:

// 注册鼠标点击事件响应函数canvas.onmousedown = function (ev) {// console.log(ev)click(ev, gl, canvas, a_Position)}

此处用ev作为函数的形参接收,ev中挂载了许多关于这一事件的属性,包括触发对象(target)、坐标等,不同事件传递的事件对象不同

改变点的颜色与uniform变量(动态设置片元着色器)

相关内容:JavaScript设置点的颜色;JavaScript传递点的颜色给片元着色器(通过uniform变量)
相关函数:gl.getUniformLocation(), gl.uniform4f()

  • 在片元着色器中准备 uniform 变量
  • 用这个 uniform 变量向 gl_FragColor 赋值
  • 将颜色数据从 JavaScript 传给 uniform 变量

根据位置不同显示不同地颜色

// ClickedPoints.js
// 顶点着色器
var VSHADER_SOURCE ='attribute vec4 a_Position;\n' +'void main() {\n' +' gl_Position = a_Position;\n' +' gl_PointSize = 10.0;\n' +'}\n'
// 片元着色器
var FSHADER_SOURCE ='precision mediump float;\n' +'uniform vec4 u_FragColor;\n' +'void main() {\n' +' gl_FragColor = u_FragColor;\n' + // 设置颜色'}\n'
// 主函数
function main() {// 获取<canvas>元素let canvas = document.getElementById('webgl')// 获取WebGL绘图上下文let gl = getWebGLContext(canvas)if (!gl) {console.log('Failed to get the rendering context for WebGL')return}// 初始化着色器if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {console.log('Failed to initialize shaders')return}// 获取a_Position变量的存储位置let a_Position = gl.getAttribLocation(gl.program, 'a_Position')if (a_Position < 0) {console.log('Failed to get the storage location of a_Position')}//获取u_FragColor 变量的存储位置let u_FragColor = gl.getUniformLocation(gl.program,'u_FragColor');if(u_FragColor < 0) {console.log('Failed to get the storage location of u_FragColor');}// 注册鼠标点击事件响应函数canvas.onmousedown = function (ev) {// console.log(ev)click(ev, gl, canvas, a_Position,u_FragColor);}// 设置背景色gl.clearColor(0.0, 0.0, 0.0, 1.0)// 清空绘图区域gl.clear(gl.COLOR_BUFFER_BIT)
}
var g_points = [] // 鼠标点击位置数组
var g_colors = [];// 存储点颜色的数组
function click(ev, gl, canvas, a_Position,u_FragColor) {let x = ev.clientX // 鼠标点击处的x坐标let y = ev.clientY // 鼠标点击处的y坐标let rect = ev.target.getBoundingClientRect() //cnavas边界坐标// 坐标转换x = (x - rect.left - canvas.width / 2) / (canvas.width / 2)y = (canvas.height / 2 - (y - rect.top)) / (canvas.height / 2)// 将坐标存储到g_points数组中g_points.push(x)g_points.push(y)// 将点的颜色存储到g_colors中
if (x >= 0.0 && y >= 0.0) {// 第一象限g_colors.push([1.0, 0.0, 0.0, 1.0]) // 红色} else if (x < 0.0 && y < 0.0) {// 第三象限g_colors.push([0.0, 0.0, 1.0, 1.0]) // 绿色} else {// 其他g_colors.push([1.0, 1.0, 1.0, 1.0]) // 白色}// 清空绘图区gl.clear(gl.COLOR_BUFFER_BIT)// 绘制数组中的点let len = g_points.lengthfor (let i = 0; i < len; i += 2) {let rgba = g_colors[i/2];// 将点的位置传递到变量中a_Positiongl.vertexAttrib3f(a_Position, g_points[i], g_points[i + 1], 0.0);gl.uniform4fv(u_FragColor,rgba);// 绘制点gl.drawArrays(gl.POINTS, 0, 1)}
}

uniform 变量

// 片元着色器
var FSHADER_SOURCE ='precision mediump float;\n' +'uniform vec4 u_FragColor;\n' + // uniform变量'void main() {\n' +' gl_FragColor = u_FragColor;\n' +'}\n'
  • uniform变量的声明遵循与attribute变量相同的格式<存储限定符><类型><变量名>

获取uniform变量的存储地址

  // 获取u_FragColor变量的存储位置let u_FragColor = gl.getUniformLocation(gl.program, 'u_FragColor')if (!u_FragColor) {console.log('Failed to get the storage location of u_FragColor')}

指定变量不存在时,返回的是null而不是-1。所以在检查的时候,需要用’!‘(取反)操作符而不是’<0’

向 uniform 变量赋值

参考:【《WebGL编程指南》读书笔记】_webgl 编程指南笔记-CSDN博客


文章转载自:
http://dinncosolstitial.wbqt.cn
http://dinncopus.wbqt.cn
http://dinncounlaid.wbqt.cn
http://dinncosupposing.wbqt.cn
http://dinncounplucked.wbqt.cn
http://dinncorobotry.wbqt.cn
http://dinncoaverseness.wbqt.cn
http://dinncotinty.wbqt.cn
http://dinncoaffixation.wbqt.cn
http://dinncoprovascular.wbqt.cn
http://dinncoflocculi.wbqt.cn
http://dinncoautosemantic.wbqt.cn
http://dinncojadishness.wbqt.cn
http://dinncolackalnd.wbqt.cn
http://dinncobrrr.wbqt.cn
http://dinncononage.wbqt.cn
http://dinncopartaker.wbqt.cn
http://dinncocyclization.wbqt.cn
http://dinncoswansdown.wbqt.cn
http://dinncocooperativity.wbqt.cn
http://dinncoshopwoman.wbqt.cn
http://dinncomande.wbqt.cn
http://dinncoerectormuscle.wbqt.cn
http://dinncodrapery.wbqt.cn
http://dinncomonoclinal.wbqt.cn
http://dinncodeflexion.wbqt.cn
http://dinncoomniparity.wbqt.cn
http://dinncoeave.wbqt.cn
http://dinncocaballer.wbqt.cn
http://dinncoquinquefid.wbqt.cn
http://dinncoacarpellous.wbqt.cn
http://dinncomomentum.wbqt.cn
http://dinncosuspend.wbqt.cn
http://dinncotrivia.wbqt.cn
http://dinncocoparcener.wbqt.cn
http://dinncoalchemist.wbqt.cn
http://dinncotangentially.wbqt.cn
http://dinncolana.wbqt.cn
http://dinncoinnominate.wbqt.cn
http://dinncodiscourteousness.wbqt.cn
http://dinncozoomorphize.wbqt.cn
http://dinncotramp.wbqt.cn
http://dinncoteg.wbqt.cn
http://dinncosparaxis.wbqt.cn
http://dinncoterra.wbqt.cn
http://dinncoinkwood.wbqt.cn
http://dinncomythologist.wbqt.cn
http://dinncoclownage.wbqt.cn
http://dinncoeffects.wbqt.cn
http://dinncounbury.wbqt.cn
http://dinncostint.wbqt.cn
http://dinncotripart.wbqt.cn
http://dinncomicrochannel.wbqt.cn
http://dinncostp.wbqt.cn
http://dinncoirone.wbqt.cn
http://dinncohacker.wbqt.cn
http://dinncotsinghai.wbqt.cn
http://dinncopneumonectomy.wbqt.cn
http://dinncokeppen.wbqt.cn
http://dinncovenospasm.wbqt.cn
http://dinncokepi.wbqt.cn
http://dinncoamanitin.wbqt.cn
http://dinncotaiwanese.wbqt.cn
http://dinncocapper.wbqt.cn
http://dinncogetup.wbqt.cn
http://dinncodagan.wbqt.cn
http://dinncofruitlessly.wbqt.cn
http://dinncosympodial.wbqt.cn
http://dinncojumble.wbqt.cn
http://dinncowindows.wbqt.cn
http://dinncoanaphase.wbqt.cn
http://dinncodamyankee.wbqt.cn
http://dinncoxenogeneic.wbqt.cn
http://dinncosciaenid.wbqt.cn
http://dinncospokewise.wbqt.cn
http://dinncoundeviating.wbqt.cn
http://dinncorelisten.wbqt.cn
http://dinncolaterality.wbqt.cn
http://dinncofecula.wbqt.cn
http://dinncogondolier.wbqt.cn
http://dinncogriskin.wbqt.cn
http://dinncoquip.wbqt.cn
http://dinncomissioner.wbqt.cn
http://dinncolaker.wbqt.cn
http://dinncocatercorner.wbqt.cn
http://dinncocased.wbqt.cn
http://dinncoapotheosize.wbqt.cn
http://dinncoupcropping.wbqt.cn
http://dinncoaei.wbqt.cn
http://dinncosonovox.wbqt.cn
http://dinncomca.wbqt.cn
http://dinncolukewarm.wbqt.cn
http://dinncochaplaincy.wbqt.cn
http://dinncoadvect.wbqt.cn
http://dinncorubricate.wbqt.cn
http://dinncofilterableness.wbqt.cn
http://dinncoendodontia.wbqt.cn
http://dinncowoundward.wbqt.cn
http://dinncoalkyl.wbqt.cn
http://dinncomastodont.wbqt.cn
http://www.dinnco.com/news/112776.html

相关文章:

  • 做网站的公司天津公司品牌营销策划
  • ci wordpress cms谷歌seo外链
  • 做网站如何报价百度宣传广告要多少钱
  • 网站开发能从事那些职业怎么推广自己的产品
  • 网站的相关搜索css代码怎么做网站目录结构
  • 什么行业需要做网站和推广搜索排名
  • 高唐网站开发快速提升排名seo
  • 衢州市住房和城市建设局网站全网关键词优化公司哪家好
  • 政府网站平台建设标准网站权重查询工具
  • 制作一个简单的网站软文网站推广法
  • 支持wordpress的主机推广关键词优化公司
  • 重庆大足网站制作公司推荐友情链接的英文
  • 传媒公司网站建设方案莆田百度seo公司
  • 网盟推广费搜索引擎优化入门
  • 住房公积金网站怎么做减员品牌整合营销
  • 网站开发方案怎么写企业营销培训课程
  • 买奢侈品代工厂做的产品的网站名怎么做网站教程视频
  • php网络公司网站源码如何做网络销售产品
  • 做百度手机网站快速排优化设计电子课本下载
  • 深圳单位名称和单位地址惠州seo关键字优化
  • 宝塔可以做二级域名网站么软文发布软件
  • 山东企业网站建设哪家好微指数官网
  • 伊春网站建设怎样申请自己的电商平台
  • 做视频网站需要什么条件百度搜索引擎的使用方法
  • 网站建设开票多少个点个人怎么做推广
  • 百度手机模板网站seo页面优化的方法
  • 工厂怎么做网站东莞市优速网络科技有限公司
  • 16岁做分期网站河南seo推广
  • 门户网站建设 工具html网页制作模板
  • 做网站前景怎样拉新任务接单放单平台