Skip to content

chompa111/saturnGL

Repository files navigation

baner7

SaturnGL

Graphic Library to build animations with Java Wiki here!

Saturn suports SVG

drawing

Saturn suports Latex

latex

Import Saturn as Maven/Gradle dependency or Jar

Built with Java 11

You can choose one of these options:

JAR - dowload the .jar (fat jar)

Gradle

repositories {
    maven { url 'https://jitpack.io' }
    maven { url "https://www.dcm4che.org/maven2/"}
}
dependencies {
    implementation 'com.github.chompa111:saturnGL:1.0.13'
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
    <repository>
        <id>dcm4che.org</id>
        <url>https://www.dcm4che.org/maven2/</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.chompa111</groupId>
    <artifactId>saturnGL</artifactId>
    <version>1.0.13</version>
</dependency>

First Steps 🪐

1) Create a class that extends Presentation

to create your first animation on Saturn, you need to:

  • create a class that extends Presentation
  • create a new instace of its class
  • on the main function: call the method build()
public class Example extends Presentation {
    @Override
    public void setup(PresentationConfig presentationConfig) {
        
    }

    @Override
    public void buildPresentation() {

    }

    public static void main(String[] args) {
        new Example().build();
    }
}

✔️ the method buildPresentation() will contain all your instructions to build the animation, and the method setup() those to config preferences about de video codec, fps and so on

2) First Animation

Our first animation will be a moving circle.

  • to create a circle:
var center = new Point(100,500);
var radius = new DoubleHolder(100);
var color = new Color(255,0,255); // this is a awt color
var circle = new Circle(center,radius,color); 
  • add the circle to your presentation:
add(circle);
  • move your circle:
circle.move(200,0).execute();// first arg is the amount on X, the second on Y

drawing

  • and change its color:
circle.move(200,0).execute();
circle.changeColor(new Color(255,0,0)).execute(); // red color

drawing

What if we wanted to move and change color at the same time? It's a good moment to talk about Tasks on SaturnGL. Task is some action that occurs in a given time, by the way move() and changeColor() are examples of tasks that you already know. On Saturn you can compose two or more tasks on a a single complex task. In our example we need to compose the task move and changeColor to another task that executes it in parallel way. We could do that as following:

var taskMove = circle.move(400,0);
var taskChangeColor = circle.changeColor(new Color(255,0,0));
var parallelTask = taskMove.parallel(taskChangeColor);

// or simplifying
var parallelTask=circle.move(400,0).parallel(circle.changeColor(new Color(255,0,0));

to execute the task job you need to call the execute() method.

circle.move(400,0).parallel(circle.changeColor(new Color(255,0,0)).execute();

Finally!

drawing

3) Generating the .mov video

Simply by executing the main method with the circle example, the library will generate a live preview on your screen, and in the end a .mov file with your animation inside the /video folder on the root of project.

you can set the fps of the generated video on the setup() method as following:

@Override
public void setup(PresentationConfig presentationConfig) {
    presentationconfig.setFps(75);        
}

presentation config always has a default value for every config, in case 60 fps is the default value

you can disable the video generation to increase your preview fps while testing your code.

@Override
public void setup(PresentationConfig presentationConfig) {
    presentationconfig.setFps(75);
    presentationconfig.disableCodec(true);
}