構文 | canvas.getColor( X, Y ) 戻り値: メイン画面のピクセルの色 |
説明 | メイン画面の(X,Y)座標のピクセルの色を取得します。 |
引数 | X: メイン画面のX座標 Y: メイン画面のY座標 |
戻り値 | メイン画面のピクセルの色 取得値は32ビットの値で、先頭からアルファ値(8ビット)、レッド(8ビット)、グリーン(8ビット)、ブルー(8ビット)に分かれて入った状態で取得されます。 |
------------------------------------------
-- メイン画面の(X,Y)座標のピクセルの色を取得するサンプル getColor_sample.lua
------------------------------------------
Blue = color(0,0,255)-- 青(ブルー)
Red = color(255, 0, 0) -- 赤(レッド)
Green = color( 0, 255, 0) -- 緑(グリーン)
Purple = color(255, 128, 0) -- 橙(オレンジ)
Black = color( 0, 0, 0) -- 黒(ブラック)
White = color(255, 255, 255) -- 白(ホワイト)
Yellow = color(255, 255, 0) -- 黄(イエロー)
function main()
local x, y = 0
local R, G, B
local r, g, b, a, cc
local w,h = canvas.getviewSize()
local xx, yy = 0, 50
canvas.drawCls(White)
canvas.drawText( "メイン画面の(X,Y)座標のピクセルの色を取得するサンプル", 0, 0, 24, Black)
canvas.drawText("画面の右下の四角枠内のタッチで終了します。", 0, 30, 24, Black)
canvas.drawRect( w-100, h-100, w-2, h-2, Black)
canvas.drawRect( 0,100, 100, 200,Blue,1)
canvas.drawRect( 100,100, 200, 200,Red,1)
canvas.drawRect( 200,100, 300, 200,Green,1)
canvas.drawRect( 300,100, 400, 200,Purple,1)
canvas.drawRect( 400,100, 500, 200,Black,1)
canvas.drawRect( 500,100, 600, 200,White,1)
canvas.drawRect( 600,100, 700, 200,Yellow,1)
while not ((x >= w-100 and x <= w-2) and (y >= h-100 and y <= h-2)) do
x,y,mode = touch(0)
if mode == 0 or mode == 2 then
cc = canvas.getColor( x, y)
a = math.fmod(math.floor(cc/256/256/256),256)
r = math.fmod(math.floor(cc/256/256),256)
g = math.fmod(math.floor(cc/256),256)
b = math.fmod(cc,256)
canvas.drawText( "R="..r.." ", 0, 220, 24, Black, White)
canvas.drawText( "G="..g.." ", 0, 250, 24, Black, White)
canvas.drawText( "B="..b.." ", 0, 280, 24, Black, White)
canvas.drawText( "A="..a.." ", 0, 310, 24, Black, White)
end
end
end
main()