Search in sources :

Example 1 with Color

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color 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;
}
Also used : Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Example 2 with Color

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color 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;
}
Also used : ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) DrawLineRequest(com.helospark.tactview.core.timeline.proceduralclip.lines.impl.DrawLineRequest) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Example 3 with Color

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color 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;
}
Also used : ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) Rectangle(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle) DrawLineRequest(com.helospark.tactview.core.timeline.proceduralclip.lines.impl.DrawLineRequest) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Example 4 with Color

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color 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;
}
Also used : ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) DrawLineRequest(com.helospark.tactview.core.timeline.proceduralclip.lines.impl.DrawLineRequest) InterpolationLine(com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine)

Example 5 with Color

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color 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;
}
Also used : ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color)

Aggregations

Color (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color)58 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)30 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)21 Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)20 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)8 InterpolationLine (com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine)8 AudioVideoFragment (com.helospark.tactview.core.timeline.AudioVideoFragment)6 DrawLineRequest (com.helospark.tactview.core.timeline.proceduralclip.lines.impl.DrawLineRequest)6 Test (org.junit.jupiter.api.Test)6 Polygon (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Polygon)5 ArrayList (java.util.ArrayList)5 PictureAssertions.assertFrameOfColor (com.helospark.tactview.core.it.PictureAssertions.assertFrameOfColor)4 ValueProviderDescriptor (com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor)4 List (java.util.List)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 CloneRequestMetadata (com.helospark.tactview.core.clone.CloneRequestMetadata)3 LoadMetadata (com.helospark.tactview.core.save.LoadMetadata)3 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)3 RenderTypeHint (com.helospark.tactview.core.timeline.effect.interpolation.hint.RenderTypeHint)3 MultiKeyframeBasedDoubleInterpolator (com.helospark.tactview.core.timeline.effect.interpolation.interpolator.MultiKeyframeBasedDoubleInterpolator)3