File: incremental2.html

package info (click to toggle)
node-zrender 5.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,544 kB
  • sloc: javascript: 1,259; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Incremental Rendering</title>
    <script src="../dist/zrender.js"></script>
</head>
<body style="margin:0px;">
    <canvas id="main" width="1000px" height="600px" style="width:1000px;height:600px;"></canvas>
    <script type="text/javascript">
        var zr = zrender.init(document.getElementById('main'));

        zr.add(new zrender.Rect({
            shape: {
                x: 0,
                y: 0,
                width: zr.getWidth(),
                height: zr.getHeight()
            },
            style: {
                fill: 'red'
            }
        }));

        var countText = new zrender.Text({
            zlevel: 1,
            style: {
                text: 0,
                x: 10,
                y: 10,
                textFont: '40px sans-serif',
                textFill: '#fff',
                textStroke: '#000',
                textStrokeWidth: 2
            }
        });
        zr.add(countText);

        var count = 0;

        zr.animation.on('frame', function ()  {
            if (count > 2e4) {
                return;
            }
            for (var i = 0; i < 200; i++) {
                var circleShape = new zrender.Circle({
                    shape: {
                        r: 5 + Math.random() * 5
                    },
                    style: {
                        fill: '#121',
                        blend: 'lighter'
                    },
                    incremental: true,
                    position: [Math.random() * zr.getWidth(), Math.random() * zr.getHeight()]
                });
                zr.add(circleShape);
            }

            countText.style.text += 200;
            countText.dirty();

            count += 200;
        });
    </script>
</body>
</html>