Last active
December 31, 2015 13:08
-
-
Save Fintan/7990446 to your computer and use it in GitHub Desktop.
set radius of a circle using toxi.math.BezierInterpolation and mouse.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define(function (require) { | |
| 'use strict'; | |
| var _ = require('underscore'); | |
| var PIXI = require('pixi'); | |
| var PMath = require('utils/PMath'); | |
| var toxi = require('toxi'); | |
| var TColor = toxi.color.TColor; | |
| var BezierInterpolation = toxi.math.BezierInterpolation; | |
| var TweenBall = function() {}; | |
| TweenBall.prototype = { | |
| init: function() { | |
| this.graphics = new PIXI.Graphics(); | |
| this.colour = TColor.newHex('155e73'); | |
| this.gameStage.addChild(this.graphics); | |
| this.tween = new BezierInterpolation(3,-3); | |
| this.mouseData = {x:0, y:0}; | |
| this.graphics.alpha = 0.01; | |
| this.graphics.setInteractive(true); | |
| this.graphics.mousemove = _.bind(function(mouseData) { | |
| this.mouseData = mouseData.getLocalPosition(this.gameStage); | |
| }, this); | |
| }, | |
| drawCircle: function(x, y, size) { | |
| this.graphics.beginFill(this.colour.toInt()); | |
| this.graphics.lineStyle(2, this.colour.toInt()); | |
| this.graphics.drawCircle(x, y, size); | |
| this.graphics.endFill(); | |
| }, | |
| update: function() { | |
| //this.graphics.clear(); | |
| var normX = this.mouseData.x/this.gameWidth; | |
| if(normX !== this.lastNormX) { | |
| var r = this.tween.interpolate(0, 150, normX); | |
| this.drawCircle(this.gameWidth/2, this.gameHeight/2, r); | |
| this.lastNormX = normX; | |
| } | |
| } | |
| }; | |
| return TweenBall; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment