GUIKit`
GUIKit`
"IndexedImagePanel"
GUIKitで提供されていた機能は,組込みのWolfram言語にネイティブのインターフェース構造およびコントロール関数で利用できるようになった.
Widget["IndexedImagePanel"]
指標付きの画像パネルを表す.
詳細
- Widget["IndexedImagePanel"]を使用する際は,まずNeeds["GUIKit`"]を使って GUIKit をロードする必要がある.
- デフォルトで,画像はパネルの中央にスケールされないで表示される.画像がパネル全体を占めるようにスケールし直すことも可能である.
- 使用可能な特性:
-
"imageWidth" 1 画像の幅 "imageHeight" 1 画像の高さ "imagePixelSize" 1 ピクセルサイズ(整数) "imageColorMapSize" 0 カラーマップのサイズ "imageColorComponents" Null カラーマップにおける各色のコンポーネントのリスト "imagePixels" Null 各ピクセルの指標 "preferredSize" 画像の表示サイズ - 使用可能なイベント:
-
"mouseClicked" パネル内の任意の点でマウスがクリックされた際にトリガされるイベント - 使用可能なメソッド:
-
InvokeMethod["getImagePixelCoordinatesAt", mouseEvent] マウスイベント位置の画像の座標を返す - デフォルトで,ほとんどのメソッドは自動的に再描画はしないので,最終引数としてTrueまたはFalseを取ってメソッドのバージョンを呼び出すことができる.これによって画像中のさまざまな場所に複数の呼出しを行ってからInvokeMethod[{panel,"repaint"}]を,または最終引数をTrueとしてメソッドを呼び出すことができる.
例題
すべて開く すべて閉じる例 (1)
Needs["GUIKit`"]すべてのピクセルを黒に設定し,5色の指標付きの色で5×5の画像を作る:
ref = GUIRun[Widget["IndexedImagePanel", {
"preferredSize" -> Widget["Dimension", {"width" -> 20 * 5, "height" -> 20 * 5}],
"imageWidth" -> 5,
"imageHeight" -> 5,
"imagePixelSize" -> 20,
"imageColorMapSize" -> 5,
"imageColorComponents" -> Flatten[
{{0, 0, 0}, {255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}}],
"imagePixels" -> Flatten[ Table[0, {5}, {5}]]}, Name -> "imagePanel"]
]GUIScreenShot[ref]ref @ SetPropertyValue[{"imagePanel", "imagePixels"},
Flatten[ Table[1, {5}, {5}]]]GUIScreenShot[ref]Do[
ref @ SetPropertyValue[{"imagePanel", "imagePixels"},
Flatten[ Table[Random[Integer, {0, 4}], {5}, {5}]]],
{100}]GUIScreenShot[ref]各ループ内の最初の行のランダムなセルをランダムな値に設定して100回繰り返す:
Do[
pos = Random[Integer, {0, 4}];
ind = Random[Integer, {0, 4}];
ref @ InvokeMethod[{"imagePanel", "setImagePixel"}, pos, 0, ind];
, {100}]GUIScreenShot[ref]ref @ InvokeMethod[{"imagePanel", "repaint"}]GUIScreenShot[ref]"setImagePixel"の最終引数としてTrueを与え,先の2つのメソッドの呼出しを結合する:
Do[
pos = Random[Integer, {0, 4}];
ind = Random[Integer, {0, 4}];
ref @ InvokeMethod[{"imagePanel", "setImagePixel"}, pos, 0, ind, True];
, {100}]GUIScreenShot[ref]Do[
coords = Transpose[{Table[#, {5}]& @ Random[Integer, {0, 4}], Range[0, 4]}];
ind = Table[#, {5}]& @ Random[Integer, {0, 4}];
ref @ InvokeMethod[{"imagePanel", "setImagePixelArray"}, coords, ind, True];
, {100}]GUIScreenShot[ref]ref @ SetPropertyValue[{"imagePanel", "imageGrid"}, True]ref @ InvokeMethod[{"imagePanel", "repaint"}]GUIScreenShot[ref]ref @ Script[
SetPropertyValue[{"imagePanel", "imageGridColor"},
Widget["Color", InitialArguments -> {255, 0, 0}]]
]ref @ InvokeMethod[{"imagePanel", "repaint"}]GUIScreenShot[ref](サイズ調整後に)パネルの大きさにフィットするように画像をスケールする:
ref @ SetPropertyValue[{"imagePanel", "scaleImage"}, True]ref @ InvokeMethod[{"imagePanel", "repaint"}]GUIScreenShot[ref]ref @ SetPropertyValue[{"imagePanel", "preserveImageAspectRatio"}, True]ref @ InvokeMethod[{"imagePanel", "repaint"}]GUIScreenShot[ref]ref @ SetPropertyValue[{"imagePanel", "centerImage"}, False]ref @ InvokeMethod[{"imagePanel", "repaint"}]GUIScreenShot[ref]メソッド"fillImagePixels"は画像の個々のピクセルを塗り潰す:
ref @ InvokeMethod[{"imagePanel", "fillImagePixels"}, Random[Integer, {0, 4}], True]GUIScreenShot[ref]メソッド"fillImagePixelArray"は明示的な位置の配列を塗り潰す:
ref @ InvokeMethod[{"imagePanel", "fillImagePixelArray"}, {{0, 0}, {1, 1}, {1, 2}}, Random[Integer, {0, 4}], True]GUIScreenShot[ref]また,始点{x,y}値と相対的なオフセット位置で与えられる領域も塗り潰す:
ref @ InvokeMethod[{"imagePanel", "fillImagePixelArray"}, 2, 2, {{0, 0}, {1, 1}, {1, 2}}, Random[Integer, {0, 4}], True]GUIScreenShot[ref]ref @ InvokeMethod[{"imagePanel", "fillImagePixelArray"}, 0, 3, {{0, 0}, {1, 1}, {1, 2}}, Random[Integer, {0, 4}], True]GUIScreenShot[ref]メソッド"fillImagePixelRect"は長方形の領域を塗り潰す:
ref @ InvokeMethod[{"imagePanel", "fillImagePixelRect"}, 1, 1, 2, 3, Random[Integer, {0, 4}], True]GUIScreenShot[ref]"setImagePixelRect"とすると,領域を左上の位置で指定することもできるようになる:
ref @ InvokeMethod[{"imagePanel", "setImagePixelRect"}, 1, 1, {{0, 1, 0}, {1, 2, 1}}, True]GUIScreenShot[ref]インタラクティブな例題 (2)
Needs["GUIKit`"]各セルがクリックされるとランダムな色で塗り潰される画像を作成する:
ref = GUIRun[
Widget["IndexedImagePanel", {
"preferredSize" -> Widget["Dimension", {"width" -> 20 * 5, "height" -> 20 * 5}],
"imageWidth" -> 5,
"imageHeight" -> 5,
"imagePixelSize" -> 20,
"imageColorMapSize" -> 5,
"imageColorComponents" -> Flatten[
{{0, 0, 0}, {255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}}],
"imagePixels" -> Flatten[ Table[0, {5}, {5}]],
BindEvent["mouseClicked",
Script[
coords = InvokeMethod[{"imagePanel", "getImagePixelCoordinatesAt"},
WidgetReference["#"]];
InvokeMethod[{"imagePanel", "setImagePixel"}, coords, Random[Integer, {0, 4}], True];
]
]
}, Name -> "imagePanel",
WidgetLayout -> {"Stretching" -> {Maximize, Maximize}}]
]GUIScreenShot[ref]GUIScreenShot[ref]Needs["GUIKit`"]灰色の四角をクリックすると黒く,さらにクリックすると白と黒が交代する3色の画像を作成する:
ref = GUIRun[
Widget["Frame", {"title" -> "IndexedImage Demo",
"resizable" -> True,
Widget["IndexedImagePanel", {
"preferredSize" -> Widget["Dimension", {"width" -> 10 * 20, "height" -> 10 * 15}],
"imageWidth" -> 20,
"imageHeight" -> 15,
"imagePixelSize" -> 10,
"imageColorMapSize" -> 3,
"imageGrid" -> True,
"scaleImage" -> True,
"preserveImageAspectRatio" -> True,
"imageColorComponents" -> Flatten[
{{0, 0, 0}, {255, 255, 255}, {128, 128, 128}}],
"imagePixels" -> Flatten[ Table[2, {20}, {15}]],
BindEvent["mouseClicked",
Script[
mouseEvent = WidgetReference["#"];
coords = InvokeMethod[{"imagePanel", "getImagePixelCoordinatesAt"},
mouseEvent];
If[(coords[[1]] ≥ 0) && ( coords[[2]] ≥ 0),
vl = InvokeMethod[{"imagePanel", "getImagePixelAt"},
mouseEvent];
InvokeMethod[{"imagePanel", "setImagePixel"}, coords,
If[vl =!= 0, 0, 1], True];
];
]
]
}, Name -> "imagePanel",
WidgetLayout -> {"Stretching" -> {Maximize, Maximize}}]
}]
]GUIScreenShot[ref]GUIScreenShot[ref]