pointing towards mouse snippet

edited April 2018 in Python Mode

i have seen many un-processonic codes for dealing with pointing towards mouse including the use of atan and PVector here is a natural solution :

def setup():
    size(640, 640)


def draw():
    background(255)
    translate(width/2, height/2)
    location = PVector(200, 200)
    mouse = PVector(mouseX, mouseY)

    mouse.sub(location) # vector from mouse to point
    mouse.normalize()
    mouse.mult(50)
    line(0, 0, mouse.x, mouse.y)

Comments

Sign In or Register to comment.