粒子动画creatjs

https://segmentfault.com/a/1190000005704935?utm_source=tuicool&utm_medium=referral
http://blog.csdn.net/yeana1/article/details/52460490#reply
html页面

<canvas id="text" width="500" height="100"></canvas>
<canvas id="stage" width="500" height="100"></canvas>
<form id="form">
    <input type="text" id="inputText" value="HELLO"/>
    <input type="submit" value="TRY IT"/>
</form>

<!--<script src='js/EasePack.min.js'></script>-->
<script src='js/TweenLite.min.js'></script>
<!--TweenJS – 用来帮助调整HTML5和Javascript属性-->
<!--EaselJS – 简化处理HTML5画布(核心)-->
<script src='js/easeljs-0.7.1.min.js'></script>
<!--<script src='js/requestAnimationFrame.js'></script>-->

<script src="js/index.js"></script>

index.js
初始化:

 var stage, textStage, form, input;
    var circles, textPixels, textFormed;
    var offsetX, offsetY, text;
    var colors = ['#B2949D', '#FFF578', '#FF5F8D', '#37A9CC', '#188EB2'];

    function init() {
        initStages();
        initForm();
        initText();
        initCircles();
        animate();
        addListeners();
    }

开始画图(canvas):

 function initStages() {
        offsetX = (window.innerWidth-600)/2;//图画定位X
        offsetY = (window.innerHeight-300)/2;//图画定位
        textStage = new createjs.Stage("text");
        textStage.canvas.width = 600;
        textStage.canvas.height = 200;

        stage = new createjs.Stage("stage");
        stage.canvas.width = window.innerWidth;
        stage.canvas.height = window.innerHeight;
    }

设置表单

  function initForm() {
        form = document.getElementById('form');
        form.style.top = offsetY+200+'px';
        form.style.left = offsetX+'px';
        input = document.getElementById('inputText');
    }

    function initText() {
        text = new createjs.Text("t", "80px 'Source Sans Pro'", "#eee");
        text.textAlign = 'center';
        text.x = 300;
    }

//画随机漂浮的小圆点

 function initCircles() {
        circles = [];
        for(var i=0; i<600; i++) {
            var circle = new createjs.Shape();
            var r = 7;//半径
            var x = window.innerWidth*Math.random();//x定位
            var y = window.innerHeight*Math.random();//y定位
            var color = colors[Math.floor(i%colors.length)];//颜色
            var alpha = 0.2 + Math.random()*0.5;//透明度
            circle.alpha = alpha;
            circle.radius = r;
            circle.graphics.beginFill(color).drawCircle(0, 0, r);//用画笔设置颜色,调用方法画矩形,矩形参数:drawRect(0, 0, 100, 100)
            circle.x = x;
            circle.y = y;
            circles.push(circle);
            stage.addChild(circle);
            circle.movement = 'float';
            tweenCircle(circle);
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 在线阅读 http://interview.poetries.top[http://interview.poetr...
    前端进阶之旅阅读 115,362评论 24 450
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,702评论 1 92
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,695评论 25 709
  • 超级时间管理方法 1抓住时间小偷 我们的时间总是在不经意间流逝,然后自己也什么也没完成。所以针对这个情况我们需要记...
    丑小鸭长成记阅读 1,265评论 0 2
  • 今天的美容室学习培训会议,先生引导全员,确定方向,找自身的长短,帮助大家怎么找方法提高完善自我!
    冰咋吃阅读 1,396评论 0 0

友情链接更多精彩内容