Page 1 of 1

Imagepolygon Stars (Now with pic) [56K WARNING]

Posted: Mon Jan 24, 2005 1:48 pm
by onion2k
I'm on a roll here. Playing with imagepolygon() stuff, I came up with a nice function to make stars..

Code: Select all

function star($number_of_points,$outer_radius=100,$inner_radius=40) {
		$p = array();
		$degrees = 360/($number_of_points*2);
		for ($i=0;$i<$number_of_points*2;$i++) {
			$cos = cos(deg2rad($degrees*$i));
			$sin = sin(deg2rad($degrees*$i));
			$x = 0;
			$y = ($i%2==0)?$outer_radius:$inner_radius;
			$p&#1111;] = $cos*($x) - $sin*($y);
			$p&#1111;] = $sin*($x) + $cos*($y);
		}
		return $p;
	}
Small isue with it at the moment coz it doesn't work with the rotatePolygon() function I posted yesterday. I'll fix it eventually. Unless someone else does.

Made a groovy pic using this function:

Image

Posted: Tue Feb 08, 2005 7:53 am
by Chris Corbyn
Wow that is pretty cool. I couldn't work it until I looked closer and saw that the whole picture is made from stars.

I like cool code like that... I hated maths at school but now with programming I see why we learnt it and how it can actually be pretty fun...

Nice one ;-) 8)

Posted: Sun Feb 13, 2005 8:01 pm
by windwaker
Whoa, that's awesome, though I can imagine that'll take up some CPU time. @_@

Posted: Wed Oct 26, 2005 10:18 am
by John Cartwright
Moved to Code Snipplets.