use of com.helospark.tactview.core.timeline.image.ClipImage in project tactview by helospark.
the class RadialGradientService method createImageWithGradient.
public ClipImage createImageWithGradient(RadialGradientRequest request) {
Point center = request.getCenter();
double radius = request.getRadius();
Color startColor = request.getStartColor();
Color endColor = request.getEndColor();
double innerSaturation = request.getInnerSaturation();
ClipImage result = ClipImage.fromSize(request.getWidth(), request.getHeight());
independentPixelOperation.executePixelTransformation(request.getWidth(), request.getHeight(), (x, y) -> {
double distance = center.distanceFrom(x, y);
if (distance > radius) {
setColor(result, x, y, endColor);
} else {
double factor = (distance / radius);
if (factor <= innerSaturation) {
setColor(result, x, y, startColor);
} else {
double realDistanceNormalized = 1.0 - innerSaturation;
factor = (factor - innerSaturation) / realDistanceNormalized;
Color newColor = startColor.interpolate(endColor, factor);
setColor(result, x, y, newColor);
}
}
});
return result;
}
use of com.helospark.tactview.core.timeline.image.ClipImage in project tactview by helospark.
the class DrawnEllipseHighlightProceduralEffect method createProceduralFrame.
@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
ClipImage result = ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
double progress;
double endSeconds = endPositionProvider.getValueAt(relativePosition);
double actualSeconds = relativePosition.getSeconds().doubleValue();
if (endSeconds > actualSeconds) {
progress = actualSeconds / endSeconds;
} else {
progress = 1.0;
}
int brushSize = (int) (brushSizeProvider.getValueAt(relativePosition) * request.getScale());
if (brushSize < 1) {
brushSize = 1;
}
Point topLeft = topLeftProvider.getValueAt(relativePosition);
topLeft = new Point(topLeft.x * request.getExpectedWidth(), topLeft.y * request.getExpectedHeight());
Point bottomRight = bottomRightProvider.getValueAt(relativePosition);
bottomRight = new Point(bottomRight.x * request.getExpectedWidth(), bottomRight.y * request.getExpectedHeight());
int width = (int) Math.abs(bottomRight.x - topLeft.x);
int height = (int) Math.abs(bottomRight.y - topLeft.y);
int centerX = (int) (topLeft.x + width / 2);
int centerY = (int) (bottomRight.y - height / 2);
String brushFilePath = brushFileProvider.getValueOrDefault(relativePosition, "classpath:/brushes/Sponge-02.gbr");
Color color = colorProvider.getValueAt(relativePosition);
if (width > 0 && height > 0) {
DrawLineRequest drawLineRequest = DrawLineRequest.builder().withBrushFilePath(brushFilePath).withBrushSize(brushSize).withColor(color).withPixels(bresenhemPixelProvider.ellipsePixels(centerX, centerY, width, height)).withProgress(progress).withResult(result).build();
drawLineService.drawLine(drawLineRequest);
}
return result;
}
use of com.helospark.tactview.core.timeline.image.ClipImage in project tactview by helospark.
the class DrawnRectangleHighlightProceduralEffect method createProceduralFrame.
@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
ClipImage result = ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
double progress;
double endSeconds = endPositionProvider.getValueAt(relativePosition);
double actualSeconds = relativePosition.getSeconds().doubleValue();
if (endSeconds > actualSeconds) {
progress = actualSeconds / endSeconds;
} else {
progress = 1.0;
}
Rectangle rectangle = rectangleProvider.getValueAt(relativePosition);
double overshoot = overshootProvider.getValueAt(relativePosition);
double totalLength = rectangle.getLength() * (1.0 + overshoot * 2 * 4);
double lengthToDraw = progress * totalLength;
int brushSize = (int) (brushSizeProvider.getValueAt(relativePosition) * request.getScale());
if (brushSize < 1) {
brushSize = 1;
}
String brushFilePath = brushFileProvider.getValueOrDefault(relativePosition, "classpath:/brushes/Sponge-02.gbr");
Point brushHalfSize = new Point((double) brushSize / request.getExpectedWidth() / 2.0, (double) brushSize / request.getExpectedHeight() / 2.0);
Color color = colorProvider.getValueAt(relativePosition);
for (int i = 0; i < 4 && lengthToDraw > 0.0; ++i) {
// 0->1, 1->2, 2->3, 3->0
Point start = rectangle.points.get(i).subtract(brushHalfSize);
Point end = rectangle.points.get((i + 1) % 4).subtract(brushHalfSize);
Point overshootOffsetVector = end.subtract(start).normalize().scalarMultiply(overshoot);
start = start.subtract(overshootOffsetVector);
end = end.add(overshootOffsetVector);
double distance = start.distanceFrom(end);
double lineProgress = lengthToDraw > distance ? 1.0 : lengthToDraw / distance;
Point startInPixels = start.multiply(request.getExpectedWidth(), request.getExpectedHeight());
Point endInPixels = end.multiply(request.getExpectedWidth(), request.getExpectedHeight());
DrawLineRequest drawLineRequest = DrawLineRequest.builder().withBrushFilePath(brushFilePath).withBrushSize(brushSize).withColor(color).withPixels(bresenhemPixelProvider.linePixels(startInPixels, endInPixels)).withProgress(lineProgress).withResult(result).build();
drawLineService.drawLine(drawLineRequest);
lengthToDraw -= distance;
}
return result;
}
use of com.helospark.tactview.core.timeline.image.ClipImage in project tactview by helospark.
the class HighlightPenProceduralEffect method createProceduralFrame.
@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
ClipImage result = ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
double progress;
double endSeconds = endPositionProvider.getValueAt(relativePosition);
double actualSeconds = relativePosition.getSeconds().doubleValue();
if (endSeconds > actualSeconds) {
progress = actualSeconds / endSeconds;
} else {
progress = 1.0;
}
InterpolationLine line = lineProvider.getValueAt(relativePosition).multiply(request.getExpectedWidth(), request.getExpectedHeight());
int brushSize = (int) (brushSizeProvider.getValueAt(relativePosition) * request.getScale());
if (brushSize < 1) {
brushSize = 1;
}
String brushFilePath = brushFileProvider.getValueOrDefault(relativePosition, "classpath:/brushes/Sponge-02.gbr");
Color color = colorProvider.getValueAt(relativePosition);
DrawLineRequest drawLineRequest = DrawLineRequest.builder().withBrushFilePath(brushFilePath).withBrushSize(brushSize).withColor(color).withPixels(bresenhemPixelProvider.linePixels(line.start, line.end)).withProgress(progress).withResult(result).build();
drawLineService.drawLine(drawLineRequest);
return result;
}
use of com.helospark.tactview.core.timeline.image.ClipImage in project tactview by helospark.
the class GridProceduralClip method createProceduralFrame.
@Override
public ReadOnlyClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
ClipImage result = ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
Color color = colorProvider.getValueAt(relativePosition).multiplyComponents(255.0);
int width = (int) (lineWidthProvider.getValueAt(relativePosition) * request.getExpectedWidth());
int xDistance = (int) (xDistanceProvider.getValueAt(relativePosition) * request.getExpectedWidth());
int yDistance = (int) (yDistanceProvider.getValueAt(relativePosition) * request.getExpectedHeight());
if (width <= 0) {
width = 1;
}
if (xDistance <= 0) {
xDistance = 1;
}
if (yDistance <= 0) {
yDistance = 1;
}
int xOffset = (int) (xOffsetProvider.getValueAt(relativePosition) * request.getExpectedWidth()) % xDistance;
int yOffset = (int) (yOffsetProvider.getValueAt(relativePosition) * request.getExpectedHeight()) % yDistance;
int x = xOffset;
while (x <= result.getWidth()) {
drawSimpleVerticalLine(result, x, width, color);
x += xDistance;
}
int y = yOffset;
while (y <= result.getHeight()) {
drawSimpleHorizontalLine(result, y, width, color);
y += yDistance;
}
return result;
}
Aggregations