一个简朴的细胞分裂小游戏

地点是
http://codepen.io/fishenal/full/EDxGL

重要用到了raphael.js来画svg,完成很简单,分享以下

var paper = Raphael(0, 0, 1000, 1000)

var Ball = function(x, y, r){
  this.x = x
  this.y = y
  this.r = r
  this.init = function(){
    var me = this;
    this.tball = paper.circle(me.x, me.y, me.r).attr('fill', '#000')
    this.tball.click(function(){
      me.tball.remove()
      var x = [new Ball(me.x - me.r/2, me.y - me.r/2, me.r/2),
               new Ball(me.x - me.r/2, me.y + me.r/2, me.r/2),
               new Ball(me.x + me.r/2, me.y - me.r/2, me.r/2),
               new Ball(me.x + me.r/2, me.y + me.r/2, me.r/2)]

      })
  }

  this.init();
}

var ball = new Ball(300, 300, 300);

一个圆,中心点x,y坐标,半径r
给本身绑定一个点击事宜,删除本身,建立四个新圆,中心点位置分别是当前+- 半径/2,四种组合,半径设为一半

    原文作者:fishenal
    原文地址: https://segmentfault.com/a/1190000000605845
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞