DEV Community

Cover image for DIV Points at Other DIV
Zevan Rosser
Zevan Rosser

Posted on • Edited on

2 1

DIV Points at Other DIV

Moving your mouse around the page, you’ll notice the red div always points at the black div.

I remember learning this from nooflat.nu by Jamie Macdonald back in 2001-2. I spun up my custom made experimental browser to take a look… also downloaded the source…

Excuse the music I was too lazy to open iMovie and add something decent… Here is the key part of the source where I learned about atan2 for the first time 😀

//SOURCE FOR EDUCATIONAL PURPOSES, ETC.
fscommand("allowscale","false")


// FUNCTION TO CALCULATE ANGLE FROM ONE OBJECT TO ANOTHER
function calcangle (me,targetclip) {

    // FIRST COMPUTE THE DISTANCES FROM THE MOVIECLIP THE FUNCTION
    // IS CALLED FROM  TO THE TARGET CLIP:
    var deltax = me._x-targetclip._x;
    var deltay = me._y-targetclip._y;

    // NEXT USE THESE DISTANCES TO CALCULATE THE ANGLE BETWEEN THEM:
    angle = Math.atan2(deltay, deltax);

    // FINALLY CONVERT THE ANGLE FROM RADIANS TO DEGREES AND THEN RETURN THE RESULT:
    angle /= (Math.pi/180);
    return angle;
}
Enter fullscreen mode Exit fullscreen mode

Brings back great memories…

See more stuff like this over @ Snippet Zone

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay