jmgraph 3.2.16 → 3.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +251 -428
- package/build/gulpfile.js +142 -142
- package/build/package-lock.json +10666 -0
- package/build/package.json +71 -71
- package/dev.js +9 -9
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3500 -2668
- package/dist/jmgraph.min.js +1 -1
- package/example/ball.html +216 -216
- package/example/base.html +111 -111
- package/example/canvas.html +53 -53
- package/example/cell.html +283 -283
- package/example/controls/arc.html +128 -128
- package/example/controls/arrowline.html +77 -77
- package/example/controls/bezier.html +298 -298
- package/example/controls/img.html +96 -96
- package/example/controls/label.html +86 -86
- package/example/controls/line.html +172 -172
- package/example/controls/prismatic.html +62 -62
- package/example/controls/rect.html +63 -63
- package/example/controls/resize.html +111 -111
- package/example/controls/test.html +359 -359
- package/example/es.html +69 -69
- package/example/es5module.html +62 -63
- package/example/heartarc.html +115 -115
- package/example/index.html +46 -46
- package/example/js/require.js +4 -4
- package/example/love/img/bling/bling.tps +265 -265
- package/example/love/img/bling.json +87 -87
- package/example/love/img/bling.tps +295 -295
- package/example/love/img/love.json +95 -95
- package/example/love/img/love.tps +315 -315
- package/example/love/img/qq/qq.tps +399 -399
- package/example/love/img/qq.json +242 -242
- package/example/love/index.html +40 -40
- package/example/love/js/game.js +558 -558
- package/example/music.html +210 -210
- package/example/node/test.js +137 -137
- package/example/pdf.html +186 -186
- package/example/progress.html +172 -172
- package/example/pso.html +147 -147
- package/example/sort.html +804 -815
- package/example/tweenjs.html +83 -83
- package/example/webgl.html +278 -278
- package/example/xfj/index.html +331 -331
- package/example/xfj/shake.js +48 -48
- package/example/xfj/testori.html +75 -75
- package/index.js +99 -99
- package/package.json +58 -56
- package/src/core/jmControl.js +1376 -1531
- package/src/core/jmEvents.js +240 -281
- package/src/core/jmGradient.js +231 -231
- package/src/core/jmGraph.js +569 -569
- package/src/core/jmList.js +92 -157
- package/src/core/jmObject.js +83 -103
- package/src/core/jmPath.js +35 -35
- package/src/core/jmProperty.js +71 -110
- package/src/core/jmShadow.js +65 -65
- package/src/core/jmUtils.js +906 -919
- package/src/lib/earcut.js +680 -680
- package/src/lib/earcut.md +73 -73
- package/src/lib/webgl/base.js +522 -452
- package/src/lib/webgl/core/buffer.js +48 -48
- package/src/lib/webgl/core/mapSize.js +40 -40
- package/src/lib/webgl/core/mapType.js +43 -43
- package/src/lib/webgl/core/program.js +138 -138
- package/src/lib/webgl/core/shader.js +13 -13
- package/src/lib/webgl/core/texture.js +60 -60
- package/src/lib/webgl/gradient.js +168 -168
- package/src/lib/webgl/index.js +137 -11
- package/src/lib/webgl/path.js +568 -561
- package/src/shapes/jmArrowLine.js +36 -36
- package/src/shapes/jmImage.js +244 -244
- package/src/shapes/jmLabel.js +271 -271
- package/src/shapes/jmResize.js +332 -330
package/example/webgl.html
CHANGED
|
@@ -1,278 +1,278 @@
|
|
|
1
|
-
<body>
|
|
2
|
-
<canvas id="cvs" width="600" height="600" style="border: dashed 1px red">
|
|
3
|
-
你的浏览器不支持画布元素
|
|
4
|
-
</canvas>
|
|
5
|
-
<canvas id="cvs2d" width="600" height="600" style="border: dashed 1px red">
|
|
6
|
-
你的浏览器不支持画布元素
|
|
7
|
-
</canvas>
|
|
8
|
-
<script type="module">
|
|
9
|
-
import {
|
|
10
|
-
createProgram,
|
|
11
|
-
writeVertexAttrib
|
|
12
|
-
} from '../src/lib/webgl/core/program.js';
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
createFloat32Buffer,
|
|
16
|
-
createUint16Buffer,
|
|
17
|
-
deleteBuffer,
|
|
18
|
-
} from '../src/lib/webgl/core/buffer.js';
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
create2DTexture
|
|
22
|
-
} from '../src/lib/webgl/core/texture.js';
|
|
23
|
-
|
|
24
|
-
//获取画布元素
|
|
25
|
-
var cvs = document.getElementById('cvs');
|
|
26
|
-
//获取到元素的上下文环境对象
|
|
27
|
-
var gl = cvs.getContext('webgl');
|
|
28
|
-
|
|
29
|
-
const width = gl.canvas.width;
|
|
30
|
-
const height = gl.canvas.height;
|
|
31
|
-
gl.viewport(0, 0, width, height)
|
|
32
|
-
// 设置 webgl 视口,将 -1 到 1 映射为 canvas 上的坐标
|
|
33
|
-
const program = createProgram(gl, `
|
|
34
|
-
attribute vec4 a_position;
|
|
35
|
-
attribute vec2 aPointIndex;
|
|
36
|
-
attribute vec4 aColor;
|
|
37
|
-
attribute vec2 aTextCoord;
|
|
38
|
-
uniform vec2 aCenterPoint;
|
|
39
|
-
uniform vec2 aLineStart;
|
|
40
|
-
uniform vec2 aLineEnd;
|
|
41
|
-
uniform float aTotalPointCount;
|
|
42
|
-
varying vec4 vColor;
|
|
43
|
-
varying vec2 vTextCoord;
|
|
44
|
-
|
|
45
|
-
vec4 translatePosition(in vec4 point, float x, float y) {
|
|
46
|
-
point.x = (point.x-x)/x;
|
|
47
|
-
point.y = (y-point.y)/y;
|
|
48
|
-
return point;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
vec4 pointToPos(vec2 start, vec2 end, float index) {
|
|
52
|
-
float len = sqrt(pow(end.x - start.x, 2.0) + pow(end.y - start.y, 2.0));
|
|
53
|
-
|
|
54
|
-
float x = start.x + (end.x - start.x)/10.0 * index;
|
|
55
|
-
float y = start.y + (end.y - start.y)/10.0 * index;
|
|
56
|
-
return vec4(x, y, 0.0, 0.0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
vec4 ceilPosition(vec4 pos) {
|
|
60
|
-
return vec4(pos.xy/10000.0, pos.zw);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
void main() {
|
|
64
|
-
gl_PointSize = 10.0;
|
|
65
|
-
//vec4 pos = pointToPos(aLineStart, aLineEnd, aPointIndex.x);
|
|
66
|
-
vec4 pos = ceilPosition(a_position);//translatePosition(a_position, aCenterPoint.x, aCenterPoint.y);
|
|
67
|
-
gl_Position = pos;
|
|
68
|
-
vColor = aColor;
|
|
69
|
-
vTextCoord = aTextCoord;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
`,`
|
|
73
|
-
precision highp float;
|
|
74
|
-
uniform vec4 u_color;
|
|
75
|
-
uniform sampler2D uSample;
|
|
76
|
-
varying vec4 vColor;
|
|
77
|
-
varying vec2 vTextCoord;
|
|
78
|
-
|
|
79
|
-
void main() {
|
|
80
|
-
//float r = distance(gl_PointCoord, vec2(0.5, 0.5));
|
|
81
|
-
//根据距离设置片元
|
|
82
|
-
//if(r <= 0.5){
|
|
83
|
-
// 方形区域片元距离几何中心半径小于0.5,像素颜色设置红色
|
|
84
|
-
gl_FragColor = u_color;
|
|
85
|
-
//}else {
|
|
86
|
-
// 方形区域距离几何中心半径不小于0.5的片元剪裁舍弃掉:
|
|
87
|
-
// discard;
|
|
88
|
-
//}
|
|
89
|
-
//gl_FragColor = u_color;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
`);
|
|
93
|
-
//texture2D(uSample, vTextCoord)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const colors = [Math.random(),Math.random(),Math.random(),1];
|
|
98
|
-
let points = [6667, 0, 5851, 3196, 3602, 5610, 472, 5555, 680];
|
|
99
|
-
const uvpoints = [];
|
|
100
|
-
|
|
101
|
-
const center = {
|
|
102
|
-
x: width / 2,
|
|
103
|
-
y: height / 2
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
let colorStop = [Math.random(),Math.random(),Math.random(),1];
|
|
108
|
-
for(let r=0; r<=Math.PI*2;r += 0.5) {
|
|
109
|
-
const cos = Math.cos(r);
|
|
110
|
-
const sin = Math.sin(r);
|
|
111
|
-
const x = (cos * 200) + center.x;
|
|
112
|
-
const y = (sin * 200) + center.y;
|
|
113
|
-
//points.push(Number(((cos * 200)/center.x).toFixed(4)), Number(((sin * 200) / center.y).toFixed(4)));
|
|
114
|
-
let ux = (cos + 1)/2;
|
|
115
|
-
//if(ux < 0.5) ux = ux/2;
|
|
116
|
-
|
|
117
|
-
let uy = (sin + 1) / 2;
|
|
118
|
-
//if(uy < 0.5) uy = uy/2;
|
|
119
|
-
|
|
120
|
-
uvpoints.push(ux, uy);
|
|
121
|
-
colors.push(...colorStop);
|
|
122
|
-
}
|
|
123
|
-
//points.push(points[0], points[1]);
|
|
124
|
-
//uvpoints.push(uvpoints[0], uvpoints[1]);
|
|
125
|
-
//colors.push(...colorStop);
|
|
126
|
-
|
|
127
|
-
/*
|
|
128
|
-
colorStop = [Math.random(),Math.random(),Math.random(),1];
|
|
129
|
-
const lastLen = points.length;
|
|
130
|
-
for(let r=0; r<=Math.PI*2;r += 0.1) {
|
|
131
|
-
points.push((Math.cos(r) * 200) / center.x, (Math.sin(r) * 200) / center.y);
|
|
132
|
-
colors.push(...colorStop);
|
|
133
|
-
}
|
|
134
|
-
points.push(points[lastLen], points[lastLen+1]);
|
|
135
|
-
colors.push(...colorStop);*/
|
|
136
|
-
|
|
137
|
-
if(program.uniforms.u_color) {
|
|
138
|
-
//const colorLocation = gl.getUniformLocation(program.program, 'u_color') // 获取 u_color 变量位置
|
|
139
|
-
gl.uniform4f(program.uniforms.u_color.location, 0.0, 1.0, 0.0, 1) // 设置它的值
|
|
140
|
-
}
|
|
141
|
-
if(program.uniforms.aLineEnd) {
|
|
142
|
-
gl.uniform2f(program.uniforms.aLineEnd.location, 100.0, 50.0) // 设置它的值
|
|
143
|
-
}
|
|
144
|
-
if(program.uniforms.aLineStart) {
|
|
145
|
-
gl.uniform2f(program.uniforms.aLineStart.location, 305.0, 500.0) // 设置它的值
|
|
146
|
-
}
|
|
147
|
-
if(program.uniforms.aTotalPointCount) {
|
|
148
|
-
gl.uniform1f(program.uniforms.aTotalPointCount.location, 100); // 设置它的值
|
|
149
|
-
}
|
|
150
|
-
if(program.uniforms.aCenterPoint) {
|
|
151
|
-
gl.uniform2f(program.uniforms.aCenterPoint.location, center.x, center.y); // 设置它的值
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//先创建一个缓存对象
|
|
155
|
-
if(program.attrs.a_position) {
|
|
156
|
-
var vertexBuffer = createFloat32Buffer(gl, points);
|
|
157
|
-
writeVertexAttrib(gl, vertexBuffer, program.attrs.a_position, 2, 0, 0);
|
|
158
|
-
//deleteBuffer(gl, vertexBuffer);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if(program.attrs.aPointIndex) {
|
|
162
|
-
const pointIndexs = [];
|
|
163
|
-
for(let i=0;i<100;i++) {
|
|
164
|
-
pointIndexs.push(i);
|
|
165
|
-
}
|
|
166
|
-
var pointIndexBuffer = createFloat32Buffer(gl, pointIndexs);
|
|
167
|
-
writeVertexAttrib(gl, pointIndexBuffer, program.attrs.aPointIndex, 1, 0, 0);
|
|
168
|
-
}
|
|
169
|
-
//先创建一个缓存对象
|
|
170
|
-
var colorBuffer = createFloat32Buffer(gl, colors);
|
|
171
|
-
writeVertexAttrib(gl, colorBuffer, program.attrs.aColor, 4, 4, 0);
|
|
172
|
-
//deleteBuffer(gl, colorBuffer);
|
|
173
|
-
//const aTextCoord = gl.getAttribLocation(program, 'aTextCoord');
|
|
174
|
-
//const uSample = gl.getUniformLocation(program, 'uSample');
|
|
175
|
-
|
|
176
|
-
//先创建一个缓存对象
|
|
177
|
-
//var textCoordBuffer = createFloat32Buffer(gl, uvpoints);
|
|
178
|
-
//writeVertexAttrib(gl, textCoordBuffer, program.attrs.aTextCoord, 2, 2, 0);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// 纹理
|
|
182
|
-
/*var img = new Image();
|
|
183
|
-
|
|
184
|
-
img.onload = function(){
|
|
185
|
-
draw();
|
|
186
|
-
};
|
|
187
|
-
img.src = 'qrcode.jpg';*/
|
|
188
|
-
|
|
189
|
-
//points = [-0.8, 0.5, 0, 0.5,0.6,0,0,-0.6, -0.5];
|
|
190
|
-
|
|
191
|
-
draw();
|
|
192
|
-
|
|
193
|
-
function draw() {
|
|
194
|
-
/*var texture = create2DTexture(gl, img);
|
|
195
|
-
|
|
196
|
-
if(program.uniforms.uSample) {
|
|
197
|
-
gl.uniform1i(program.uniforms.uSample.location, 0) // 纹理单元传递给着色器
|
|
198
|
-
}*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
gl.clearColor(1, 1, 1, 1) // 设置清空颜色缓冲时的颜色值
|
|
205
|
-
gl.clear(gl.COLOR_BUFFER_BIT) // 清空颜色缓冲区,也就是清空画布
|
|
206
|
-
|
|
207
|
-
if(program.uniforms.u_color) {
|
|
208
|
-
gl.uniform4f(program.uniforms.u_color.location, Math.random(), Math.random(), Math.random(), 1) // 设置它的值
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
vertexBuffer = createFloat32Buffer(gl, points);
|
|
212
|
-
writeVertexAttrib(gl, vertexBuffer, program.attrs.a_position, 2, 0, 0);
|
|
213
|
-
|
|
214
|
-
/*gl.drawArrays( // 从数组中绘制图元
|
|
215
|
-
gl.TRIANGLES, // 渲染三角形
|
|
216
|
-
0, // 从数组中哪个点开始渲染
|
|
217
|
-
3 // 需要用到多少个点,三角形的三个顶点
|
|
218
|
-
);
|
|
219
|
-
gl.drawArrays( // 从数组中绘制图元
|
|
220
|
-
gl.TRIANGLES, // 渲染三角形
|
|
221
|
-
3, // 从数组中哪个点开始渲染
|
|
222
|
-
3 // 需要用到多少个点,三角形的三个顶点
|
|
223
|
-
);*/
|
|
224
|
-
//gl.drawArrays(gl.TRIANGLE, 0, points.length/2);
|
|
225
|
-
gl.drawArrays(gl.LINE_STRIP, 0, points.length/2);
|
|
226
|
-
//gl.drawArrays(gl.TRIANGLE_STRIP, 0, points.length/2);
|
|
227
|
-
//gl.drawArrays(gl.LINE_STRIP, 0, points.length/2);
|
|
228
|
-
//gl.drawArrays(gl.LINE_LOOP, 0, points.length/2);
|
|
229
|
-
//gl.drawArrays(gl.POINTS, 0, points.length/2);
|
|
230
|
-
//gl.drawArrays(gl.LINES, 0, points.length/2);
|
|
231
|
-
|
|
232
|
-
//deleteBuffer(gl, vertexBuffer);
|
|
233
|
-
//deleteBuffer(gl, colorBuffer);
|
|
234
|
-
//deleteBuffer(gl, textCoordBuffer);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
//console.log(1,vertexBuffer);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if(program.uniforms.u_color) {
|
|
243
|
-
gl.uniform4f(program.uniforms.u_color.location, Math.random(), Math.random(), Math.random(), 1) // 设置它的值
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
//setTimeout(() => {
|
|
247
|
-
|
|
248
|
-
vertexBuffer = createFloat32Buffer(gl, points);
|
|
249
|
-
console.log(0, vertexBuffer);
|
|
250
|
-
writeVertexAttrib(gl, vertexBuffer, program.attrs.a_position, 2, 0, 0);
|
|
251
|
-
console.log(5, vertexBuffer.buffer);
|
|
252
|
-
gl.drawArrays(gl.LINE_STRIP, 0, points.length/2);
|
|
253
|
-
|
|
254
|
-
deleteBuffer(gl, vertexBuffer);
|
|
255
|
-
//}, 2000);
|
|
256
|
-
|
|
257
|
-
draw2d(points);
|
|
258
|
-
|
|
259
|
-
//setTimeout(draw, 1000)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function draw2d(points) {
|
|
263
|
-
var cvs = document.getElementById("cvs2d");
|
|
264
|
-
var ctx = cvs.getContext("2d");
|
|
265
|
-
|
|
266
|
-
ctx.strokeStyle = "rgba(0, 255, 0, 1)";
|
|
267
|
-
|
|
268
|
-
ctx.beginPath();
|
|
269
|
-
ctx.moveTo(points[0]/10000 * center.x + center.x, center.y - points[1]/10000 * center.y);
|
|
270
|
-
for(let i=2;i<points.length;i+=2) {
|
|
271
|
-
ctx.lineTo(points[i]/10000 * center.x + center.x, center.y - points[i+1]/10000 * center.y);
|
|
272
|
-
}
|
|
273
|
-
ctx.lineTo(points[0]/10000 * center.x + center.x, center.y - points[1]/10000 * center.y);
|
|
274
|
-
ctx.stroke();
|
|
275
|
-
ctx.closePath();
|
|
276
|
-
}
|
|
277
|
-
</script>
|
|
278
|
-
</body>
|
|
1
|
+
<body>
|
|
2
|
+
<canvas id="cvs" width="600" height="600" style="border: dashed 1px red">
|
|
3
|
+
你的浏览器不支持画布元素
|
|
4
|
+
</canvas>
|
|
5
|
+
<canvas id="cvs2d" width="600" height="600" style="border: dashed 1px red">
|
|
6
|
+
你的浏览器不支持画布元素
|
|
7
|
+
</canvas>
|
|
8
|
+
<script type="module">
|
|
9
|
+
import {
|
|
10
|
+
createProgram,
|
|
11
|
+
writeVertexAttrib
|
|
12
|
+
} from '../src/lib/webgl/core/program.js';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
createFloat32Buffer,
|
|
16
|
+
createUint16Buffer,
|
|
17
|
+
deleteBuffer,
|
|
18
|
+
} from '../src/lib/webgl/core/buffer.js';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
create2DTexture
|
|
22
|
+
} from '../src/lib/webgl/core/texture.js';
|
|
23
|
+
|
|
24
|
+
//获取画布元素
|
|
25
|
+
var cvs = document.getElementById('cvs');
|
|
26
|
+
//获取到元素的上下文环境对象
|
|
27
|
+
var gl = cvs.getContext('webgl');
|
|
28
|
+
|
|
29
|
+
const width = gl.canvas.width;
|
|
30
|
+
const height = gl.canvas.height;
|
|
31
|
+
gl.viewport(0, 0, width, height)
|
|
32
|
+
// 设置 webgl 视口,将 -1 到 1 映射为 canvas 上的坐标
|
|
33
|
+
const program = createProgram(gl, `
|
|
34
|
+
attribute vec4 a_position;
|
|
35
|
+
attribute vec2 aPointIndex;
|
|
36
|
+
attribute vec4 aColor;
|
|
37
|
+
attribute vec2 aTextCoord;
|
|
38
|
+
uniform vec2 aCenterPoint;
|
|
39
|
+
uniform vec2 aLineStart;
|
|
40
|
+
uniform vec2 aLineEnd;
|
|
41
|
+
uniform float aTotalPointCount;
|
|
42
|
+
varying vec4 vColor;
|
|
43
|
+
varying vec2 vTextCoord;
|
|
44
|
+
|
|
45
|
+
vec4 translatePosition(in vec4 point, float x, float y) {
|
|
46
|
+
point.x = (point.x-x)/x;
|
|
47
|
+
point.y = (y-point.y)/y;
|
|
48
|
+
return point;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vec4 pointToPos(vec2 start, vec2 end, float index) {
|
|
52
|
+
float len = sqrt(pow(end.x - start.x, 2.0) + pow(end.y - start.y, 2.0));
|
|
53
|
+
|
|
54
|
+
float x = start.x + (end.x - start.x)/10.0 * index;
|
|
55
|
+
float y = start.y + (end.y - start.y)/10.0 * index;
|
|
56
|
+
return vec4(x, y, 0.0, 0.0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
vec4 ceilPosition(vec4 pos) {
|
|
60
|
+
return vec4(pos.xy/10000.0, pos.zw);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void main() {
|
|
64
|
+
gl_PointSize = 10.0;
|
|
65
|
+
//vec4 pos = pointToPos(aLineStart, aLineEnd, aPointIndex.x);
|
|
66
|
+
vec4 pos = ceilPosition(a_position);//translatePosition(a_position, aCenterPoint.x, aCenterPoint.y);
|
|
67
|
+
gl_Position = pos;
|
|
68
|
+
vColor = aColor;
|
|
69
|
+
vTextCoord = aTextCoord;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
`,`
|
|
73
|
+
precision highp float;
|
|
74
|
+
uniform vec4 u_color;
|
|
75
|
+
uniform sampler2D uSample;
|
|
76
|
+
varying vec4 vColor;
|
|
77
|
+
varying vec2 vTextCoord;
|
|
78
|
+
|
|
79
|
+
void main() {
|
|
80
|
+
//float r = distance(gl_PointCoord, vec2(0.5, 0.5));
|
|
81
|
+
//根据距离设置片元
|
|
82
|
+
//if(r <= 0.5){
|
|
83
|
+
// 方形区域片元距离几何中心半径小于0.5,像素颜色设置红色
|
|
84
|
+
gl_FragColor = u_color;
|
|
85
|
+
//}else {
|
|
86
|
+
// 方形区域距离几何中心半径不小于0.5的片元剪裁舍弃掉:
|
|
87
|
+
// discard;
|
|
88
|
+
//}
|
|
89
|
+
//gl_FragColor = u_color;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
`);
|
|
93
|
+
//texture2D(uSample, vTextCoord)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
const colors = [Math.random(),Math.random(),Math.random(),1];
|
|
98
|
+
let points = [6667, 0, 5851, 3196, 3602, 5610, 472, 5555, 680];
|
|
99
|
+
const uvpoints = [];
|
|
100
|
+
|
|
101
|
+
const center = {
|
|
102
|
+
x: width / 2,
|
|
103
|
+
y: height / 2
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
let colorStop = [Math.random(),Math.random(),Math.random(),1];
|
|
108
|
+
for(let r=0; r<=Math.PI*2;r += 0.5) {
|
|
109
|
+
const cos = Math.cos(r);
|
|
110
|
+
const sin = Math.sin(r);
|
|
111
|
+
const x = (cos * 200) + center.x;
|
|
112
|
+
const y = (sin * 200) + center.y;
|
|
113
|
+
//points.push(Number(((cos * 200)/center.x).toFixed(4)), Number(((sin * 200) / center.y).toFixed(4)));
|
|
114
|
+
let ux = (cos + 1)/2;
|
|
115
|
+
//if(ux < 0.5) ux = ux/2;
|
|
116
|
+
|
|
117
|
+
let uy = (sin + 1) / 2;
|
|
118
|
+
//if(uy < 0.5) uy = uy/2;
|
|
119
|
+
|
|
120
|
+
uvpoints.push(ux, uy);
|
|
121
|
+
colors.push(...colorStop);
|
|
122
|
+
}
|
|
123
|
+
//points.push(points[0], points[1]);
|
|
124
|
+
//uvpoints.push(uvpoints[0], uvpoints[1]);
|
|
125
|
+
//colors.push(...colorStop);
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
colorStop = [Math.random(),Math.random(),Math.random(),1];
|
|
129
|
+
const lastLen = points.length;
|
|
130
|
+
for(let r=0; r<=Math.PI*2;r += 0.1) {
|
|
131
|
+
points.push((Math.cos(r) * 200) / center.x, (Math.sin(r) * 200) / center.y);
|
|
132
|
+
colors.push(...colorStop);
|
|
133
|
+
}
|
|
134
|
+
points.push(points[lastLen], points[lastLen+1]);
|
|
135
|
+
colors.push(...colorStop);*/
|
|
136
|
+
|
|
137
|
+
if(program.uniforms.u_color) {
|
|
138
|
+
//const colorLocation = gl.getUniformLocation(program.program, 'u_color') // 获取 u_color 变量位置
|
|
139
|
+
gl.uniform4f(program.uniforms.u_color.location, 0.0, 1.0, 0.0, 1) // 设置它的值
|
|
140
|
+
}
|
|
141
|
+
if(program.uniforms.aLineEnd) {
|
|
142
|
+
gl.uniform2f(program.uniforms.aLineEnd.location, 100.0, 50.0) // 设置它的值
|
|
143
|
+
}
|
|
144
|
+
if(program.uniforms.aLineStart) {
|
|
145
|
+
gl.uniform2f(program.uniforms.aLineStart.location, 305.0, 500.0) // 设置它的值
|
|
146
|
+
}
|
|
147
|
+
if(program.uniforms.aTotalPointCount) {
|
|
148
|
+
gl.uniform1f(program.uniforms.aTotalPointCount.location, 100); // 设置它的值
|
|
149
|
+
}
|
|
150
|
+
if(program.uniforms.aCenterPoint) {
|
|
151
|
+
gl.uniform2f(program.uniforms.aCenterPoint.location, center.x, center.y); // 设置它的值
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//先创建一个缓存对象
|
|
155
|
+
if(program.attrs.a_position) {
|
|
156
|
+
var vertexBuffer = createFloat32Buffer(gl, points);
|
|
157
|
+
writeVertexAttrib(gl, vertexBuffer, program.attrs.a_position, 2, 0, 0);
|
|
158
|
+
//deleteBuffer(gl, vertexBuffer);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if(program.attrs.aPointIndex) {
|
|
162
|
+
const pointIndexs = [];
|
|
163
|
+
for(let i=0;i<100;i++) {
|
|
164
|
+
pointIndexs.push(i);
|
|
165
|
+
}
|
|
166
|
+
var pointIndexBuffer = createFloat32Buffer(gl, pointIndexs);
|
|
167
|
+
writeVertexAttrib(gl, pointIndexBuffer, program.attrs.aPointIndex, 1, 0, 0);
|
|
168
|
+
}
|
|
169
|
+
//先创建一个缓存对象
|
|
170
|
+
var colorBuffer = createFloat32Buffer(gl, colors);
|
|
171
|
+
writeVertexAttrib(gl, colorBuffer, program.attrs.aColor, 4, 4, 0);
|
|
172
|
+
//deleteBuffer(gl, colorBuffer);
|
|
173
|
+
//const aTextCoord = gl.getAttribLocation(program, 'aTextCoord');
|
|
174
|
+
//const uSample = gl.getUniformLocation(program, 'uSample');
|
|
175
|
+
|
|
176
|
+
//先创建一个缓存对象
|
|
177
|
+
//var textCoordBuffer = createFloat32Buffer(gl, uvpoints);
|
|
178
|
+
//writeVertexAttrib(gl, textCoordBuffer, program.attrs.aTextCoord, 2, 2, 0);
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
// 纹理
|
|
182
|
+
/*var img = new Image();
|
|
183
|
+
|
|
184
|
+
img.onload = function(){
|
|
185
|
+
draw();
|
|
186
|
+
};
|
|
187
|
+
img.src = 'qrcode.jpg';*/
|
|
188
|
+
|
|
189
|
+
//points = [-0.8, 0.5, 0, 0.5,0.6,0,0,-0.6, -0.5];
|
|
190
|
+
|
|
191
|
+
draw();
|
|
192
|
+
|
|
193
|
+
function draw() {
|
|
194
|
+
/*var texture = create2DTexture(gl, img);
|
|
195
|
+
|
|
196
|
+
if(program.uniforms.uSample) {
|
|
197
|
+
gl.uniform1i(program.uniforms.uSample.location, 0) // 纹理单元传递给着色器
|
|
198
|
+
}*/
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
gl.clearColor(1, 1, 1, 1) // 设置清空颜色缓冲时的颜色值
|
|
205
|
+
gl.clear(gl.COLOR_BUFFER_BIT) // 清空颜色缓冲区,也就是清空画布
|
|
206
|
+
|
|
207
|
+
if(program.uniforms.u_color) {
|
|
208
|
+
gl.uniform4f(program.uniforms.u_color.location, Math.random(), Math.random(), Math.random(), 1) // 设置它的值
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
vertexBuffer = createFloat32Buffer(gl, points);
|
|
212
|
+
writeVertexAttrib(gl, vertexBuffer, program.attrs.a_position, 2, 0, 0);
|
|
213
|
+
|
|
214
|
+
/*gl.drawArrays( // 从数组中绘制图元
|
|
215
|
+
gl.TRIANGLES, // 渲染三角形
|
|
216
|
+
0, // 从数组中哪个点开始渲染
|
|
217
|
+
3 // 需要用到多少个点,三角形的三个顶点
|
|
218
|
+
);
|
|
219
|
+
gl.drawArrays( // 从数组中绘制图元
|
|
220
|
+
gl.TRIANGLES, // 渲染三角形
|
|
221
|
+
3, // 从数组中哪个点开始渲染
|
|
222
|
+
3 // 需要用到多少个点,三角形的三个顶点
|
|
223
|
+
);*/
|
|
224
|
+
//gl.drawArrays(gl.TRIANGLE, 0, points.length/2);
|
|
225
|
+
gl.drawArrays(gl.LINE_STRIP, 0, points.length/2);
|
|
226
|
+
//gl.drawArrays(gl.TRIANGLE_STRIP, 0, points.length/2);
|
|
227
|
+
//gl.drawArrays(gl.LINE_STRIP, 0, points.length/2);
|
|
228
|
+
//gl.drawArrays(gl.LINE_LOOP, 0, points.length/2);
|
|
229
|
+
//gl.drawArrays(gl.POINTS, 0, points.length/2);
|
|
230
|
+
//gl.drawArrays(gl.LINES, 0, points.length/2);
|
|
231
|
+
|
|
232
|
+
//deleteBuffer(gl, vertexBuffer);
|
|
233
|
+
//deleteBuffer(gl, colorBuffer);
|
|
234
|
+
//deleteBuffer(gl, textCoordBuffer);
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
//console.log(1,vertexBuffer);
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
if(program.uniforms.u_color) {
|
|
243
|
+
gl.uniform4f(program.uniforms.u_color.location, Math.random(), Math.random(), Math.random(), 1) // 设置它的值
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//setTimeout(() => {
|
|
247
|
+
|
|
248
|
+
vertexBuffer = createFloat32Buffer(gl, points);
|
|
249
|
+
console.log(0, vertexBuffer);
|
|
250
|
+
writeVertexAttrib(gl, vertexBuffer, program.attrs.a_position, 2, 0, 0);
|
|
251
|
+
console.log(5, vertexBuffer.buffer);
|
|
252
|
+
gl.drawArrays(gl.LINE_STRIP, 0, points.length/2);
|
|
253
|
+
|
|
254
|
+
deleteBuffer(gl, vertexBuffer);
|
|
255
|
+
//}, 2000);
|
|
256
|
+
|
|
257
|
+
draw2d(points);
|
|
258
|
+
|
|
259
|
+
//setTimeout(draw, 1000)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function draw2d(points) {
|
|
263
|
+
var cvs = document.getElementById("cvs2d");
|
|
264
|
+
var ctx = cvs.getContext("2d");
|
|
265
|
+
|
|
266
|
+
ctx.strokeStyle = "rgba(0, 255, 0, 1)";
|
|
267
|
+
|
|
268
|
+
ctx.beginPath();
|
|
269
|
+
ctx.moveTo(points[0]/10000 * center.x + center.x, center.y - points[1]/10000 * center.y);
|
|
270
|
+
for(let i=2;i<points.length;i+=2) {
|
|
271
|
+
ctx.lineTo(points[i]/10000 * center.x + center.x, center.y - points[i+1]/10000 * center.y);
|
|
272
|
+
}
|
|
273
|
+
ctx.lineTo(points[0]/10000 * center.x + center.x, center.y - points[1]/10000 * center.y);
|
|
274
|
+
ctx.stroke();
|
|
275
|
+
ctx.closePath();
|
|
276
|
+
}
|
|
277
|
+
</script>
|
|
278
|
+
</body>
|