Search in sources :

Example 1 with Point

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point 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 Point

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point 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 Point

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point 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 Point

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point in project tactview by helospark.

the class DrawnRectangleHighlightProceduralEffect method initializeValueProvider.

@Override
protected void initializeValueProvider() {
    super.initializeValueProvider();
    rectangleProvider = RectangleProvider.createDefaultFullImageWithNormalizedCenterAndSize(new Point(0.5, 0.5), 0.1, 0.1);
    colorProvider = ColorProvider.fromDefaultValue(0, 0, 0);
    brushSizeProvider = new IntegerProvider(1, 200, new MultiKeyframeBasedDoubleInterpolator(70.0));
    endPositionProvider = new DoubleProvider(new MultiKeyframeBasedDoubleInterpolator(2.0));
    overshootProvider = new DoubleProvider(0.0, 0.2, new MultiKeyframeBasedDoubleInterpolator(0.02));
    brushFileProvider = new FileProvider("*.gbr", new StepStringInterpolator());
}
Also used : DoubleProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.DoubleProvider) IntegerProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.IntegerProvider) FileProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.FileProvider) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) MultiKeyframeBasedDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.MultiKeyframeBasedDoubleInterpolator) StepStringInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.StepStringInterpolator)

Example 5 with Point

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point in project tactview by helospark.

the class ParticleSystemProceduralClip method simulateParticles.

private List<Particle> simulateParticles(TimelinePosition requestedPosition, List<Particle> particles, BigDecimal startSecond) {
    BigDecimal timeSinceLastCache = BigDecimal.ZERO;
    BigDecimal roundedEndPosition = requestedPosition.getSeconds().setScale(2, RoundingMode.CEILING);
    BigDecimal roundedStartPosition = startSecond.setScale(2, RoundingMode.CEILING).add(SIMULATION_TIME);
    while (roundedStartPosition.compareTo(roundedEndPosition) < 0) {
        TimelinePosition currentSimlutatedTimelinePosition = new TimelinePosition(roundedStartPosition);
        Random random = repeatableRandom.createRandomForPosition(roundedStartPosition);
        double gravity = gravityProvider.getValueAt(currentSimlutatedTimelinePosition);
        for (Particle particle : particles) {
            particle.x += particle.xVel;
            particle.y += particle.yVel;
            particle.yVel += gravity;
        }
        int numberOfParticlesToCreate = (int) numberOfParticlesCreatedInStep.getValueAt(currentSimlutatedTimelinePosition).doubleValue();
        Point center = emitterCenterProvider.getValueAt(currentSimlutatedTimelinePosition);
        Point startDirection = startDirectionProvider.getValueAt(currentSimlutatedTimelinePosition);
        double randomXSpeed = startDirectionXRandomSpeedProvider.getValueAt(currentSimlutatedTimelinePosition);
        double randomYSpeed = startDirectionYRandomSpeedProvider.getValueAt(currentSimlutatedTimelinePosition);
        double emitterRandomization = emitterRandomizationProvider.getValueAt(currentSimlutatedTimelinePosition);
        DoubleRange lifeRange = ageRangeProvider.getValueAt(currentSimlutatedTimelinePosition);
        for (int i = 0; i < numberOfParticlesToCreate; ++i) {
            Particle particle = new Particle();
            particle.x = center.x + ((random.nextDouble() * 2.0 - 1.0) * emitterRandomization);
            particle.y = center.y + ((random.nextDouble() * 2.0 - 1.0) * emitterRandomization);
            particle.xVel = startDirection.x + (random.nextDouble() * 2.0 - 1.0) * randomXSpeed;
            particle.yVel = startDirection.y + (random.nextDouble() * 2.0 - 1.0) * randomYSpeed;
            particle.maxAge = lifeRange.lowEnd + random.nextDouble() * (lifeRange.highEnd - lifeRange.lowEnd);
            particle.bornTime = roundedStartPosition.doubleValue();
            particles.add(particle);
        }
        double currentSecondDouble = roundedStartPosition.doubleValue();
        particles.removeIf(particle -> particle.bornTime + particle.maxAge <= currentSecondDouble);
        timeSinceLastCache.add(SIMULATION_TIME);
        if (timeSinceLastCache.compareTo(CACHE_TIME) > 0) {
            timeSinceLastCache = timeSinceLastCache.subtract(CACHE_TIME);
            particlesCache.put(roundedStartPosition, cloneParticles(particles));
        }
        roundedStartPosition = roundedStartPosition.add(SIMULATION_TIME);
    }
    return particles;
}
Also used : DoubleRange(com.helospark.tactview.core.timeline.effect.interpolation.pojo.DoubleRange) Random(java.util.Random) RepeatableRandom(com.helospark.tactview.core.util.RepeatableRandom) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BigDecimal(java.math.BigDecimal) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Aggregations

Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)79 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)23 Color (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color)19 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)15 InterpolationLine (com.helospark.tactview.core.timeline.effect.interpolation.pojo.InterpolationLine)11 ArrayList (java.util.ArrayList)8 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)7 Polygon (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Polygon)6 CubicBezierPoint (com.helospark.tactview.core.util.bezier.CubicBezierPoint)6 DrawLineRequest (com.helospark.tactview.core.timeline.proceduralclip.lines.impl.DrawLineRequest)5 BezierDoubleInterpolator (com.helospark.tactview.core.timeline.effect.interpolation.interpolator.bezier.BezierDoubleInterpolator)4 GraphicsContext (javafx.scene.canvas.GraphicsContext)4 Vector2D (org.apache.commons.math3.geometry.euclidean.twod.Vector2D)4 ValueProviderDescriptor (com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor)3 MultiKeyframeBasedDoubleInterpolator (com.helospark.tactview.core.timeline.effect.interpolation.interpolator.MultiKeyframeBasedDoubleInterpolator)3 StepStringInterpolator (com.helospark.tactview.core.timeline.effect.interpolation.interpolator.StepStringInterpolator)3 DoubleProvider (com.helospark.tactview.core.timeline.effect.interpolation.provider.DoubleProvider)3 FileProvider (com.helospark.tactview.core.timeline.effect.interpolation.provider.FileProvider)3 IntegerProvider (com.helospark.tactview.core.timeline.effect.interpolation.provider.IntegerProvider)3 LayerMaskBetweenTwoImageApplyRequest (com.helospark.tactview.core.timeline.effect.layermask.LayerMaskBetweenTwoImageApplyRequest)3