GithubHelp home page GithubHelp logo

Comments (1)

IonSwitz avatar IonSwitz commented on June 16, 2024

package
{
import flash.display.Shape;
import starling.display.Sprite;
import starling.display.graphicsEx.ShapeEx;

/**
 * ...
 * Simple class to draw numbers (useful for profiling)
 */
public class DebugNumbers extends Sprite 
{
    protected var _shapeEx:ShapeEx;
    public var _characterHeight:Number = 20;
    public var _characterWidth:Number = 10;
    public var _lineWidth:Number = 2;
    public var _lineColor:Number = 0xFFFFFF;

    public function DebugNumbers() 
    {
        _shapeEx = new ShapeEx();
        addChild(_shapeEx);
    }

    public function drawNumber(value:uint) : void
    {
        var valueString:String = "" + value;

        var xPos:Number = x;

        _shapeEx.graphics.clear();
        _shapeEx.graphics.lineStyle(_lineWidth, _lineColor, 1.0);

        for ( var i:int = 0; i < valueString.length; i++)
        {
            var currentChar:String = valueString.charAt(i);
            if ( currentChar == "0" )
                xPos += draw_0(xPos);
            else if (currentChar == "1" )
                xPos += draw_1(xPos);
            else if (currentChar == "2" )
                xPos += draw_2(xPos);
            else if (currentChar == "3" )
                xPos += draw_3(xPos);
            else if (currentChar == "4" )
                xPos += draw_4(xPos);
            else if (currentChar == "5" )
                xPos += draw_5(xPos);
            else if (currentChar == "6" )
                xPos += draw_6(xPos);
            else if (currentChar == "7" )
                xPos += draw_7(xPos);
            else if (currentChar == "8" )
                xPos += draw_8(xPos);
            else if (currentChar == "9" )
                xPos += draw_9(xPos);
        }

    }

    protected function draw_0(xpos:Number) : Number
    {
        _shapeEx.graphics.drawEllipse(xpos + _characterWidth * 0.5, _characterHeight * 0.5, _characterWidth, _characterHeight);

        return _characterWidth + _lineWidth;
    }

    protected function draw_1(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos + _characterWidth * 0.5, 0);

        _shapeEx.graphics.lineTo(xpos + _characterWidth * 0.5, _characterHeight);

        return _characterWidth + _lineWidth;
    }

    protected function draw_2(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos , _characterHeight * 0.2 );
        _shapeEx.graphics.curveTo(xpos + _characterWidth * 0.5, -_characterHeight * 0.2, xpos + _characterWidth, _characterHeight * 0.2);

        _shapeEx.graphics.lineTo(xpos , _characterHeight);
        _shapeEx.graphics.lineTo(xpos + _characterWidth, _characterHeight);

        return _characterWidth + _lineWidth;
    }
    protected function draw_3(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos , _characterHeight * 0.2 );
        _shapeEx.graphics.curveTo(xpos + _characterWidth * 0.5, -_characterHeight * 0.2, xpos + _characterWidth, _characterHeight * 0.2);
        _shapeEx.graphics.lineTo(xpos + _characterWidth * 0.5, _characterHeight * 0.5);
        _shapeEx.graphics.lineTo(xpos + _characterWidth , _characterHeight * 0.8);

        _shapeEx.graphics.curveTo(xpos + _characterWidth * 0.5, _characterHeight * 1.2, xpos , _characterHeight * 0.8);

        return _characterWidth + _lineWidth;
    }
    protected function draw_4(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos + _characterWidth * 0.8 , 0);
        _shapeEx.graphics.lineTo(xpos + _characterWidth * 0.8 , _characterHeight);

        _shapeEx.graphics.moveTo(xpos + _characterWidth * 0.2 , 0);
        _shapeEx.graphics.lineTo(xpos + _characterWidth * 0.2 , _characterHeight * 0.4);
        _shapeEx.graphics.lineTo(xpos + _characterWidth , _characterHeight * 0.4);


        return _characterWidth + _lineWidth;
    }
    protected function draw_5(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos + _characterWidth , 0 );
        _shapeEx.graphics.lineTo(xpos , 0);
        _shapeEx.graphics.lineTo(xpos , _characterHeight * 0.4);

        _shapeEx.graphics.curveTo(xpos + _characterWidth * 2.0, _characterHeight * 0.75, xpos , _characterHeight);

        return _characterWidth + _lineWidth;
    }
    protected function draw_6(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos + _characterWidth * 0.8 , 0);
        _shapeEx.graphics.lineTo(xpos , _characterHeight * 0.65);
        _shapeEx.graphics.drawEllipse(xpos + _characterWidth * 0.5 , _characterHeight * 0.75, _characterWidth, _characterHeight*0.5);

        return _characterWidth + _lineWidth;
    }
    protected function draw_7(xpos:Number) : Number
    {
        _shapeEx.graphics.moveTo(xpos , 0);

        _shapeEx.graphics.lineTo(xpos + _characterWidth , 0);
        _shapeEx.graphics.lineTo(xpos + 0.5 * _characterWidth , _characterHeight);

        return _characterWidth + _lineWidth;
    }
    protected function draw_8(xpos:Number) : Number
    {
        _shapeEx.graphics.drawEllipse(xpos + _characterWidth * 0.5, _characterHeight * 0.25, _characterWidth * .8, _characterHeight * 0.4);
        _shapeEx.graphics.drawEllipse(xpos + _characterWidth * 0.5 , _characterHeight * 0.75, _characterWidth, _characterHeight*0.5);

        return _characterWidth + _lineWidth;
    }
    protected function draw_9(xpos:Number) : Number
    {
        _shapeEx.graphics.drawEllipse(xpos + _characterWidth * 0.5 , _characterHeight * 0.25, _characterWidth, _characterHeight * 0.5);

        _shapeEx.graphics.moveTo(xpos + _characterWidth , _characterHeight* 0.4 );
        _shapeEx.graphics.lineTo(xpos + _characterWidth*0.2 , _characterHeight);

        return _characterWidth + _lineWidth;
    }

}

}

from starling-extension-graphics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.