PHP: Text Circle


I was messing around trying to create a circle tag cloud that I would later use jQuery to animate the text around the outside of the circle on mouse over events. The base level to this idea was to draw a circle. I graduated college with a math minor and it never ceases to amaze me how much I have forgot. To the point I had to look up the Wikipedia entry for circle to figure out how to calculate point in a circle.

Below is an example of how to draw a circle composed of absolutely positioned div tags with a period character.

1
2
3
4
5
6
7
8
9
$radius = 100;
$cent_x = 300;
$cent_y = 300;
 
for($i = 1; $i < 360;$i++) {
	$pos_x = $cent_x + ($radius * cos($i));
	$pos_y = $cent_y + ($radius * sin($i));
	echo '<div style="position:absolute;top:' . round($pos_x) . ';left:' . round($pos_y) . ';">.</div>';
}

Share on Facebook Share on Facebook


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!