Friday, January 21, 2011

Graphvizで背景色を指定する

Graphvizで背景色を指定するには、以下のようにbgcolor attributeを使用します。

graph5.dot(UTF-8で保存)
graph graph5
{
graph[bgcolor="#ccddff"];
node [fontname="MS Gothic"];
項目1 -- 項目2 -- 項目3;
項目2 -- 項目4;
}

実行コマンド
dot -Gviewport=200,200 -Gresolution=72 -Tpng graph5.dot -o test5.png

出力画像


動作環境
Graphviz 2.26.3

関連情報
Graphvizまとめ
graphvizのサイト
http://graphviz.org/

Thursday, January 20, 2011

VPythonでレンダリング時間を表示する

VPythonでレンダリング時間を表示するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# レンダリング時間を表示
scene.show_rendertime = True
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Tuesday, January 18, 2011

Graphvizでノードの文字色を指定する

Graphvizでノードの文字色を指定するには、以下のようにfontcolor attributeを使用します。

graph4.dot(UTF-8で保存)
graph graph4
{
node [fontname="MS Gothic"];
項目2[fontcolor="#ffaa00"];
項目1 -- 項目2 -- 項目3;
項目2 -- 項目4;
}

実行コマンド
dot -Gviewport=200,200 -Gresolution=72 -Tpng graph4.dot -o test4.png

出力画像


動作環境
Graphviz 2.26.3

関連情報
Graphvizまとめ
graphvizのサイト
http://graphviz.org/

Monday, January 17, 2011

VPythonで環境光を設定する

VPythonで環境光を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 環境光を設定
scene.ambient = (0x20/255.,0xdd/255.,0x66/255.)
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0xff/255.,0xff/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Saturday, January 15, 2011

Graphvizでノードの塗りつぶし色を指定する

Graphvizでノードの塗りつぶし色を指定するには、以下のようにfillcolor attributeを使用します(styleにfilledを指定する必要あります)。

graph3.dot(UTF-8で保存)
graph graph3
{
node [fontname="MS Gothic"];
項目2[fillcolor="#ccddff", style="filled"];
項目1 -- 項目2 -- 項目3;
項目2 -- 項目4;
}

実行コマンド
dot -Gviewport=200,200 -Gresolution=72 -Tpng graph3.dot -o test3.png

出力画像


○動作環境
Graphviz 2.26.3/2.38.0
○インストール
・Debian StretchにGraphvizをインストールする場合は、以下のコマンドを実行します。
sudo apt-get install graphviz
○関連情報
Graphvizまとめ
・graphvizのサイト
http://graphviz.org/

Friday, January 14, 2011

VPythonで背景色を設定する

VPythonで背景色を設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 背景色を設定
scene.background = (0xdd/255.,0xee/255.,0xff/255.)
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Wednesday, January 12, 2011

Graphvizでノードの線の色を指定する

Graphvizでノードの線の色を指定するには、以下のようにcolor attributeを使用します。

graph2.dot(UTF-8で保存)
graph graph2
{
node [fontname="MS Gothic"];
項目2[color="#7799dd"];
項目1 -- 項目2 -- 項目3;
項目2 -- 項目4;
}

実行コマンド
dot -Gviewport=200,200 -Gresolution=72 -Tpng graph2.dot -o test2.png

出力画像


○動作環境
Graphviz 2.26.3/2.38.0
○インストール
・Debian StretchにGraphvizをインストールする場合は、以下のコマンドを実行します。
sudo apt-get install graphviz
○関連情報
Graphvizまとめ
・graphvizのサイト
http://graphviz.org/

Tuesday, January 11, 2011

VPythonでウインドウタイトルを設定する

VPythonでウインドウタイトルを設定するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# ウインドウのタイトルを設定
scene.title = 'VPython sample'
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Saturday, January 08, 2011

Graphvizで日本語のグラフを描画する

Graphvizで日本語のグラフを描画するには、以下のコマンドを実行します。
dot -Gviewport=200,200 -Gresolution=72 -Tpng graph1.dot -o test1.png

graph1.dot(UTF-8で保存)
graph graph1
{
node [fontname="MS Gothic"];
項目1 -- 項目2 -- 項目3;
項目2 -- 項目4;
}


出力画像


○動作環境
Graphviz 2.26.3/2.38.0
○インストール
・Debian StretchにGraphvizをインストールする場合は、以下のコマンドを実行します。
sudo apt-get install graphviz
○関連情報
Graphvizまとめ
・graphvizのサイト
http://graphviz.org/

VPythonでラベルを描画する

VPythonでラベルを描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 球を作成
sphere1 = sphere(pos=(0, 0, 0), radius=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# ラベルを作成
textlabel = label(pos=sphere1.pos,
text='球のサンプル', xoffset=70,
yoffset=80, space=100,
color=(0xff/255.,0xdd/255.,0x66/255.),
linecolor=(0xcc/255.,0xcc/255.,0xcc/255.),
height=20, border=6,
font='MS ゴシック')



実行画面


動作環境
Python 3.1.3, VPython 5.41

Wednesday, January 05, 2011

VPythonで螺旋を描画する

VPythonで螺旋を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 螺旋を作成
helix1 = helix(pos=(0, 0, 0), radius=0.6,
color=(0x99/255.,0xdd/255.,0xff/255.))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Sunday, January 02, 2011

VPythonで矢印を描画する

VPythonで矢印を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 矢印を作成
arrow1 = arrow(pos=(0, 0, 0), shaftwidth=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
arrow1.rotate(angle=pi*110./180., axis=(1,0,1))


実行画面


動作環境
Python 3.1.3, VPython 5.41

Thursday, December 30, 2010

VPythonで楕円を描画する

VPythonで楕円を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 楕円を作成
ellipsoid1 = ellipsoid(pos=(0, 0, 0), size=(2,0.5,0.5),
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
ellipsoid1.rotate(angle=pi*110./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Tuesday, December 28, 2010

PHPとGDで半透明のノイズがかかった画像に変換する

PHPとGDで半透明のノイズがかかった画像に変換するには、以下のコードを実行します。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja"
xml:lang="ja" dir="ltr">
<head>
<title>gd_test7</title>
</head>
<body>
<?php
// 入力ファイル名
$fn = "sf.jpg";
// 入力ファイルサイズ取得
$bimg = imagecreatefromjpeg($fn);
//imagefilter($bimg, IMG_FILTER_GRAYSCALE);
$sx = imagesx($bimg);
$sy = imagesy($bimg);

$img = imagecreatetruecolor($sx, $sy);
imagesavealpha($img, true);
imagealphablending($img, false);
// 半透明のノイズをかける
for($ly=0;$ly<$sy;$ly++){
for($lx=0;$lx<$sx;$lx++){
$pa = rand(5,40);
$px = imagecolorat($bimg, $lx, $ly);
$pr = ($px >> 16) & 0xff;
$pg = ($px >> 8 ) & 0xff;
$pb = $px & 0xff;
imagesetpixel($img, $lx, $ly,
imagecolorresolvealpha($img, $pr, $pg, $pb, $pa));
}
}
// ファイル出力
imagepng($img, "gd_test7.png");
// 開放
imagedestroy($img);
imagedestroy($bimg);
?>
<img src="gd_test7.png" /><br />
</body>
</html>



元画像


出力画像


動作環境
Apache httpd 2.2.17, PHP5.3.3

Monday, December 27, 2010

VPythonで円錐を描画する

VPythonで円錐を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# 円錐を作成
cone1 = cone(pos=(0, 0, 0), radius=0.25, length=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
cone1.rotate(angle=pi*110./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Saturday, December 25, 2010

PHPとGDで半透明の網掛けがかかった画像に変換する

PHPとGDで半透明の網掛けがかかった画像に変換するには、以下のコードを実行します。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja"
xml:lang="ja" dir="ltr">
<head>
<title>gd_test6</title>
</head>
<body>
<?php
// 入力ファイル名
$fn = "sf.jpg";
// 入力ファイルサイズ取得
$bimg = imagecreatefromjpeg($fn);
//imagefilter($bimg, IMG_FILTER_GRAYSCALE);
$sx = imagesx($bimg);
$sy = imagesy($bimg);

$img = imagecreatetruecolor($sx, $sy);
imagesavealpha($img, true);
imagealphablending($img, false);
// 半透明の網掛けをかける
for($ly=0;$ly<$sy;$ly++){
for($lx=0;$lx<$sx;$lx++){
$pa = (($ly + $lx)% 2 == 0)?0:0x40;
$px = imagecolorat($bimg, $lx, $ly);
$pr = ($px >> 16) & 0xff;
$pg = ($px >> 8 ) & 0xff;
$pb = $px & 0xff;
imagesetpixel($img, $lx, $ly,
imagecolorresolvealpha($img, $pr, $pg, $pb, $pa));
}
}
// ファイル出力
imagepng($img, "gd_test6.png");
// 開放
imagedestroy($img);
imagedestroy($bimg);
?>
<img src="gd_test6.png" /><br />
</body>
</html>



元画像


出力画像


動作環境
Apache httpd 2.2.17, PHP5.3.3

Friday, December 24, 2010

VPythonでシリンダーを描画する

VPythonでシリンダーを描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# シリンダーを作成
cylinder1 = cylinder(pos=(0, 0, 0), radius=0.25, length=1,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
cylinder1.rotate(angle=pi*110./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Wednesday, December 22, 2010

PHPとGDで半透明ストライプのかかった画像に変換する

PHPとGDで半透明ストライプのかかった画像に変換するには、以下のコードを実行します。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja"
xml:lang="ja" dir="ltr">
<head>
<title>gd_test5</title>
</head>
<body>
<?php
// 入力ファイル名
$fn = "sf.jpg";
// 入力ファイルサイズ取得
$bimg = imagecreatefromjpeg($fn);
//imagefilter($bimg, IMG_FILTER_GRAYSCALE);
$sx = imagesx($bimg);
$sy = imagesy($bimg);

$img = imagecreatetruecolor($sx, $sy);
imagesavealpha($img, true);
imagealphablending($img, false);
// 半透明のストライプの入った画像を作成
for($ly=0;$ly<$sy;$ly++){
$pa = ($ly % 2 == 0)?0:0x30;
for($lx=0;$lx<$sx;$lx++){
$px = imagecolorat($bimg, $lx, $ly);
$pr = ($px >> 16) & 0xff;
$pg = ($px >> 8 ) & 0xff;
$pb = $px & 0xff;
imagesetpixel($img, $lx, $ly,
imagecolorresolvealpha($img, $pr, $pg, $pb, $pa));
}
}
// ファイル出力
imagepng($img, "gd_test5.png");
// 開放
imagedestroy($img);
imagedestroy($bimg);
?>
<img src="gd_test5.png" /><br />
</body>
</html>



元画像


出力画像


動作環境
Apache httpd 2.2.17, PHP5.3.3

Tuesday, December 21, 2010

VPythonでリング型を描画する

VPythonでリング型を描画するには、以下のコードを実行します。

# coding=UTF-8
from visual import *
# リングを作成
ring1 = ring(pos=(0, 0, 0), radius=1, thickness=0.2,
color=(0x99/255.,0xdd/255.,0xff/255.))
# 回転
ring1.rotate(angle=pi*90./180., axis=(1,0,1))


出力画面


動作環境
Python 3.1.3, VPython 5.41

Sunday, December 19, 2010

PHPとGDでグラデーションのかかった画像に変換する

PHPとGDでグラデーションのかかった画像に変換するには、以下のコードを実行します。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja"
xml:lang="ja" dir="ltr">
<head>
<title>gd_test4</title>
</head>
<body>
<?php
// 入力ファイル名
$fn = "sf.jpg";
// 入力ファイルサイズ取得
$bimg = imagecreatefromjpeg($fn);
imagefilter($bimg, IMG_FILTER_GRAYSCALE);
$sx = imagesx($bimg);
$sy = imagesy($bimg);
// グラデーション用画像を作成
$img = imagecreate($sx, $sy);
imagesavealpha($img, true);
imagealphablending($img, false);
// 半透明グラデーションを作成
$c1 = 0xffff10;
$c2 = 0x3070a0;
for($ly=0;$ly<$sy;$ly++){
$r1 = ($c1 >> 16) & 0xff;
$g1 = ($c1 >> 8 ) & 0xff;
$b1 = $c1 & 0xff;
$r2 = ($c2 >> 16) & 0xff;
$g2 = ($c2 >> 8 ) & 0xff;
$b2 = $c2 & 0xff;
$ro = $r1 + round(($r2 - $r1)/$sy*$ly);
$go = $g1 + round(($g2 - $g1)/$sy*$ly);
$bo = $b1 + round(($b2 - $b1)/$sy*$ly);
for($lx=0;$lx<$sx;$lx++){
imagesetpixel($img, $lx, $ly,
imagecolorresolve($img, $ro, $go, $bo));
}
}

// 重ね合わせ
imagecopymerge($bimg, $img, 0, 0, 0, 0, $sx, $sy, 50);

// ファイル出力
imagepng($bimg, "gd_test4.png");
// 開放
imagedestroy($bimg);
imagedestroy($img);
?>
<img src="gd_test4.png" /><br />
</body>
</html>



元画像


出力画像


動作環境
Apache httpd 2.2.17, PHP5.3.3