Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
Images
filetypeMatchesExtension($file)
imagelinerectangle()
issa clock
rotate_wide_line($x, $y, $width, $length, $degrees)
4
found
auth
Name:
Category: Images
Body:
// I was hacking away at a clock. somehow I ended up with this. // x, y are the center coords of where a line would be drawn from. // width, length are of that line. degrees starts at 0 pointing straight up and ends at 359 (supporting multiples and negatives and such). // It returns an array [x1, y1, .. x4, y4] (8 items) that can be used in .. wherever. They're pairs of coords. // Todo: rewrite the thing so that it can take rectangle coords as input, and coords to rotate around function rotate_wide_line($x, $y, $width, $length, $degrees) { $hw = $width / 2; $degrees = abs($degrees % 360); // normalize $m = ($degrees/360)*2*M_PI; // m for magic $lx = $x + sin($m) * $length; // these are what the end points of the line would be $ly = $y - cos($m) * $length; // we'll add offsets. $m2 = (($degrees-90)/360)*2*M_PI; // m for magic $coords[0] = $x - sin($m2) * $hw; // these are the x/y coords of the "first" corner of the resulting polygon $coords[1] = $y + cos($m2) * $hw; $ox = $x - $coords[0]; // grab some offsets $oy = $y - $coords[1]; $coords[2] = $x + $ox; // and apply to line coords for the rest of the coords $coords[3] = $y + $oy; $coords[4] = $lx + $ox; $coords[5] = $ly + $oy; $coords[6] = $lx - $ox; $coords[7] = $ly - $oy; return $coords; }
Footer