zoukankan      html  css  js  c++  java
  • 布朗(随机)运动

    基础:Math.random() * 200 - 100;

    代码
    package
    {
        
    import flash.display.Sprite;
        
    import flash.events.Event;

        
    public class Main extends Sprite
        {
            
    private var numDots:uint = 20;
            
    private var friction:Number = 0.95;
            
    private var dots:Array;

            
    public function Main()
            {
                init();
            }

            
    private function init():void
            {
                graphics.lineStyle(
    00, .5);
                dots 
    = new Array();
                
    for (var i:uint = 0; i < numDots; i++)
                {
                    var dot:Ball 
    = new Ball();
                    dot.x 
    = Math.random() * stage.stageWidth;
                    dot.y 
    = Math.random() * stage.stageHeight;
                    dot.vx 
    = 0;
                    dot.vy 
    = 0;
                    addChild(dot);
                    dots.push(dot);
                }
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
            }

            
    private function onEnterFrame(event:Event):void
            {
                
    for (var i:uint = 0; i < numDots; i++)
                {
                    var dot:Ball 
    = dots[i];
                    graphics.moveTo(dot.x, dot.y);
                    dot.vx 
    += Math.random() * 0.2 - 0.1;
                    dot.vy 
    += Math.random() * 0.2 - 0.1;
                    dot.x 
    += dot.vx;
                    dot.y 
    += dot.vy;
                    dot.vx 
    *= friction;
                    dot.vy 
    *= friction;
                    graphics.lineTo(dot.x, dot.y);
                    
    if (dot.x > stage.stageWidth)
                    {
                        dot.x 
    = 0;
                    }
                    
    else if (dot.x < 0)
                    {
                        dot.x 
    = stage.stageWidth;
                    }
                    
    if (dot.y > stage.stageHeight)
                    {
                        dot.y 
    = 0;
                    }
                    
    else if (dot.y < 0)
                    {
                        dot.y 
    = stage.stageHeight;
                    }
                }
            }
        }
    }
    import flash.display.Sprite;
    class Ball extends Sprite
    {
        
    public var vx:Number;
        
    public var vy:Number;
        
    public function Ball():void
        {
            
    this.graphics.beginFill(0);
            
    this.graphics.drawCircle(002);
            
    this.graphics.endFill();
        }
    }
  • 相关阅读:
    安全测试 + 渗透测试 Xmind 要点梳理
    Confluence wiki——CentOS6.8搭建详解
    Flask从入门到做出一个博客的大型教程(一)
    基于Cat的分布式调用追踪
    Elastic-job使用及原理
    Jmeter模拟不同带宽
    Mybatis中parameterType、resultMap、statementType等等配置详解(标签中基本配置详解)
    SQLyog Enterprise常用快捷键
    MyBatis 与 Spring Data JPA 选择谁?
    Springboot集成mybatis(mysql),mail,mongodb,cassandra,scheduler,redis,kafka,shiro,websocket
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/1678694.html
Copyright © 2011-2022 走看看