Guest User

Untitled

a guest
Jul 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package com.fly.api.colors;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Point;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7.  
  8. import org.runedream.api.methods.Calculations;
  9. import org.runedream.api.methods.Game;
  10. import org.runedream.api.methods.ImageUtil;
  11.  
  12. public class ColorUtils {
  13.  
  14. public static Point[] findColor(final Color c) {
  15. List<Point> points = new LinkedList<Point>();
  16. if (c != null) {
  17. points = ImageUtil.getPointsWithColor(Game.getImage(), c, 0.01);
  18. if (!points.isEmpty()) {
  19. return points.toArray(new Point[points.size()]);
  20. }
  21. }
  22. return null;
  23. }
  24.  
  25. public static Point findClosestPoint(final Point CENTER, final Color c) {
  26. final Point points[] = findColor(c);
  27. if (points != null) {
  28. return getClosestPoint(CENTER, points);
  29. }
  30. return null;
  31. }
  32.  
  33. public static Point getClosestPoint(final Point CENTER,
  34. final Point... points) {
  35. Point nearest = null;
  36. double dist = -1;
  37. for (final Point point : points) {
  38. final double distTmp = Calculations.getDistanceBetween(point,
  39. CENTER);
  40. if (nearest == null || nearest != null && distTmp < dist) {
  41. dist = distTmp;
  42. nearest = point;
  43. }
  44. }
  45. return nearest;
  46. }
  47.  
  48. }
Add Comment
Please, Sign In to add comment