カスタム操作命令を選択する
Put 描画命令文へのパラメタ
構文:
Put [ target, ] [ STEP ] ( x,y ), source [ ,( x1,y1 )-( x2,y2 ) ], Custom, custom_function_ptr
[, parameter]
パラメタ:
Custom
必要。
custom_function_ptr
カスタムユーザ定義関数の名前。
parameter
カスタム関数に渡される任意の
POINTER ;
省略すると、デフォルト値は(
0)です。
説明:
Custom は、画像バッファに点描するための方法として、カスタム・ユーザ定義関数を選定します。
Custom 方法は、あて先バッファに描く、最終的なピクセル値を計算するのに、ユーザ定義関数を使います。
この関数は、ソース画像のあらゆる画素のために一度呼ばれて、ソースのピクセル値と、あて先のピクセル値、および、
Put 関数によって渡されたデータ・ポインタを受け取ります。
戻ってきた画素の値は、あて先バッファに描かれるために使われます。
この関数には、フォームがあります:
identifier は、関数の名前です。
source_pixel は、ソース画像の、現在のピクセル値です。
destination_pixel は、あて先画像の、現在のピクセル値です。
parameter は、
Put 命令で渡されるパラメタです。
これを省略すると、値はゼロになります。
例:
注意:FreeBASIC 1.08〜 で、SetEnviron を追加しなくても、日本語環境で描画画面が表示されるように改善されました。
' Sets the graphics method GDI
' 描画方法を GDI に設定
SetEnviron("fbgfx=GDI")
Function dither
( ByVal source_pixel
As UInteger,
ByVal destination_pixel
As UInteger,
ByVal parameter
As Any Ptr ) As UInteger
''rnd(乱数)の結果によって、元の画素か、あて先の画素を返します
Dim threshold
As Single =
0.
5
If parameter <>
0 Then threshold = *
CPtr
(Single Ptr, parameter
)
If Rnd() < threshold
Then
Return source_pixel
Else
Return destination_pixel
End If
End Function
Dim img
As Any Ptr, threshold
As Single
'' 画面を設定します
ScreenRes 320,
200,
16,
2
ScreenSet 0,
1
'' 画像を作成します
img =
ImageCreate
(32,
32)
Line img,
( 0,
0)-
(15,
15),
RGB(255,
0,
0), bf
Line img,
(16,
0)-
(31,
15),
RGB( 0,
0,
255), bf
Line img,
( 0,
16)-
(15,
31),
RGB( 0,
255,
0), bf
Line img,
(16,
16)-
(31,
31),
RGB(255,
0,
255), bf
'' dither the image with varying thresholds
'' 「震え、異なった敷居があるイメージ」
Do Until Len
(Inkey)
Cls
threshold =
0.
2
Put ( 80 -
16,
100 -
16), img,
Custom, @dither, @threshold
'' default threshold = 0.5 デフォルトの敷居は、0.5です
Put (160 -
16,
100 -
16), img,
Custom, @dither
threshold =
0.
8
Put (240 -
16,
100 -
16), img,
Custom, @dither, @threshold
ScreenCopy
Sleep 25
Loop
'' 画像メモリを解放します
ImageDestroy img
方言差:
QB との違い:
参照: