Java Geometry Algorithm starRunner(int[][] screen, int x, int y, List blueList)

Here you can find the source of starRunner(int[][] screen, int x, int y, List blueList)

Description

star Runner

License

Open Source License

Declaration

public static Point[] starRunner(int[][] screen, int x, int y, List<Point> blueList) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;
import java.awt.Point;

import java.util.List;

public class Main {
    public static Point[] starRunner(int[][] screen, int x, int y, List<Point> blueList) {
        if (x < 0 || y < 0 || x >= screen.length || y >= screen[0].length)
            return new Point[0];

        Color pixelColor = new Color(screen[x][y], true);
        if (!(pixelColor.getBlue() == 255 && pixelColor.getGreen() == 0 && pixelColor.getRed() == 0)) {
            // not blue
            Point[] containerArr = { new Point(x, y) };
            return containerArr;
        }/*  w w  w  . j  av a2  s .c o  m*/
        boolean didEndSoon = false;
        for (Point p : blueList) {
            if (p.x == x && p.y == y) {
                didEndSoon = true;
                break;
            }
        }
        if (didEndSoon) {
            // is on list
            return new Point[0];
        }

        blueList.add(new Point(x, y));

        // not on list, blue, so valid, untouched pixel
        Point[] up = starRunner(screen, x, y + 1, blueList);
        Point[] down = starRunner(screen, x, y - 1, blueList);
        Point[] right = starRunner(screen, x + 1, y, blueList);
        Point[] left = starRunner(screen, x - 1, y, blueList);

        Point[] totalArr = new Point[up.length + down.length + right.length + left.length];
        System.arraycopy(up, 0, totalArr, 0, up.length);
        System.arraycopy(down, 0, totalArr, up.length, down.length);
        System.arraycopy(right, 0, totalArr, up.length + down.length, right.length);
        System.arraycopy(left, 0, totalArr, up.length + down.length + right.length, left.length);
        return totalArr;
    }
}

Related

  1. setPathControlPoint(Shape s, int i, Point2D pt)
  2. setRevisePoint(Point2D.Double revisePoint, Point2D.Double startPoint)
  3. slopeOfLineBetween(Point2D.Double p1, Point2D.Double p2)
  4. smallestBoundingBox( java.awt.Point.Double[] points)
  5. snapToGrid(Point original, double gridSpacing)
  6. te static double t(Point2D.Double original, Point2D.Double endpt1, Point2D.Double endpt2)
  7. vecLength(final Point2D v)
  8. verticalParallelogram(Point2D top, Point2D bottom, double width)