FreeBASIC マニュアルのトップに戻る

FreeBASIC Customgfx

目次→描画ライブラリ参考→2次元 描画関数CUSTOM←オリジナル・サイト

CUSTOM 左にメニュー・フレームが表示されていない場合は、ここをクリックして下さい

←リンク元に戻る プログラム開発関連に戻る

カスタム操作命令を選択する 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 関数によって渡されたデータ・ポインタを受け取ります。
戻ってきた画素の値は、あて先バッファに描かれるために使われます。
この関数には、フォームがあります:

declare function identifier ( _
byval source_pixel as ulong, _
byval destination_pixel as ulong, _
byval parameter as any ptr _
) as ulong



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, ( 00)-(1515), RGB(255,   0,   0), bf
Line img, (160)-(3115), RGB(  0,   0, 255), bf
Line img, ( 0, 16)-(1531), RGB(  0, 255,   0), bf
Line img, (16, 16)-(3131), 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 との違い:

参照:

2次元描画関数に戻る

←リンク元に戻る プログラム開発関連に戻る

ページ歴史:2020-12-19 18:17:48
日本語翻訳:WATANABE Makoto、原文著作者:AntoniGual

ホームページのトップに戻る

表示-非営利-継承