PHP Draws a custom graphic and vector map of 3D graphics

Source: Internet
Author: User

This article introduces the custom and vector diagram examples. First draw a three-pointed star, respectively, by "front", "Back" and three "side" composition. Custom Polygon

Code:

<?php
Require_once (' image/3d.php ');
$image = new Image_3d ();
$image->setcolor (New Image_3d_color (255, 255, 255));
To create a light source
$light 1 = $image->createlight (' Light ', array (-50,-50,-50));
$light 1->setcolor (New Image_3d_color (100, 250, 100));

$light 2 = $image->createlight (' Light ', array (50,-50, 0));
$light 2->setcolor (New Image_3d_color (100, 100, 250));

$light 3 = $image->createlight (' Light ', array (50, 50, 0));
$light 3->setcolor (New Image_3d_color (50, 0, 100));

Creating an array of polygons
$polygons = Array ();

Front Point coordinates
$polygons [] = Array (
Array (0, -120, 0), Array (-18,-12, 0),
Array ( -86, 0), array (0, 18, 0),
Array (0), Array (18,-12, 0)
);

Back Point coordinates
$polygons [] = Array (
Array (0, -120,), Array (-18,-12, 60),
Array ( -86, M, m), array (0, 18, 60),
Array (18,-12, 60).
);

Three-side point coordinates
$polygons [] = Array (
Array (0, -120, 0), Array (-18,-12, 0),
Array ( -86, 0), Array (-86, 48, 60),
Array ( -18, -12,), array (0,-120, 60)
);
$polygons [] = Array (
Array ( -86, 0), array (0, 18, 0),
Array (0), Array (86, 48, 60),
Array (0, a), array (-86, 48, 60)
);
$polygons [] = Array (
Array (0), Array (18,-12, 0),
Array (0, -120, 0), array (0,-120, 60),
Array ( -12,), Array (86, 48, 60)
);

Draw a 3D image
foreach ($polygons as $poly) {
$points = Array ();
foreach ($poly as $set) {
$points [] = new Image_3d_point ($set [0], $set [1], $set [2]);
}
$p = $image->createobject (' polygon ', $points);
$p->setcolor (New Image_3d_color (255, 255, 255));
}

$image->transform ($image->creatematrix (' rotation ', array (-10,-25,-15));
$image->createrenderer (' perspectively ');
$image->createdriver (' GD ');
$image->render ("Anim.png");
Echo ' ';
?>

Effect Chart:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.