Skip to content

Commit 7f280bc

Browse files
committed
spiral option in the Color Wheel filter
1 parent f5bddae commit 7f280bc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main/java/pixelitor/filters/ColorWheel.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class ColorWheel extends ParametrizedFilter {
4141
@Serial
4242
private static final long serialVersionUID = -8398979151631397821L;
4343

44+
private static final double SPIRAL_EFFECT_SCALE = 0.0005;
45+
4446
public enum ColorSpaceType {
4547
HSB {
4648
@Override
@@ -65,11 +67,13 @@ int toRGB(float hue, float sat, float bri) {
6567
private final AngleParam hueRotParam = new AngleParam("Rotate", 0);
6668
private final RangeParam brgLumParam = new RangeParam("Brightness (%)", 0, 75, 100);
6769
private final RangeParam satParam = new RangeParam("Saturation (%)", 0, 90, 100);
70+
private final RangeParam spiralParam = new RangeParam("Spiral", -100, 0, 100);
6871

6972
public ColorWheel() {
7073
super(false);
7174

72-
setParams(type, center, hueRotParam, brgLumParam, satParam);
75+
setParams(type, center,
76+
hueRotParam, brgLumParam, satParam, spiralParam);
7377
}
7478

7579
@Override
@@ -88,13 +92,15 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
8892
double sat = satParam.getPercentage();
8993
double brgLum = brgLumParam.getPercentage();
9094

95+
double spiral = spiralParam.getValueAsDouble();
96+
9197
var pt = new StatusBarProgressTracker(NAME, height);
9298

9399
Future<?>[] rowFutures = new Future[height];
94100
for (int y = 0; y < height; y++) {
95101
int finalY = y;
96102
Runnable rowTask = () -> processRow(
97-
destPixels, width, finalY, cx, cy, hueRot, sat, brgLum, space);
103+
destPixels, width, finalY, cx, cy, hueRot, sat, brgLum, space, spiral);
98104
rowFutures[y] = ThreadPool.submit(rowTask);
99105
}
100106
ThreadPool.waitFor(rowFutures, pt);
@@ -105,11 +111,19 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
105111

106112
private static void processRow(int[] destPixels, int width, int y,
107113
double cx, double cy, double hueRot,
108-
double saturation, double brightness, ColorSpaceType model) {
114+
double saturation, double brightness,
115+
ColorSpaceType model, double spiral) {
109116
for (int x = 0; x < width; x++) {
110117
double yDiff = cy - y;
111118
double xDiff = x - cx;
112-
double angle = FastMath.atan2(yDiff, xDiff) + hueRot;
119+
double baseAngle = FastMath.atan2(yDiff, xDiff);
120+
double angle = baseAngle + hueRot;
121+
if (spiral != 0.0) {
122+
double radius = FastMath.hypot(xDiff, yDiff);
123+
double spiralAngleOffset = spiral * radius * SPIRAL_EFFECT_SCALE;
124+
angle += spiralAngleOffset;
125+
}
126+
113127
double hue = angle / (2 * Math.PI);
114128

115129
destPixels[x + y * width] = model.toRGB((float) hue, (float) saturation, (float) brightness);

0 commit comments

Comments
 (0)