Giter Site home page Giter Site logo

Comments (1)

sobytes avatar sobytes commented on July 22, 2024

Update this works on the simulator but not on the device have absolutely no idea why ;(

var container = Ti.UI.createView({
        backgroundColor : 'blue',
borderRadius: 144,
        width : 288,
        height : 288
    });
var free = Draggable.createView({
        opacity : 0,
        backgroundColor : 'transparent',
        borderWidth : 4,
        borderColor : '#101010',
        borderRadius : 30,
        width : 60,
        height : 60,
        zIndex : 2
    });
free.addEventListener('move', function(e) {

var circle_cenx = container.width / 2;
        var circle_cenx = container.width / 2;
        var circle_ceny = container.width / 2;
        var circle_radius = container.width / 2;

        var result = limit(e.center.x, e.center.y, circle_cenx, circle_ceny, circle_radius);

        Ti.API.info("X: " + result.x);
        Ti.API.info("Y: " + result.y);

        free.left = (result.x - (free.width / 2));
        free.top = (result.y - (free.height / 2));

        Ti.API.info("free.left: " + (result.x - 30));
        Ti.API.info("free.top: " + (result.y - 30));

});

function limit(x, y, cenx, ceny, r) {
        var dist = distance([x, y], [cenx, ceny]);
        if (dist <= r) {
            return {
                x : x,
                y : y
            };
        } else {
            x = x - cenx;
            y = y - ceny;
            var radians = Math.atan2(y, x);
            return {
                x : Math.cos(radians) * r + cenx,
                y : Math.sin(radians) * r + ceny
            };
        }
    }

    function distance(dot1, dot2) {
        var x1 = dot1[0],
            y1 = dot1[1],
            x2 = dot2[0],
            y2 = dot2[1];
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    }

from tidraggable.

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.