程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> PHP繪制3D圖形之自定義圖形及矢量圖

PHP繪制3D圖形之自定義圖形及矢量圖

編輯:PHP綜合

本篇介紹自定義及矢量圖實例。首先繪制一個三尖角星體,分別由“前面”,“後面”和三個“側面”組成。 自定義多邊形

代碼:

<?php
require_once('Image/3D.php');
$image = new Image_3D();
$image->setColor(new Image_3D_Color(255, 255, 255));
//創建光源 
$light1 = $image->createLight('light',array(-50, -50, -50));
$light1->setColor(new Image_3D_Color(100, 250, 100));

$light2 = $image->createLight('light',array(50, -50, 0));
$light2->setColor(new Image_3D_Color(100, 100, 250));

$light3 = $image->createLight('light',array(50, 50, 0));
$light3->setColor(new Image_3D_Color(50, 0, 100));

//創建多邊形數組
$polygons = array();

//前面點坐標
$polygons[] = array(
        array(0, -120, 0), array(-18, -12, 0),
        array(-86, 48, 0), array(0, 18, 0),
        array(86, 48, 0), array(18, -12, 0)
       );

//後面點坐標
$polygons[] = array(
        array(0, -120, 60), array(-18, -12, 60),
        array(-86, 48, 60), array(0, 18, 60),
        array(86, 48, 60), array(18, -12, 60)
       );

//三側面點坐標
$polygons[] = array(
        array(0, -120, 0), array(-18, -12, 0),
        array(-86, 48, 0), array(-86, 48, 60),
        array(-18, -12, 60),array(0, -120, 60)
       );
$polygons[] = array(
        array(-86, 48, 0), array(0, 18, 0),
        array(86, 48, 0), array(86, 48, 60),
        array(0, 18, 60), array(-86, 48, 60)
       );
$polygons[] = array(
        array(86, 48, 0), array(18, -12, 0),
        array(0, -120, 0), array(0, -120, 60),
        array(18, -12, 60),array(86, 48, 60)
       );

//繪制3D圖像 
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(300, 300, 'anim.png');
echo '<img src="anim.png">';
?>

效果圖:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved