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;
}
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;
}
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;
}
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());
}
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;
}
Aggregations