-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.html
More file actions
847 lines (648 loc) · 22.6 KB
/
index2.html
File metadata and controls
847 lines (648 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
*{
padding: 0;
margin: 0;
}
html, body {
height: 100%;
padding: 0;
margin: 0;
background: #000;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
}
.aa{
position: fixed;
left: 50%;
bottom: 10px;
color: #ccc
}
#canvas1 {
position: absolute;
left: 0px;
top: 0px;
/* margin: 20px; */
/* background: #ffffff; */
/* border: thin solid #aaaaaa; */
}
#canvas2 {
position: absolute;
left: 0px;
top: 0px;
/* margin: 20px; */
/* border: thin solid #aaaaaa; */
}
#tree {
position: absolute;
left: -250px;
top: 300px;
}
#flower{
position: absolute;
left: -250 px;
top: 300px;
}
</style>
<body>
<canvas id="canvas1"></canvas>
<canvas id="canvas2"></canvas>
<!-- <link rel="stylesheet" href="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> -->
<script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
var utils = {
norm: function(value, min, max) {
return (value - min) / (max - min);
},
lerp: function(norm, min, max) {
return (max - min) * norm + min;
},
map: function(value, sourceMin, sourceMax, destMin, destMax) {
return utils.lerp(utils.norm(value, sourceMin, sourceMax), destMin, destMax);
},
clamp: function(value, min, max) {
return Math.min(Math.max(value, Math.min(min, max)), Math.max(min, max));
},
distance: function(p0, p1) {
var dx = p1.x - p0.x,
dy = p1.y - p0.y;
return Math.sqrt(dx * dx + dy * dy);
},
distanceXY: function(x0, y0, x1, y1) {
var dx = x1 - x0,
dy = y1 - y0;
return Math.sqrt(dx * dx + dy * dy);
},
circleCollision: function(c0, c1) {
return utils.distance(c0, c1) <= c0.radius + c1.radius;
},
circlePointCollision: function(x, y, circle) {
return utils.distanceXY(x, y, circle.x, circle.y) < circle.radius;
},
pointInRect: function(x, y, rect) {
return utils.inRange(x, rect.x, rect.x + rect.radius) &&
utils.inRange(y, rect.y, rect.y + rect.radius);
},
inRange: function(value, min, max) {
return value >= Math.min(min, max) && value <= Math.max(min, max);
},
rangeIntersect: function(min0, max0, min1, max1) {
return Math.max(min0, max0) >= Math.min(min1, max1) &&
Math.min(min0, max0) <= Math.max(min1, max1);
},
rectIntersect: function(r0, r1) {
return utils.rangeIntersect(r0.x, r0.x + r0.width, r1.x, r1.x + r1.width) &&
utils.rangeIntersect(r0.y, r0.y + r0.height, r1.y, r1.y + r1.height);
},
degreesToRads: function(degrees) {
return degrees / 180 * Math.PI;
},
radsToDegrees: function(radians) {
return radians * 180 / Math.PI;
},
randomRange: function(min, max) {
return min + Math.random() * (max - min);
},
randomInt: function(min, max) {
return min + Math.random() * (max - min + 1);
},
getmiddle: function(p0, p1) {
var x = p0.x,
x2 = p1.x;
middlex = (x + x2) / 2;
var y = p0.y,
y2 = p1.y;
middley = (y + y2) / 2;
pos = [middlex, middley];
return pos;
},
getAngle: function(p0, p1) {
var deltaX = p1.x - p0.x;
var deltaY = p1.y - p0.y;
var rad = Math.atan2(deltaY, deltaX);
return rad;
},
inpercentW: function(size) {
return (size * W) / 100;
},
inpercentH: function(size) {
return (size * H) / 100;
},
}
// basic setup :)
canvas = document.getElementById("canvas2");
var ctx = canvas.getContext('2d');
W = canvas.width = window.innerWidth;
H = canvas.height = window.innerHeight;
gridX = 5;
gridY = 5;
function shape(x, y, texte) {
this.x = x;
this.y = y;
this.size = 72;
this.text = texte;
this.placement = [];
this.vectors = [];
}
shape.prototype.getValue = function() {
console.log("get black pixels position");
// Draw the shape :^)
ctx.textAlign = "center";
ctx.font = "bold " + this.size + "px arial";
ctx.fillText(this.text, this.x, this.y);
var idata = ctx.getImageData(0, 0, W, H);
var buffer32 = new Uint32Array(idata.data.buffer);
for (var y = 0; y < H; y += gridY) {
for (var x = 0; x < W; x += gridX) {
if (buffer32[y * W + x]) {
this.placement.push(new particle2(x, y));
}
}
}
ctx.clearRect(0, 0, W, H);
}
colors = [
'#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5',
'#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4CAF50',
'#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800',
'#FF5722'
];
function particle2(x, y, type) {
this.radius = 1.1;
this.futurRadius = utils.randomInt(radius, radius+3);
this.rebond = utils.randomInt(1, 5);
this.x = x;
this.y = y;
this.dying = false;
this.base = [x, y]
this.vx = 0;
this.vy = 0;
this.type = type;
this.friction = .99;
this.gravity = gravity;
this.color = colors[Math.floor(Math.random() * colors.length)];
this.getSpeed = function() {
return Math.sqrt(this.vx * this.vx + this.vy * this.vy);
};
this.setSpeed = function(speed) {
var heading = this.getHeading();
this.vx = Math.cos(heading) * speed;
this.vy = Math.sin(heading) * speed;
};
this.getHeading = function() {
return Math.atan2(this.vy, this.vx);
};
this.setHeading = function(heading) {
var speed = this.getSpeed();
this.vx = Math.cos(heading) * speed;
this.vy = Math.sin(heading) * speed;
};
this.angleTo = function(p2) {
return Math.atan2(p2.y - this.y, p2.x - this.x);
};
this.update = function(heading) {
this.x += this.vx;
this.y += this.vy;
this.vy += gravity;
this.vx *= this.friction;
this.vy *= this.friction;
if(this.radius < this.futurRadius && this.dying === false){
this.radius += duration;
}else{
this.dying = true;
}
if(this.dying === true){
this.radius -= duration;
}
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.arc(this.x, this.y, this.radius, Math.PI * 2, false);
ctx.fill();
ctx.closePath();
if (this.y < 0 || this.radius < 1) {
this.x = this.base[0];
this.dying = false;
this.y = this.base[1];
this.radius = 1.1;
this.setSpeed(speed);
this.futurRadius = utils.randomInt(radius, radius+3);
this.setHeading(utils.randomInt(utils.degreesToRads(0), utils.degreesToRads(360)));
}
};
this.setSpeed(utils.randomInt(.1, .5));
this.setHeading(utils.randomInt(utils.degreesToRads(0), utils.degreesToRads(360)));
}
// element2 = document.getElementById("2");
// element3 = document.getElementById("3");
// element4 = document.getElementById("4");
// element5 = document.getElementById("5");
// element6 = document.getElementById("6");
// fieldvalue = document.getElementById("message");
gravity = parseFloat(0);//element2.value);
duration = parseFloat(0.4);//element3.value);
resolution = parseFloat(4);//element4.value);
speed = parseFloat(0.1);//element5.value);
radius = parseFloat(2);//element5.value);
var message = new shape(W / 2, H / 2 - 40, '❤小芮');
var message2 = new shape(W / 2, H / 2 + 30, '生日快乐!');
message.getValue();
message2.getValue();
setTimeout( update,3000);
// update();
// function change() {
// ctx.clearRect(0, 0, W, H);
// gridX = parseFloat(element4.value);
// gridY = parseFloat(element4.value);
// message.placement = [];
// message.text = fieldvalue.value;
// message.getValue();
// }
// function changeV() {
// gravity = parseFloat(element2.value);
// duration = parseFloat(element3.value);
// speed = parseFloat(element5.value);
// radius = parseFloat(element6.value);
// }
var fps = 100;
function update() {
setTimeout(function() {
ctx.clearRect(0, 0, W, H);
for (var i = 0; i < message.placement.length; i++) {
message.placement[i].update();
}
for (var i = 0; i < message2.placement.length; i++) {
message2.placement[i].update();
}
requestAnimationFrame(update);
}, 1000 / fps);
}
</script>
<script>
/*
* Settings
*/
var settings = {
particles: {
length: 800, // maximum amount of particles
duration: 2, // particle duration in sec
velocity: 30, // particle velocity in pixels/sec
effect: -0.4, // play with this for a nice effect
size: 20, // particle size in pixels
},
};
/*
* RequestAnimationFrame polyfill by Erik M?ller
*/
(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f)},f);b=d+f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());
/*
* Point class
*/
var Point = (function() {
function Point(x, y) {
this.x = (typeof x !== 'undefined') ? x : 0;
this.y = (typeof y !== 'undefined') ? y : 0;
}
Point.prototype.clone = function() {
return new Point(this.x, this.y);
};
Point.prototype.length = function(length) {
if (typeof length == 'undefined')
return Math.sqrt(this.x * this.x + this.y * this.y);
this.normalize();
this.x *= length;
this.y *= length;
return this;
};
Point.prototype.normalize = function() {
var length = this.length();
this.x /= length;
this.y /= length;
return this;
};
return Point;
})();
/*
* Particle class
*/
var Particle = (function() {
function Particle() {
this.position = new Point();
this.velocity = new Point();
this.acceleration = new Point();
this.age = 0;
}
Particle.prototype.initialize = function(x, y, dx, dy) {
this.position.x = x;
this.position.y = y;
this.velocity.x = dx;
this.velocity.y = dy;
this.acceleration.x = dx * settings.particles.effect;
this.acceleration.y = dy * settings.particles.effect;
this.age = 0;
};
Particle.prototype.update = function(deltaTime) {
this.position.x += this.velocity.x * deltaTime;
this.position.y += this.velocity.y * deltaTime;
this.velocity.x += this.acceleration.x * deltaTime;
this.velocity.y += this.acceleration.y * deltaTime;
this.age += deltaTime;
};
Particle.prototype.draw = function(context, image) {
function ease(t) {
return (--t) * t * t + 1;
}
var size = image.width * ease(this.age / settings.particles.duration);
context.globalAlpha = 1 - this.age / settings.particles.duration;
context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
};
return Particle;
})();
/*
* ParticlePool class
*/
var ParticlePool = (function() {
var particles,
firstActive = 0,
firstFree = 0,
duration = settings.particles.duration;
function ParticlePool(length) {
// create and populate particle pool
particles = new Array(length);
for (var i = 0; i < particles.length; i++)
particles[i] = new Particle();
}
ParticlePool.prototype.add = function(x, y, dx, dy) {
particles[firstFree].initialize(x, y, dx, dy);
// handle circular queue
firstFree++;
if (firstFree == particles.length) firstFree = 0;
if (firstActive == firstFree ) firstActive++;
if (firstActive == particles.length) firstActive = 0;
};
ParticlePool.prototype.update = function(deltaTime) {
var i;
// update active particles
if (firstActive < firstFree) {
for (i = firstActive; i < firstFree; i++)
particles[i].update(deltaTime);
}
if (firstFree < firstActive) {
for (i = firstActive; i < particles.length; i++)
particles[i].update(deltaTime);
for (i = 0; i < firstFree; i++)
particles[i].update(deltaTime);
}
// remove inactive particles
while (particles[firstActive].age >= duration && firstActive != firstFree) {
firstActive++;
if (firstActive == particles.length) firstActive = 0;
}
};
ParticlePool.prototype.draw = function(context, image) {
// draw active particles
if (firstActive < firstFree) {
for (i = firstActive; i < firstFree; i++)
particles[i].draw(context, image);
}
if (firstFree < firstActive) {
for (i = firstActive; i < particles.length; i++)
particles[i].draw(context, image);
for (i = 0; i < firstFree; i++)
particles[i].draw(context, image);
}
};
return ParticlePool;
})();
/*
* Putting it all together
*/
(function(canvas) {
var context = canvas.getContext('2d'),
particles = new ParticlePool(settings.particles.length),
particleRate = settings.particles.length / settings.particles.duration, // particles/sec
time;
// get point on heart with -PI <= t <= PI
function pointOnHeart(t) {
return new Point(
160 * Math.pow(Math.sin(t), 3),
130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25
);
}
// creating the particle image using a dummy canvas
var image = (function() {
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d');
canvas.width = settings.particles.size;
canvas.height = settings.particles.size;
// helper function to create the path
function to(t) {
var point = pointOnHeart(t);
point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;
point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;
return point;
}
// create the path
context.beginPath();
var t = -Math.PI;
var point = to(t);
context.moveTo(point.x, point.y);
while (t < Math.PI) {
t += 0.01; // baby steps!
point = to(t);
context.lineTo(point.x, point.y);
}
context.closePath();
// create the fill
context.fillStyle = '#ea80b0';
context.fill();
// create the image
var image = new Image();
image.src = canvas.toDataURL();
return image;
})();
// render that thing!
function render() {
// next animation frame
requestAnimationFrame(render);
// update time
var newTime = new Date().getTime() / 1000,
deltaTime = newTime - (time || newTime);
time = newTime;
// clear canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// create new particles
var amount = particleRate * deltaTime;
var alpha = 1;
var colorr ;
for (var i = 0; i < amount; i++) {
var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
var dir = pos.clone().length(settings.particles.velocity);
particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
if (i%10==0)
// alpha -= 0.5/amount;
colorr = "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")";
}
// update and draw particles
particles.update(deltaTime);
particles.draw(context, image);
// context.font = "bold 40px Microsoft YaHei";
// context.strokeStyle = "HotPink";
// context.fillStyle = colorr;//"#FFDAB9"
// // context.strokeStyle =
// context.globalAlpha = alpha;
// context.textAlign = "center";
// context.fillText("❤小芮", canvas.width / 2 ,canvas.height / 2-30);
// context.fillText("Happy Birthday!",canvas.width / 2 ,canvas.height / 2+20);
}
// handle (re-)sizing of the canvas
function onResize() {
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
}
window.onresize = onResize;
// delay rendering bootstrap
// setTimeout(function() {
// onResize();
// render();
// for (var i = 0; i < message.placement.length; i++) {
// message.placement[i].update();
// }
// // requestAnimationFrame(update);
// }, 100);
setTimeout(update,2000);
// update();
function update() {
setTimeout(function() {
// ctx.clearRect(0, 0, W, H);
// for (var i = 0; i < message.placement.length; i++) {
// message.placement[i].update();
// }
onResize();
render();
// context.fillStyle = "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")";//'#ea80b0';
// requestAnimationFrame(update);
}, 1000);
}
})(document.getElementById('canvas1'));
var a_idx = 0;
$(document).ready(function() {
$("body").on("tap",function(e) {
var a = new Array("❤乖乖🐱","❤点点🐱");
var $i = $("<span></span>").text(a[a_idx]);
a_idx = (a_idx + 1) % a.length;
var x = e.pageX,
y = e.pageY;
$i.css({
"z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
"top": y - 20,
"left": x,
"position": "absolute",
"font-weight": "bold",
"color": "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"
});
$("body").append($i);
$i.animate({
"top": y - 180,
"opacity": 0
},
1500,
function() {
$i.remove();
});
return false;
});
});
</script>
<canvas id="tree"></canvas>
<canvas id="flower"></canvas>
<script>
//两个canvas
var tree = document.getElementById("tree");
tree.width = window.innerWidth;
tree.height = window.innerHeight ;
var tCxt = tree.getContext("2d");
var flower = document.getElementById("flower");
flower.width = window.innerWidth;
flower.height = window.innerHeight ;
var cxt = flower.getContext("2d");
var flowerList = [];//樱花列表
var rootTop = 320 ;//树起点
var flowerColor = "rgba(255,192,203,.3)" ;//花色
var flowerColorDeep = "rgba(241,158,194,.5)" ;//花色深
var treeColor2 = "rgba(255,192,203,.5)" ;//树枝颜色
var treeColor = "#FFF" ;//树干颜色
var fallList = [];//飘落樱花列表
var g = 0.01 ;//重力加速度
var gWind = 0.005;//风力加速度
var limitSpeedY = 1;//速度上限
var limitSpeedX = 1 ;//速度上限
cxt.shadowColor= "#FFF" ;
cxt.shadowBlur = 10 ;
function drawTree(x,y,deg,step,type){
var deg1 = step%2 == 0 ? 0.1 : -0.1 ;
var x1 = x + Math.cos(deg+deg1) * (step+4) * 0.8 ;//以步长来判断枝干长度 x轴偏移大一些
var y1 = y + Math.sin(deg+deg1) * (step-1) * 0.8 ;//以步长来判断枝干长度 Y轴压缩一些
tCxt.beginPath();
tCxt.lineWidth = step/3;
tCxt.moveTo(x,y);
tCxt.lineTo(x1,y1);
tCxt.strokeStyle = (step > 5 ) ? treeColor : treeColor2 ;//细纸条都换成花的颜色
tCxt.stroke();
if(step > 20){//树干相交的位置有间隙,以一个圆填充
tCxt.fillStyle = treeColor ;
tCxt.arc(x,y,step/6,0,Math.PI*2);
tCxt.fill();
}
if(step < 3 || (step < 23 && Math.random() > 0.1)){
//末梢位置 画花瓣
var color = [flowerColorDeep,flowerColor,flowerColor][Math.round(Math.random()+0.2)] ;
var r = 2+Math.random()*2
tCxt.fillStyle = color ;
tCxt.arc(x1+Math.random()*3,y1+Math.random()*3,r,0,Math.PI)
tCxt.fill();
flowerList.push({x:x,y:y,sx:(Math.random()-0.5),sy:0,color:color,r:r,deg:deg});//保存下画樱花的位置
}
step -- ;
if(step > 0){
drawTree(x1,y1,deg,step,type);
if(step%3 == 1 && step > 0 && step < 30)
drawTree(x1,y1,deg+0.2 + 0.3 * Math.random(),Math.round(step/1.13));//右分叉
if(step%3 == 0 && step > 0 && step < 30)
drawTree(x1,y1,deg-0.2 - 0.3 * Math.random(),Math.round(step/1.13));//左分叉
}
}
drawTree(tree.width/2,rootTop,-Math.PI/2,30,1);//执行
var len = flowerList.length ;
function step(){
if(Math.random() > 0.3) fallList.push(flowerList[Math.floor(Math.random()*len)]);//随机取出一个,花瓣复制到飘落花瓣的列表中
cxt.clearRect(0,0,tree.width,tree.height);
for(var i = 0 ;i < fallList.length ; i ++){
if(fallList[i].sy < limitSpeedY) fallList[i].sy += g ;
fallList[i].sx += gWind ;
fallList[i].x += fallList[i].sx ;
fallList[i].y += fallList[i].sy ;
if(fallList[i].y > rootTop){//飘到树根的花瓣移除
fallList.splice(i,1);
i -- ;
continue ;
}
cxt.beginPath();
cxt.fillStyle = fallList[i].color ;
fallList[i].deg += fallList[i].sx*0.05 ;//跟速度相关的旋转花瓣
cxt.arc(fallList[i].x,fallList[i].y,fallList[i].r,fallList[i].deg,fallList[i].deg+Math.PI*1.3);
cxt.fill();
}
requestAnimationFrame(step);
}
requestAnimationFrame(step);
</script>
</body>
</html>