use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine 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.effect.interpolation.pojo.InterpolationLine in project tactview by helospark.
the class RectangleProceduralClip method getXPosition.
@Override
public int getXPosition(GetPositionParameters parameterObject) {
if (extendedFrameProvider.getValueAt(parameterObject.getTimelinePosition())) {
return super.getXPosition(parameterObject);
} else {
InterpolationLine line = lineProvider.getValueAt(parameterObject.getTimelinePosition());
double xPos = Math.min(line.start.x, line.end.x);
return (int) (xPos * parameterObject.getWidth()) + super.getXPosition(parameterObject);
}
}
use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine in project tactview by helospark.
the class RectangleProceduralClip method createProceduralFrame.
@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
InterpolationLine line = lineProvider.getValueAt(relativePosition);
Point startPositionNormalized = line.start;
Point endPositionNormalized = line.end;
boolean isExtendedFrame = extendedFrameProvider.getValueAt(relativePosition);
if (isExtendedFrame) {
return extendedFrameDraw(request, relativePosition, startPositionNormalized, endPositionNormalized);
} else {
return nonExtendedFrameDraw(request, relativePosition, startPositionNormalized, endPositionNormalized);
}
}
use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine in project tactview by helospark.
the class LinearGradientProceduralClip method createProceduralFrame.
@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
InterpolationLine line = lineProvider.getValueAt(relativePosition);
Color startColor = startColorProvider.getValueAt(relativePosition);
Color endColor = endColorProvider.getValueAt(relativePosition);
LinearGradientRequest linearGradientRequest = LinearGradientRequest.builder().withStartColor(startColor).withEndColor(endColor).withNormalizedLine(line).withWidth(request.getExpectedWidth()).withHeight(request.getExpectedHeight()).build();
return linearGradientService.render(linearGradientRequest);
}
use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine in project tactview by helospark.
the class LinearGradientService method render.
public ClipImage render(LinearGradientRequest request) {
int width = request.getWidth();
int height = request.getHeight();
ClipImage result = ClipImage.fromSize(width, height);
InterpolationLine line = request.getNormalizedLine();
Color startColor = request.getStartColor();
Color endColor = request.getEndColor();
Point startPositionInPixels = line.start.multiply(result.getWidth(), result.getHeight());
Point endPositionInPixels = line.end.multiply(result.getWidth(), result.getHeight());
Vector2D start = new Vector2D(startPositionInPixels.x, startPositionInPixels.y);
Vector2D originalEnd = new Vector2D(endPositionInPixels.x, endPositionInPixels.y);
double lineDistance = start.distance(originalEnd);
Line perpendicularLine = getPerpendicularLine(start, originalEnd);
if (!request.getSaturateOnEndSide()) {
independentPixelOperation.executePixelTransformation(result.getWidth(), result.getHeight(), (x, y) -> {
// TODO: avoid new on every pixel
double pixelDistance = perpendicularLine.distance(new Vector2D(x, y));
if (pixelDistance > lineDistance) {
setColor(result, x, y, endColor);
} else {
double factor = pixelDistance / lineDistance;
Color newColor = startColor.interpolate(endColor, factor);
setColor(result, x, y, newColor);
}
});
} else {
independentPixelOperation.executePixelTransformation(result.getWidth(), result.getHeight(), (x, y) -> {
// TODO: avoid new on every pixel
double pixelOffset = perpendicularLine.getOffset(new Vector2D(x, y));
double pixelDistance = Math.abs(pixelOffset);
if (pixelOffset < 0.0) {
setColor(result, x, y, startColor);
} else if (Math.abs(pixelDistance) > lineDistance) {
setColor(result, x, y, endColor);
} else {
double factor = pixelDistance / lineDistance;
Color newColor = startColor.interpolate(endColor, factor);
setColor(result, x, y, newColor);
}
});
}
return result;
}
Aggregations