Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fly.api.colors;
- import java.awt.Color;
- import java.awt.Point;
- import java.util.LinkedList;
- import java.util.List;
- import org.runedream.api.methods.Calculations;
- import org.runedream.api.methods.Game;
- import org.runedream.api.methods.ImageUtil;
- public class ColorUtils {
- public static Point[] findColor(final Color c) {
- List<Point> points = new LinkedList<Point>();
- if (c != null) {
- points = ImageUtil.getPointsWithColor(Game.getImage(), c, 0.01);
- if (!points.isEmpty()) {
- return points.toArray(new Point[points.size()]);
- }
- }
- return null;
- }
- public static Point findClosestPoint(final Point CENTER, final Color c) {
- final Point points[] = findColor(c);
- if (points != null) {
- return getClosestPoint(CENTER, points);
- }
- return null;
- }
- public static Point getClosestPoint(final Point CENTER,
- final Point... points) {
- Point nearest = null;
- double dist = -1;
- for (final Point point : points) {
- final double distTmp = Calculations.getDistanceBetween(point,
- CENTER);
- if (nearest == null || nearest != null && distTmp < dist) {
- dist = distTmp;
- nearest = point;
- }
- }
- return nearest;
- }
- }
Add Comment
Please, Sign In to add comment