Skip to content

Commit

Permalink
RT animation
Browse files Browse the repository at this point in the history
  • Loading branch information
chompa111 committed May 28, 2023
1 parent f889508 commit 61ceb9d
Show file tree
Hide file tree
Showing 23 changed files with 582 additions and 93 deletions.
14 changes: 14 additions & 0 deletions src/main/java/graphical/basics/behaviors/AlwaysOnTop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package graphical.basics.behaviors;

import graphical.basics.gobject.struct.Gobject;
import graphical.basics.presentation.Presentation;

public class AlwaysOnTop {

public static Runnable onTop(Gobject gobject) {
return () ->{
Presentation.staticReference.remove(gobject);
Presentation.staticReference.add(gobject);
};
}
}
56 changes: 56 additions & 0 deletions src/main/java/graphical/basics/behaviors/FollowBehavior.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package graphical.basics.behaviors;

import graphical.basics.gobject.struct.Gobject;
import graphical.basics.location.Location;

public class FollowBehavior {
public static Runnable follow(Gobject followedGobject, Gobject followerGobject) {
return () -> followerGobject.setPositionTo(followedGobject.getMidPoint());
}

public static Runnable followWithDelay(Gobject followedGobject, Gobject followerGobject, double delay) {
return () -> {
var m1 = followerGobject.getMidPoint();
var m2 = followedGobject.getMidPoint();

followerGobject.changeSetPosition((m2.getX() - m1.getX()) * delay, (m2.getY() - m1.getY()) * delay);
};
}


public static Runnable followWithDelay(Gobject followedGobject, Gobject followerGobject) {
return followWithDelay(followedGobject, followerGobject, 0.1);
}

public static Runnable asSubtitle(Gobject followedGobject, Gobject followerGobject, double margin) {
return () -> {
var fd = followedGobject.getBorders();
var fr = followerGobject.getBorders();
var fdh2 = fd.getheight() / 2;
var frh2 = fr.getheight() / 2;
var fdmid = fd.midPoint();

var desirredPoint = Location.at(fd.midPoint().getX(), fd.midPoint().getY() + fdh2 + frh2 + margin);

followerGobject.setPositionTo(desirredPoint);
};
}

public static Runnable asSubtitleWithDelay(Gobject followedGobject, Gobject followerGobject, double margin, double delay) {
asSubtitle(followedGobject, followerGobject, margin).run();
return () -> {
var fd = followedGobject.getBorders();
var fr = followerGobject.getBorders();
var fdh2 = fd.getheight() / 2;
var frh2 = fr.getheight() / 2;
var fdmid = fd.midPoint();
var frmid = fr.midPoint();

var desirredPoint = Location.at(fdmid.getX(), fdmid.getY() + fdh2 + frh2 + margin);

followerGobject.changeSetPosition((desirredPoint.getX() - frmid.getX()) * delay, (desirredPoint.getY() - frmid.getY()) * delay);
};
}


}
9 changes: 9 additions & 0 deletions src/main/java/graphical/basics/behaviors/RunnableUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package graphical.basics.behaviors;

import java.util.function.Consumer;

public class RunnableUtils {
public static <T> Runnable wrap(T metadata, Consumer<T> consumer) {
return () -> consumer.accept(metadata);
}
}
46 changes: 22 additions & 24 deletions src/main/java/graphical/basics/gobject/CodeBlock.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package graphical.basics.gobject;

import graphical.basics.gobject.latex.Rect;
import graphical.basics.gobject.struct.Gobject;
import graphical.basics.location.Location;
import graphical.basics.presentation.Animation;
import graphical.basics.presentation.AnimationStaticReference;
import graphical.basics.presentation.Presentation;
import graphical.basics.task.ContextSetupTask;
import graphical.basics.task.SupplierTask;
import graphical.basics.task.Task;
import graphical.basics.task.WaitTask;

import java.awt.*;
import java.util.List;

public class CodeBlock extends Group {

Expand Down Expand Up @@ -98,11 +97,11 @@ public Task newLineAnimated(int index, String line) {
textGutter.newLine("" + lineCounter);
var newNumber = textGutter.getLine(textGutter.lines.size() - 1);
return text.newLineAnimated(index, line)
.parallel(background.getLowerRightPoint().move(0, textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(Animation.fadeInGrow(newNumber, Presentation.staticReference.seconds(1)))
.parallel(background.getLowerRightPoint().move(0, textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(Animation.fadeInGrow(newNumber, AnimationStaticReference.staticReference.seconds(1)))
.afterConclusion(() -> {
lineCounter++;
javaHilighter.colorize(text);
Expand Down Expand Up @@ -134,10 +133,10 @@ public void removeLines(int i,int j) {

public Task removeLinesAnimated(int i, int j) {
return text.removeLinesAnimated(i,j)
.parallel(background.getLowerRightPoint().move(0, -(j-i+1)*textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, -(j-i+1)*textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, -(j-i+1)*textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, -(j-i+1)*textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(background.getLowerRightPoint().move(0, -(j-i+1)*textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, -(j-i+1)*textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, -(j-i+1)*textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, -(j-i+1)*textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(Animation.fadeoutGrow(textGutter.getLinesAsGroup((lineCounter-2)-(j-i),lineCounter-2), Presentation.staticReference.seconds(0.75)))
.afterConclusion(()->{
textGutter.removeLines((lineCounter-2)-(j-i),lineCounter-2);
Expand All @@ -148,11 +147,11 @@ public Task removeLinesAnimated(int i, int j) {

public Task removeLineAnimated(int index) {
return text.removeLineAnimated(index)
.parallel(background.getLowerRightPoint().move(0, -textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, -textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, -textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, -textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(Animation.fadeOut(textGutter.getLine(lineCounter-2), Presentation.staticReference.seconds(1)))
.parallel(background.getLowerRightPoint().move(0, -textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, -textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, -textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, -textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(Animation.fadeOut(textGutter.getLine(lineCounter-2), AnimationStaticReference.staticReference.seconds(1)))
.afterConclusion(()->{
textGutter.removeLine(lineCounter - 2);
lineCounter--;
Expand All @@ -162,18 +161,17 @@ public Task removeLineAnimated(int index) {

public Task newLinesAnimated(int index, String... newLines) {
var amount = newLines.length;

return text.newLinesAnimated(index, newLines)
.parallel(background.getLowerRightPoint().move(0, amount * textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, amount * textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, amount * textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, amount * textSize * 1.15, Presentation.staticReference.seconds(1)))
.parallel(background.getLowerRightPoint().move(0, amount * textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(backgroundShadow.getLowerRightPoint().move(0, amount * textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutter.getLowerRightPoint().move(0, amount * textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(gutterLine.getP2().move(0, amount * textSize * 1.15, AnimationStaticReference.staticReference.seconds(1)))
.parallel(new WaitTask(Presentation.staticReference.seconds(0.5) + 1)
.andThen(() -> {
for (int i = 0; i < newLines.length; i++) {
textGutter.newLine("" + (lineCounter + i));
}
return textGutter.getLinesAsGroup(lineCounter - 1, lineCounter - 2 + amount).onChildren(x -> Animation.fadeInGrow(x, Presentation.staticReference.seconds(1)));
return textGutter.getLinesAsGroup(lineCounter - 1, lineCounter - 2 + amount).onChildren(x -> Animation.fadeInGrow(x, AnimationStaticReference.staticReference.seconds(1)));
}))
.afterConclusion(() -> {
lineCounter += amount;
Expand Down Expand Up @@ -202,7 +200,7 @@ public Task debuggNextLineAnimated(int frames) {
}

public Task setDebuglineAnimated(int line, int frames) {
return new ContextSetupTask(() -> {
return new SupplierTask(() -> {
var delta = line - debuggerCurrentLine;
debuggerCurrentLine = line;
return debbugLine.move(0, delta * textSize * EXTRA_SPACEMENT, frames);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/graphical/basics/gobject/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public void addAll(List<Gobject> gobjectList) {
this.gobjects.addAll(gobjectList);
}

public void deleteGobjects() {
this.gobjects = new ArrayList<>();
}


public Group subGroup(Integer... index) {
var list = new ArrayList<Gobject>();
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/graphical/basics/gobject/StringGobject.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import graphical.basics.gobject.struct.Gobject;
import graphical.basics.gobject.struct.ShapeGobject2;
import graphical.basics.location.Location;
import graphical.basics.task.ContextSetupTask;
import graphical.basics.task.SupplierTask;
import graphical.basics.task.SequenceTask;
import graphical.basics.task.Task;
import graphical.basics.task.WaitTask;
Expand Down Expand Up @@ -64,6 +64,7 @@ public Group getFirstSubstring(String s) {

}


public Group getAllMatchesGroup(String s) {
var group = new Group();
int index = string.indexOf(s);
Expand Down Expand Up @@ -123,7 +124,7 @@ public Task typeEffect() {
for (int i = 0; i < colorHolders.size(); i++) {

int finalI = i;
taskList.add(new ContextSetupTask(() -> {
taskList.add(new SupplierTask(() -> {
colorHolders.get(finalI).setColor(beforeColors.get(finalI));
return new WaitTask((int) (Math.random() * 2) + 1);
}));
Expand All @@ -137,7 +138,7 @@ public Task typeEffect() {
public Task erase(int amount) {
var taskList = new ArrayList<Task>();
for (int i = 0; i < amount; i++) {
taskList.add(new ContextSetupTask(() -> {
taskList.add(new SupplierTask(() -> {
var size = getGobjects().size();
if (size >= 1) {
remove(size - 1);
Expand All @@ -156,6 +157,15 @@ public Location getRef() {
}


public void set(String s){
this.string = s;
this.spacemapping = extractSpaceMapping(s);
deleteGobjects();
addAll(generateText(Fonts.JETBRAINS_MONO.deriveFont(30f), s, ref, Color.white));
}



@Override
public List<Location> getReferenceLocations() {
var locations = super.getReferenceLocations();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/graphical/basics/gobject/SupplierText.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public SupplierText(Supplier<String> supplier, Location location, Color color) {
this.color = new ColorHolder(color);
this.supplier = supplier;

if (isLatex) {
this.setGobjects(generateExp(supplier.get(), location, this.color.getColor()));
} else {
this.setGobjects(TextGobject.generateText(f, supplier.get(), location, this.color.getColor()));
}
}

public SupplierText(Font font, Supplier<String> supplier, Location location, Color color) {
Expand All @@ -46,11 +51,13 @@ public void paint(Graphics g) {
super.paint(g);
}


@Override
public List<ColorHolder> getColors() {
return List.of(color);
}


@Override
public List<Location> getReferenceLocations() {
return List.of(location);
}
}
22 changes: 11 additions & 11 deletions src/main/java/graphical/basics/gobject/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ public class Video extends Gobject {
int heith;

public Video(Location location, String path) {
this.location=location;
this.location = location;
decodeAndCaptureFrames = new DecodeAndCaptureFrames(path);
for(int i=0;i<40;i++){
decodeAndCaptureFrames.processFrame();

}
var img=decodeAndCaptureFrames.getFrame();
width=img.getWidth();
heith=img.getHeight();
while (decodeAndCaptureFrames.getFrame() == null) {
decodeAndCaptureFrames.processFrame();
}
var img = decodeAndCaptureFrames.getFrame();
width = img.getWidth();
heith = img.getHeight();
}

@Override
public void paint(Graphics g) {
var img = decodeAndCaptureFrames.getFrame();
g.drawImage(img, (int) location.getX()-(width/2), (int) location.getY()-(heith/2), null);
g.drawImage(img, (int) location.getX() - (width / 2), (int) location.getY() - (heith / 2), null);
}

@Override
public LocationPair getBorders() {
return new LocationPair(Location.at(location.getX()-(width*scale.getValue()),location.getY()-(heith*scale.getValue())),Location.at(location.getX()+(width*scale.getValue()),location.getY()+(heith*scale.getValue())));
return new LocationPair(Location.at(location.getX() - (width * scale.getValue()), location.getY() - (heith * scale.getValue())), Location.at(location.getX() + (width * scale.getValue()), location.getY() + (heith * scale.getValue())));
}

@Override
Expand All @@ -54,8 +54,8 @@ public List<Location> getReferenceLocations() {
return Arrays.asList(location);
}

public Task play(int frames){
return new SingleStepTask(()->{
public Task play(int frames) {
return new SingleStepTask(() -> {
decodeAndCaptureFrames.processFrame();
}).repeat(frames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public ColorHolder getFillColorHolder() {
return fillColorHolder;
}

public Color getFillColor() {
return fillColorHolder.getColor();
}
public Color getStrokeColor() {
return strokeColorHolder.getColor();
}

public void setFillColorHolder(ColorHolder fillColorHolder) {
this.fillColorHolder = fillColorHolder;
}
Expand Down
Loading

0 comments on commit 61ceb9d

Please sign in to comment.