Matrix effect funzionante, scie fluide, visualizza immagine colorando le lettere pixel per pixel, parametri settabili, migliorati
This commit is contained in:
@@ -11,110 +11,199 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Colonna extends JPanel {
|
||||
public static final char[] MATRIX_CHARS = (
|
||||
"ヲァィゥェォャュョッ" +
|
||||
"アイウエオカキクケコ" +
|
||||
"サシスセソタチツテト" +
|
||||
"ナニヌネノハヒフヘホ" +
|
||||
"マミムメモヤユヨ" +
|
||||
"ラリルレロワン" +
|
||||
"01010101010101010101010101010"
|
||||
).toCharArray();
|
||||
|
||||
public static final char[] MATRIX_CHARS = ("ヲァィゥェォャュョッ"
|
||||
+ "アイウエオカキクケコ"
|
||||
+ "サシスセソタチツテト"
|
||||
+ "ナニヌネノハヒフヘホ"
|
||||
+ "マミムメモヤユヨ"
|
||||
+ "ラリルレロワン"
|
||||
+ "01010101010101010101010101010"
|
||||
+ "Luca Mustacchio").toCharArray();
|
||||
private final List<Lettera> lettere = new ArrayList<>();
|
||||
private final int width;
|
||||
private int nextY = 0; // ← posizione verticale corrente
|
||||
|
||||
private int offsetY = 0; // posizione iniziale
|
||||
private int stepY = 0; // distanza tra lettere
|
||||
|
||||
private final float dissolvenza;
|
||||
private int maxLetters=0;
|
||||
private int letteraAggiunte=0;
|
||||
private int height=0;
|
||||
private int velocita=5;
|
||||
private int timeset=2;
|
||||
private int maxLetters = 0;
|
||||
private int letteraAggiunte = 0;
|
||||
private int height = 0;
|
||||
private int velocita = 4;
|
||||
private int timeset = 4;
|
||||
private Point startPoint;
|
||||
private Point endPoint;
|
||||
private int grandezza_minima_lettera=15;
|
||||
private int grandezza_massima_lettera=25;
|
||||
|
||||
private float dissolve_max= 0.01f;
|
||||
private float dissolve_min=0.001f;
|
||||
|
||||
private int grandezza_minima_lettera = 15;
|
||||
private int grandezza_massima_lettera = 30;
|
||||
private Color C_lettera = Color.GREEN;
|
||||
private float dissolve_max = 0.01f;
|
||||
private float dissolve_min = 0.001f;
|
||||
|
||||
public Colonna(int pointX, int height) {
|
||||
//setOpaque(true); // importante per Matrix
|
||||
//this.setBackground(Color.red);
|
||||
setOpaque(false);
|
||||
this.dissolvenza=randomDissolve();
|
||||
this.width=randomWidth();
|
||||
this.height=height;
|
||||
|
||||
this.dissolvenza = randomDissolve();
|
||||
this.width = randomWidth();
|
||||
this.height = height;
|
||||
|
||||
this.maxLetters = height / this.width;
|
||||
// altezza proporzionata alla larghezza
|
||||
this.setBounds(pointX, 0, width, height);
|
||||
// numero massimo di lettere contenibili
|
||||
this.startPoint = new Point(pointX, 0);
|
||||
this.endPoint = new Point(pointX + width, height);
|
||||
this.endPoint = new Point(pointX + width, height);
|
||||
addRandomChar();
|
||||
}
|
||||
|
||||
public void addChar(char c) {
|
||||
//int size = 20; // oppure random
|
||||
Point p = new Point(0, nextY);
|
||||
/**
|
||||
*
|
||||
* @param pointX punto di partenza dello schermo per le sie
|
||||
* @param height altezza della visualizzazione delle scie
|
||||
* @param vel velocità di aggiornamento della colonna numero maggiore, meno
|
||||
* veloci, numero minore, piu veloce, se null impostato su 4
|
||||
* @param diss_l indice di dissolvenza delle lettere se nullo valore max =
|
||||
* 0.01f valore min = 0.001f
|
||||
* @param max_l numero di lettere da visualizzare nella colonna, spaz non
|
||||
* verrà considerato, il calcolo sarà automatico
|
||||
* @param spaz spaziatura verticale tra le lettere. se null verrà calcolato
|
||||
* in base alla h della colonna, altrimenti verranno calcolate quante
|
||||
* lettere ci staranno nella colonna
|
||||
* @param c_col colore della colonna, se null trasparente
|
||||
* @param c_let colore della lettera, se null verde
|
||||
*/
|
||||
public Colonna(int pointX, int height, Integer vel, Min_Max diss_l, Integer max_l, Integer spaz, Color c_col, Color c_let) {
|
||||
|
||||
Lettera l = new Lettera(c, this.width, p);
|
||||
lettere.add(l);
|
||||
this.width = randomWidth();
|
||||
this.height = height;
|
||||
|
||||
nextY += this.width; // ← distanza coerente con la dimensione
|
||||
letteraAggiunte++;
|
||||
repaint();
|
||||
if (vel != null) {
|
||||
this.velocita = vel;
|
||||
}
|
||||
if (diss_l != null) {
|
||||
dissolve_max = diss_l.get_maxf();
|
||||
dissolve_min = diss_l.get_minf();
|
||||
|
||||
}
|
||||
if (max_l != null) {
|
||||
this.maxLetters = max_l;
|
||||
if (maxLetters > 1) {
|
||||
offsetY = 0;
|
||||
stepY = (height - width) / (maxLetters - 1);
|
||||
|
||||
} else {
|
||||
offsetY = 0;
|
||||
stepY = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (spaz == null) {
|
||||
this.maxLetters = height / width;
|
||||
offsetY = 0;
|
||||
stepY = width;
|
||||
|
||||
} else {
|
||||
this.maxLetters = (int) Math.floor((height - spaz) / (double) (width + spaz));
|
||||
offsetY = spaz;
|
||||
stepY = width + spaz;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (c_col == null) {
|
||||
setOpaque(false);
|
||||
|
||||
} else {
|
||||
setOpaque(true); // importante per Matrix
|
||||
this.setBackground(c_col);
|
||||
}
|
||||
this.dissolvenza = randomDissolve();
|
||||
|
||||
if (c_let != null) {
|
||||
C_lettera = c_let;
|
||||
}
|
||||
// altezza proporzionata alla larghezza
|
||||
this.setBounds(pointX, 0, width, height);
|
||||
// numero massimo di lettere contenibili
|
||||
this.startPoint = new Point(pointX, 0);
|
||||
this.endPoint = new Point(pointX + width, height);
|
||||
addRandomChar();
|
||||
}
|
||||
private int randomWidth(){
|
||||
|
||||
public void addChar(char c) {
|
||||
int y = offsetY + letteraAggiunte * stepY;
|
||||
Point p = new Point(0, y);
|
||||
|
||||
Lettera l = new Lettera(c, this.width, p, C_lettera);
|
||||
lettere.add(l);
|
||||
|
||||
letteraAggiunte++;
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
private int randomWidth() {
|
||||
return (int) (grandezza_minima_lettera + Math.random() * (grandezza_massima_lettera - grandezza_minima_lettera));
|
||||
}
|
||||
|
||||
private float randomDissolve() {
|
||||
|
||||
return dissolve_min +
|
||||
(float) Math.random() * (dissolve_max - dissolve_min);
|
||||
return dissolve_min
|
||||
+ (float) Math.random() * (dissolve_max - dissolve_min);
|
||||
}
|
||||
public void addRandomChar(){
|
||||
|
||||
public void addRandomChar() {
|
||||
char c = MATRIX_CHARS[ThreadLocalRandom.current().nextInt(MATRIX_CHARS.length)];
|
||||
addChar(c);
|
||||
}
|
||||
public int count(){
|
||||
|
||||
public int count() {
|
||||
return lettere.size();
|
||||
}
|
||||
public boolean isDead(){
|
||||
|
||||
public boolean isDead() {
|
||||
return lettere.isEmpty();
|
||||
}
|
||||
|
||||
public Rectangle getBoundsRect() {
|
||||
return new Rectangle(startPoint.x, startPoint.y, width, height);
|
||||
}
|
||||
|
||||
public void setHeight(int h){
|
||||
this.height=h;
|
||||
this.maxLetters = height / this.width;
|
||||
public void setHeight(int h) {
|
||||
this.height = h;
|
||||
if (maxLetters == 0) {
|
||||
this.maxLetters = height / this.width;
|
||||
}
|
||||
}
|
||||
public List <Lettera> getLettere(){
|
||||
|
||||
public List<Lettera> getLettere() {
|
||||
return lettere;
|
||||
}
|
||||
public Lettera getLettera(int p){
|
||||
|
||||
public Lettera getLettera(int p) {
|
||||
return lettere.get(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g); // FONDAMENTALE
|
||||
for (int i = lettere.size() - 1; i >= 0; i--) {
|
||||
Lettera l = lettere.get(i);
|
||||
if (l.isDead()){
|
||||
if (l.isDead()) {
|
||||
lettere.remove(i);
|
||||
}else{
|
||||
} else {
|
||||
l.dissolve(dissolvenza);
|
||||
l.draw((Graphics2D) g);
|
||||
}
|
||||
}
|
||||
if (letteraAggiunte<maxLetters){
|
||||
if (letteraAggiunte < maxLetters) {
|
||||
timeset--;
|
||||
if (timeset==0){
|
||||
if (timeset == 0) {
|
||||
addRandomChar();
|
||||
// addChar((char) this.maxLetters);
|
||||
timeset=velocita;
|
||||
timeset = velocita;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user