function make_cut_image($row, $verts, $width, $height) { $center = new vertex(0, 0, 0); $image = imagecreatetruecolor($width, $height); if (isset($_REQUEST['usealpha'])) { $trans_color = imagecolorallocatealpha($image, 255, 255, 255, 0); imagefill($image, 0, 0, $trans_color); } $verticies = explode("\n", $verts); $start = new vertex(0, 0, 0); $start->parse_llvector($verticies[0]); $count = count($verticies); $x = 0.0; $t = 0.0; $start_color = new vertex(0, 128, 0); $end_color = new vertex(255, 255, 255); $previous = $start; foreach ($verticies as $point) { $current = new vertex(0, 0, 0); $current->parse_llvector($point); $center->add($current); ++$x; } $center->mult(1.0 / $x); $x = 0; imagesetthickness($image, 2); foreach ($verticies as $point) { $t = $x / $count; $current = new vertex(0, 0, 0); $current->parse_llvector($point); if ($verticies[0] != $point) { $vcolor = $start_color->get_interp($end_color, $t); $color = $vcolor->allocate_color($image); fill_pie($image, $center, $previous, $current, $width, $height, $color); } $previous = $current; ++$x; } $color = imagecolorallocate($image, $end_color->x, $end_color->y, $end_color->z); fill_pie($image, $center, $previous, $start, $width, $height, $color); $x = 0; foreach ($verticies as $point) { ++$x; $t = $x / $count; $current = new vertex(0, 0, 0); $current->parse_llvector($point); $current->x = ($current->x + 1) * 0.5; $current->y = 1.0 - ($current->y + 1) * 0.5; $current->x *= $width; $current->y *= $height; $color = $color = imagecolorallocate($image, 255 * $t, 0, 255 * (1 - $t)); imagefilledellipse($image, intval($current->x), intval($current->y), 8, 8, $color); } return $image; }
function make_sculpty($verts, $sc, $o, $width, $height, $upsample, $smooth) { $image = imagecreatetruecolor($width, $height); $scale = new vertex(0, 0, 0); $orig = new vertex(0, 0, 0); $orig->load($o); $orig->mult(-1); $scale->load($sc); $scale->mult(0.5); //Radius $this_row = 0; foreach ($verts as $vert_row) { $x = 0; $row = explode("|", $vert_row); $point = FALSE; if (count($row) == 1) { $point = TRUE; } $y = $height - 1 - $this_row; foreach ($row as $v) { $vert = new vertex(0, 0, 0); $vert->load(explode(",", $v)); $vert->add($orig); $vert->combine($scale); $vert = $vert->get_color(); $color = $vert->allocate_color($image); if ($point) { imageline($image, 0, $y, $width - 1, $y, $color); break; } else { imagesetpixel($image, $x, $y, $color); } ++$x; if ($x >= $width) { break; } } $this_row++; if ($this_row >= $height) { break; } } //Up-sample the image if ($upsample) { $new_h = $height * 2; $new_w = $width * 2; $image_resampled = imagecreatetruecolor($new_w, $new_h); imagecopyresized($image_resampled, $image, 0, 0, 0, 0, $new_w, $new_h, $width, $height); imagedestroy($image); $image = $image_resampled; } if ($smooth == "gaussian") { $gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0)); imageconvolution($image, $gaussian, 16, 0); } if ($smooth == "linear") { $linear = array(array(1.0, 1.0, 1.0), array(1.0, 1.0, 1.0), array(1.0, 1.0, 1.0)); imageconvolution($image, $linear, 9, 0); } return $image; }