Repositories on GitHub are now for issues only. I've set up my own installation of GitLab and moved all my repositories over to Git.Griefed.de. Make sure to check there first for the latest code before opening an issue on GitHub.
For questions, you can always join my Discord server and talk to me there.
This is a Larson Scanner inspired by the Cylons from Battlestart Galactica and Kitt from Knight Rider. It's basically just a red light which scrolls from left to right to left, with a nice fade-out effect along with it.
This Larson Scanner lets you customize just about everything though! To get an idea about what's possible with this Larson Scanner, make sure to take a look at the examples below!
$VERSION
is the version of LarsonScanner you want to use in your project. The most recent version as of me writing this is 1.0.3
, however, for newer versions, make sure to check out the releases-page. More information can be found at Sonatype Maven
LarsonScanner was written using Java 8.
implementation 'de.griefed:larsonscanner:$VERSION'
<dependency>
<groupId>de.griefed</groupId>
<artifactId>larsonscanner</artifactId>
<version>$VERSION</version>
</dependency>
The quickest way is to create a new instance of LarsonScanner with the default values and just add it the the element you want to display it in.
LarsonScanner larsonScanner = new LarsonScanner();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
larsonScanner.setPreferredSize(new Dimension(512, 128));
frame.setPreferredSize(new Dimension(512, 128));
frame.setSize(new Dimension(512, 128));
frame.add(larsonScanner);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
larsonScanner.play();
LarsonScanner comes as a JPanel
, so you can immediately add it to your Java Swing GUI.
The GIF shown just above the Implementation-chapter shows the default settings to which you can compare all the following examples to.
You can set the alpha value for each element in the eye separately, allowing you to create some neat effects!
Be aware that these alpha values are only used when you use gradients! Alpha values are reset / automatically set / calculated when you change the number of elements in your configuration. So, if you plan on using custom alpha values and a custom amount of elements, make sure to update your alphas after changing the number of elements!
Every n
milliseconds the position of the eye gets updated and the eye redrawn. Smaller values therefor
increase the speed at wich the eye scrolls across the screen, whilst bigger values decrease it.
The divider determines the amount with which to increment or decrement the position of the eye each time the timer fires. Meaning: Smaller values increase the speed of the eye whilst bigger values decrease it.
The number of elements in the eye of the Larson Scanner. Pretty self-explanatory.
Fractions for the distribution of colours along the gradients of each oval-shaped element.
The gap between rectangular elements is n %
of the width of one element. Meaning:
A smaller divider results in smaller gaps, whilst a bigger divider results in larger gaps.
The total width of the available area is divided by this value, and the resulting value is the total width of the eye in which all elements will be drawn. The smaller the value, the bigger the eye and the other way around.
If the aspect ratio is being forced, each element will be drawn with a 1:1 aspect ratio, turning ovals into circles and rectangles into squares. The aspect ratio is being enforced by de-/increasing the height of the eye in the scanner to the width of one element, resulting in a nice and sexy 1:1 ratio.
If you plan on using different scanner and eye background colours, you should make use of this setting, otherwise the eye background colour will also prevail.
You can choose between a total of two different animation styles, Cylon-eye and Kitt-eye. If you plan on using the Kitt-eye animation, say goodbye to the alpha-setting, as it will not have any affect on the eye whatsoever when using the Kitt-style animation.
Whether to draw the eye using gradients. If gradients are not used, then every element in the eye will be drawn using a solid colour.
Whether to use a divider to in-/decrement across the width of the Larson Scanner. If the divider is being used, then the position of the eye will be updated with the result of the width of the Scanner divided by the divider.
Set the colour for each element in the eye, from left to right. If you plan on using this, make sure to check the number of elements in your eye beforehand! You must provide one colour per element.
255,0,0 - 0,255,0 - 0,0,255 - 255,255,0 - 0,255,255 (default 255,0,0 - 255,0,0 - 255,0,0 - 255,0,0 - 255,0,0)
The background colour of the LarsonScanner JPanel in which the eye resides in. If you plan on using this, then you are advised to use the aspect ratio enforcement, because otherwise the available area will be filled with the background colour of the eye.
The background colour of the eye in the LarsonScanner.
Changing the quality settings is only really relevant when you plan on making the LarsonScanner quite large. For smaller scanners, you can leave these on low (default) and nobody will notice.
If you want to experiment with this Larson Scanner, or find the perfect configuration for yourself, there's a class in the misc-folder in this repository, call Playground.java
. It creates
a GUI for you which lets you play around with all the different settings, so you can see whether this is something for you, or so you can tweak some stuff around to find the perfect
settings for you and your project. Enjoy!