Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package input;
- import java.awt.Point;
- import java.util.ArrayList;
- import api.methods.Client;
- public class BeizerSplineGenerator {
- Mouse parent =input.Mouse.getMouse();
- public BeizerSplineGenerator() {
- this.parent = parent;
- }
- protected final void moveMouseSpline(Point start, Point end) {
- if (start == null || end == null)
- return;
- try {
- int curveHeight = (int) (Math
- .ceil(Point.distance(start.getX(),start.getY(),end.getX(),end.getY())) / Client
- .random(5, 15));
- int largeCurveHeight = (int) (curveHeight * Client
- .random(2, 3));
- int curveCount = Client.random(8, 10);
- int small = Math.min(curveHeight, largeCurveHeight);
- Point[] midpoints = new Point[curveCount - 1];
- for (int i = 1; i < curveCount; i++)
- midpoints[i - 1] = new Point(((start.x + end.x) * i)
- / curveCount, ((start.y + end.y) * i) / curveCount);
- Point last = start;
- Point c1 = randomCirclePoint(small, last);
- Point c2 = randomCirclePoint(small, end);
- moveMouseBezier(last, c1, c2, end);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- this.parent.mouseSpline.clear();
- }
- }
- private void omitPoints(final ArrayList<Point> spline) {
- if (spline.size() < 2)
- return;
- ArrayList<Point> newSpline = new ArrayList<Point>();
- Point last = spline.get(0);
- double mid = spline.size() / 2.00D;
- double multiplier1 = Client.random(11000, 13000) / 1000D;
- double multiplier2 = Client.random(11000, 13000) / 1000D;
- double nDist = Client.random(
- Client.random(8, 10), 12)
- - (Math.abs(0 - mid) / mid) * multiplier1;
- for (int i = 1; i < spline.size(); i++) {
- if (i == spline.size() - 1) {
- if (!spline.get(i).equals(last))
- newSpline.add(spline.get(spline.size() - 1));
- break;
- }
- if (spline.get(i).equals(last))
- continue;
- if (Point.distance(spline.get(i).getX(),spline.get(i).getY(),last.getX(), last.getY()) > nDist) {
- if (i > mid) {
- if (Client.random(0, 1) == 0)
- multiplier2 += (Client.random(0,
- 1000) / 100000D);
- else
- multiplier2 -= (Client.random(0,
- 1000) / 100000D);
- } else {
- if (Client.random(0, 1) == 0)
- multiplier1 += (Client.random(0,
- 1000) / 100000D);
- else
- multiplier1 -= (Client.random(0,
- 1000) / 100000D);
- }
- newSpline.add(spline.get(i));
- last = spline.get(i);
- nDist = Client.random(
- Client.random(8, 10), 12)
- - (Math.abs(i - mid) / mid)
- * (i > mid ? multiplier2 : multiplier1);
- }
- }
- spline.clear();
- spline.addAll(newSpline);
- }
- private int fittsLaw(double delay, double dist, double size, double speed) {
- return (int) (delay + speed * Math.log10(dist / size + 1)
- / Math.log10(2));
- }
- private void moveMouseBezier(Point p1, Point p2, Point p3, Point p4) {
- int baseSpeed = 45;
- ArrayList<Point> spline = generateSpline(p1, p2, p3, p4);
- omitPoints((this.parent.mouseSpline = spline));
- if (this.parent.stopMovement)
- this.parent.stopMovement = false;
- for (int i = 0; i < this.parent.mouseSpline.size(); i++) {
- if (this.parent.stopMovement)
- break;
- Point p = this.parent.mouseSpline.get(i);
- Mouse.setMousePos(p.x, p.y);
- if (i == this.parent.mouseSpline.size() - 1)
- break;
- double dist = p.distance(this.parent.mouseSpline.get(i + 1));
- sleep(fittsLaw((300.0D / this.parent.mouseSpline.size()),
- dist, 1, ((200 - 5)
- - baseSpeed + Client
- .random(2, 3)) / 20.0D));
- }
- }
- public static void sleep(int z) {
- try {
- Thread.sleep(z);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public ArrayList<Point> generateSpline(Point start, Point controlPoint1,
- Point controlPoint2, Point end) {
- ArrayList<Point> spline = new ArrayList<Point>();
- double d = Math.ceil(start.distance(end));
- for (int i = 0; i < d; i++) {
- Point next = bezierFunction(start.x, start.y, controlPoint1.x,
- controlPoint1.y, controlPoint2.x, controlPoint2.y, end.x,
- end.y, i / d);
- spline.add(next);
- if (next.equals(end))
- break;
- }
- return spline;
- }
- private Point bezierFunction(int x1, int y1, int x2, int y2, int x3,
- int y3, int x4, int y4, double t) {
- double a = Math.pow(1 - t, 3);
- double b = 3 * Math.pow(1 - t, 2) * t;
- double c = (3 * (1 - t)) * Math.pow(t, 2);
- double d = Math.pow(t, 3);
- double newX = (a * x1) + (b * x2) + (c * x3) + (d * x4);
- double newY = (a * y1) + (b * y2) + (c * y3) + (d * y4);
- return new Point((int) newX, (int) newY);
- }
- private int circleFunction(int r2, int val) {
- return (int) Math.round(Math.sqrt(r2 - Math.pow(val, 2)));
- }
- private final Point randomCirclePoint(int radius, Point center) {
- boolean high = Client.random(0, 2) == 0;
- boolean negate = Client.random(0, 2) == 0;
- int x, y;
- if (high) {
- y = Client.random(center.y - radius + 1,
- center.y + radius);
- x = circleFunction(radius * radius, y - center.y);
- x = negate ? center.x - x : x + center.x;
- } else {
- x = Client.random(center.x - radius + 1,
- center.x + radius);
- y = circleFunction(radius * radius, x - center.x);
- y = negate ? center.y - y : y + center.y;
- }
- return new Point(x, y);
- }
- }
Add Comment
Please, Sign In to add comment