Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.
Moderator: General Moderators
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Sun Jan 30, 2005 11:30 am
Pretty obvious code, but its useful. This function will generate an
n sided shape with a given radius.
Code: Select all
function shape($number_of_edges,$radius=100) {
$p = array();
$degrees = 360/$number_of_edges;
for ($i=0;$i<$number_of_edges;$i++) {
$cos = cos(deg2rad($degrees*$i));
$sin = sin(deg2rad($degrees*$i));
$x = 0;
$y = $radius;
$p[] = round($cos*($x) - $sin*($y));
$p[] = round($sin*($x) + $cos*($y));
}
return $p;
}
Last edited by
onion2k on Sun Dec 03, 2006 7:09 am, edited 1 time in total.
SidewinderX
Forum Contributor
Posts: 407 Joined: Fri Jul 16, 2004 9:04 pm
Location: NY
Post
by SidewinderX » Fri Dec 01, 2006 11:06 pm
I dont think this code works anymore as-is, maybe someone could clean it up
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Sun Dec 03, 2006 7:09 am
Done.