The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: Degrees To Eight Way Direction [JS]

Important!

Dear visitors,

This blog and the Tigarus.com network will be changing our website software in May (2024). There will be some down time and there will be a change to the webpage addresses.

We will also be removing the Anime blogs. The Rocksmith Songs website will be unavailable of a few weeks or months while I move the database to the new software.

At the moment we are running on Wordpress, the new software is an in-house project which is 57 times faster. It will also provide more freedom for development.

Thank you for understanding.

, By Patcoola

Script Title: degToEightDir
Programming Language: Java Script
Date Completed: 2012/09/02

Purpose: To determine the direction something is from degrees. Returns a number between 0-7.

Advertisement

Donate Now!

I don't always use the women's bathroom, but when I do, you can bet it really smells. If you like my blog, please consider donating.


Description: Determine the direction something is based on an eight way system of direction from degrees. Determines the direction using eight directions, returns a number ( 0,1,2,3,4,5,6,7 ), returns NaN (Not a Number) if the degrees argument is not a number, is a value greater than 360 or is a value lesser than -360.

Returned Values:

0 – Top
1 – Top Right
2 – Right
3 – Bottom Right
4 – Bottom
5 – Bottom Left
6 – Left
7 – Top Left
NaN – If the degrees_n argument is not valid

Method:

degToEightDir ( degrees_n ); // Returns a number

Arguments: degrees_n, accepts a number between -360 to 360.

Example Usage:

degToEightDir ( 180 ); // Returns 4

degToEightDir ( -180 ); // Returns 4

degToEightDir ( 760 ); // Returns NaN

 

Advertisement

Donate Now!

Hi there, I spend a lot of time making this blog.

It would be great if you would consider donating.


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.

 
20.558854 milliseconds