PHPTurtle – turtle graphics library for PHP

This is the website of PHPTurtle – PHP library for doing turtle graphics. The motto of this library is Tuptusiu, w drogę! The library can be distributed under GPLv3 or any other OSI approved open source licence.

You can download the library here.

Example of usage – stars

include('../phpturtle/turtle.php');
$im = new Image(210, 210);
$zolw = new Turtle($im);
// place the turtle in the middle of image
$zolw->goto(105, 105);
$i = 0;
while ($i < 25) {
	// set the color of turtle's pen
	$zolw->set_color(10*$i, 5*$i, 255-(10*$i), 20);
	$j = 0;
	while ($j < 9) {
		// forward the turtle 100 pixels
		$zolw->move(100);
		// move the turtle 160 degrees
		$zolw->rotate(160);
		$j++;
	}
	// move the turtle 24 degrees
	$zolw->rotate(24);
	$i++;
}
// send the image to the browser
$im->send_gif();

Example of usage – writing the text

include('../phpturtle/turtle.php');
$im = new Image(800, 400);
$myturtle = new Turtle($im);
$myturtle->goto(400, 200);
$myturtle->font = "FreeMono.ttf";
$i = 0;
while ($i < 12) {
	$myturtle->set_color(18*$i, 5*$i, 255-(7*$i), 0);
	$myturtle->rotate(45);
	$myturtle->write('kaloryfer', $i*3);
	$myturtle->move($i*17);
	$i++;
}
$im->send_gif();