-
Notifications
You must be signed in to change notification settings - Fork 60
/
FactoryTemplates.java
176 lines (160 loc) · 7.68 KB
/
FactoryTemplates.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.github.joonasvali.naturalmouse.util;
import com.github.joonasvali.naturalmouse.api.MouseMotionFactory;
import com.github.joonasvali.naturalmouse.api.SpeedManager;
import com.github.joonasvali.naturalmouse.support.DefaultMouseMotionNature;
import com.github.joonasvali.naturalmouse.support.DefaultNoiseProvider;
import com.github.joonasvali.naturalmouse.support.DefaultOvershootManager;
import com.github.joonasvali.naturalmouse.support.DefaultSpeedManager;
import com.github.joonasvali.naturalmouse.support.DoublePoint;
import com.github.joonasvali.naturalmouse.support.Flow;
import com.github.joonasvali.naturalmouse.support.MouseMotionNature;
import com.github.joonasvali.naturalmouse.support.SinusoidalDeviationProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FactoryTemplates {
/**
* <h1>Stereotypical granny using a computer with non-optical mouse from the 90s.</h1>
* Low speed, variating flow, lots of noise in movement.
*
* @return the factory
*/
public static MouseMotionFactory createGrannyMotionFactory() {
return createGrannyMotionFactory(new DefaultMouseMotionNature());
}
/**
* <h1>Stereotypical granny using a computer with non-optical mouse from the 90s.</h1>
* Low speed, variating flow, lots of noise in movement.
* @param nature the nature for the template to be configured on
* @return the factory
*/
public static MouseMotionFactory createGrannyMotionFactory(MouseMotionNature nature) {
MouseMotionFactory factory = new MouseMotionFactory(nature);
List<Flow> flows = new ArrayList<>(Arrays.asList(
new Flow(FlowTemplates.jaggedFlow()),
new Flow(FlowTemplates.random()),
new Flow(FlowTemplates.interruptedFlow()),
new Flow(FlowTemplates.interruptedFlow2()),
new Flow(FlowTemplates.adjustingFlow()),
new Flow(FlowTemplates.stoppingFlow())
));
DefaultSpeedManager manager = new DefaultSpeedManager(flows);
factory.setDeviationProvider(new SinusoidalDeviationProvider(9));
factory.setNoiseProvider(new DefaultNoiseProvider(1.6));
factory.getNature().setReactionTimeBaseMs(100);
DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
overshootManager.setOvershoots(3);
overshootManager.setMinDistanceForOvershoots(3);
overshootManager.setMinOvershootMovementMs(400);
overshootManager.setOvershootRandomModifierDivider(DefaultOvershootManager.OVERSHOOT_RANDOM_MODIFIER_DIVIDER / 2f);
overshootManager.setOvershootSpeedupDivider(DefaultOvershootManager.OVERSHOOT_SPEEDUP_DIVIDER * 2);
factory.getNature().setTimeToStepsDivider(DefaultMouseMotionNature.TIME_TO_STEPS_DIVIDER - 2);
manager.setMouseMovementBaseTimeMs(1000);
factory.setSpeedManager(manager);
return factory;
}
/**
* <h1>Robotic fluent movement.</h1>
* Custom speed, constant movement, no mistakes, no overshoots.
*
* @param motionTimeMsPer100Pixels approximate time a movement takes per 100 pixels of travelling
* @return the factory
*/
public static MouseMotionFactory createDemoRobotMotionFactory(long motionTimeMsPer100Pixels) {
return createDemoRobotMotionFactory(new DefaultMouseMotionNature(), motionTimeMsPer100Pixels);
}
/**
* <h1>Robotic fluent movement.</h1>
* Custom speed, constant movement, no mistakes, no overshoots.
*
* @param nature the nature for the template to be configured on
* @param motionTimeMsPer100Pixels approximate time a movement takes per 100 pixels of travelling
* @return the factory
*/
public static MouseMotionFactory createDemoRobotMotionFactory(
MouseMotionNature nature, long motionTimeMsPer100Pixels
) {
MouseMotionFactory factory = new MouseMotionFactory(nature);
final Flow flow = new Flow(FlowTemplates.constantSpeed());
double timePerPixel = motionTimeMsPer100Pixels / 100d;
SpeedManager manager = distance -> new Pair<>(flow, (long) (timePerPixel * distance));
factory.setDeviationProvider((totalDistanceInPixels, completionFraction) -> DoublePoint.ZERO);
factory.setNoiseProvider(((random, xStepSize, yStepSize) -> DoublePoint.ZERO));
DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
overshootManager.setOvershoots(0);
factory.setSpeedManager(manager);
return factory;
}
/**
* <h1>Gamer with fast reflexes and quick mouse movements.</h1>
* Quick movement, low noise, some deviation, lots of overshoots.
*
* @return the factory
*/
public static MouseMotionFactory createFastGamerMotionFactory() {
return createFastGamerMotionFactory(new DefaultMouseMotionNature());
}
/**
* <h1>Gamer with fast reflexes and quick mouse movements.</h1>
* Quick movement, low noise, some deviation, lots of overshoots.
* @param nature the nature for the template to be configured on
* @return the factory
*/
public static MouseMotionFactory createFastGamerMotionFactory(MouseMotionNature nature) {
MouseMotionFactory factory = new MouseMotionFactory(nature);
List<Flow> flows = new ArrayList<>(Arrays.asList(
new Flow(FlowTemplates.variatingFlow()),
new Flow(FlowTemplates.slowStartupFlow()),
new Flow(FlowTemplates.slowStartup2Flow()),
new Flow(FlowTemplates.adjustingFlow()),
new Flow(FlowTemplates.jaggedFlow())
));
DefaultSpeedManager manager = new DefaultSpeedManager(flows);
factory.setDeviationProvider(new SinusoidalDeviationProvider(SinusoidalDeviationProvider.DEFAULT_SLOPE_DIVIDER));
factory.setNoiseProvider(new DefaultNoiseProvider(DefaultNoiseProvider.DEFAULT_NOISINESS_DIVIDER));
factory.getNature().setReactionTimeVariationMs(100);
manager.setMouseMovementBaseTimeMs(250);
DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
overshootManager.setOvershoots(4);
factory.setSpeedManager(manager);
return factory;
}
/**
* <h1>Standard computer user with average speed and movement mistakes</h1>
* medium noise, medium speed, medium noise and deviation.
*
* @return the factory
*/
public static MouseMotionFactory createAverageComputerUserMotionFactory() {
return createAverageComputerUserMotionFactory(new DefaultMouseMotionNature());
}
/**
* <h1>Standard computer user with average speed and movement mistakes</h1>
* medium noise, medium speed, medium noise and deviation.
*
* @param nature the nature for the template to be configured on
* @return the factory
*/
public static MouseMotionFactory createAverageComputerUserMotionFactory(MouseMotionNature nature) {
MouseMotionFactory factory = new MouseMotionFactory(nature);
List<Flow> flows = new ArrayList<>(Arrays.asList(
new Flow(FlowTemplates.variatingFlow()),
new Flow(FlowTemplates.interruptedFlow()),
new Flow(FlowTemplates.interruptedFlow2()),
new Flow(FlowTemplates.slowStartupFlow()),
new Flow(FlowTemplates.slowStartup2Flow()),
new Flow(FlowTemplates.adjustingFlow()),
new Flow(FlowTemplates.jaggedFlow()),
new Flow(FlowTemplates.stoppingFlow())
));
DefaultSpeedManager manager = new DefaultSpeedManager(flows);
factory.setDeviationProvider(new SinusoidalDeviationProvider(SinusoidalDeviationProvider.DEFAULT_SLOPE_DIVIDER));
factory.setNoiseProvider(new DefaultNoiseProvider(DefaultNoiseProvider.DEFAULT_NOISINESS_DIVIDER));
factory.getNature().setReactionTimeVariationMs(110);
manager.setMouseMovementBaseTimeMs(400);
DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
overshootManager.setOvershoots(4);
factory.setSpeedManager(manager);
return factory;
}
}