Here you can find the source of findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex)
private static Point findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex)
//package com.java2s; /** 2048 playa - a 2048 autonomous player. * Copyright 2014-2015 MeBigFatGuy.com //from w ww . j a v a 2 s. c o m * Copyright 2014-2015 Dave Brosius * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and limitations * under the License. */ import java.awt.Point; import java.awt.image.BufferedImage; import java.awt.image.Raster; public class Main { private static Point findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex) { int curX = startX; int curY = startY; int[] pixel = new int[1]; Raster r = image.getRaster(); do { r.getPixel(curX, curY, pixel); if (pixel[0] == colorIndex) { return new Point(curX, curY); } curX += dirX; curY += dirY; } while (true); } }