Created
October 8, 2023 03:51
-
-
Save yowasou/9774c18cf3a4c8afd83ea0cf20a7e23e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double grayScaleFromPixel(img.Pixel px) { | |
return (px.r + px.g + px.b) / 3; | |
} | |
bool _hitTest(img.Image? clipImage, int x1, int y1, int x2, int y2, int width, | |
int height) { | |
// 切り抜き画像がnullかどうか | |
if (clipImage == null) { | |
return false; | |
} | |
//中心座標 | |
int centerX = ((x2 - x1) / 2).toInt(); | |
int centerY = ((y2 - y1) / 2).toInt(); | |
List<double> grayScales = [ | |
/* 中心 */ | |
grayScaleFromPixel(clipImage.getPixel(centerX, centerY)), | |
/* 右 */ | |
grayScaleFromPixel(clipImage.getPixel(centerX + 1, centerY)), | |
/* 左 */ | |
grayScaleFromPixel(clipImage.getPixel(centerX - 1, centerY)), | |
/* 下 */ | |
grayScaleFromPixel(clipImage.getPixel(centerX, centerY + 1)), | |
/* 上 */ | |
grayScaleFromPixel(clipImage.getPixel(centerX, centerY - 1)) | |
]; | |
double grayScale = grayScales.reduce((a, b) => a + b) / grayScales.length; | |
Logger.info('grayScales:${grayScales.toString()}'); | |
Logger.info('grayScale:${grayScale.toString()}'); | |
if (grayScale < 128) { | |
// 見つめてる | |
return true; | |
} else { | |
// 見つめてない | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment