2 Commits
V1.0 ... master

5 changed files with 444 additions and 112 deletions

View File

@@ -11,110 +11,201 @@ import java.util.concurrent.ThreadLocalRandom;
import javax.swing.JPanel;
public class Colonna extends JPanel {
public static final char[] MATRIX_CHARS = (
"ヲァィゥェォャュョッ" +
"アイウエオカキクケコ" +
"サシスセソタチツテト" +
"ナニヌネノハヒフヘホ" +
"マミムメモヤユヨ" +
"ラリルレロワン" +
"01010101010101010101010101010"
).toCharArray();
// "ヲァィゥェォャュョッ"+
// "アイウエオカキクケコ"+
// "サシスセソタチツテト"+
// "ナニヌネノハヒフヘホ"+
// "マミムメモヤユヨ"+
// "ラリルレロワン"+
"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;
}
}
}

View File

@@ -5,13 +5,13 @@ import java.awt.image.BufferedImage;
public class Lettera {
private final BufferedImage image;
private BufferedImage image;
private final Point position;
private float alpha = 1.0f;
public Lettera(char c, int size, Point position) {
public Lettera(char c, int size, Point position, Color c_l) {
this.position = position;
this.image = creaLetteraImage(c, size, Color.GREEN);
this.image = creaLetteraImage(c, size, c_l);
}
private BufferedImage creaLetteraImage(char c, int size, Color color) {
@@ -66,6 +66,9 @@ public class Lettera {
alpha -= amount;
if (alpha < 0f) alpha = 0f;
}
public float getAlpha(){
return this.alpha;
}
public boolean isDead() {
return alpha <= 0f;
@@ -87,4 +90,8 @@ public class Lettera {
public int getSize() {
return image.getWidth();
}
void setImage(BufferedImage finalImg) {
this.image=finalImg;
}
}

View File

@@ -4,6 +4,7 @@
*/
package matrix2;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -19,59 +20,63 @@ import javax.imageio.ImageIO;
* @author mstc
*/
public class Logo {
private BufferedImage image;
private Point startPoint = null;
private Point endPoint = null;
public Logo(String path, Point posizione, int percentuale) {
try {
BufferedImage original = ImageIO.read(new File(path));
if (original != null) {
// calcolo nuove dimensioni in base alla percentuale
int newWidth = original.getWidth() * percentuale / 100;
int newHeight = original.getHeight() * percentuale / 100;
// creo nuova immagine scalata
image = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
public Logo(String path, Point posizione, int percentuale) {
try {
BufferedImage original = ImageIO.read(new File(path));
if (original != null) {
// calcolo nuove dimensioni in base alla percentuale
int newWidth = original.getWidth() * percentuale / 100;
int newHeight = original.getHeight() * percentuale / 100;
// abilitare l’anti-aliasing e la qualità
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(original, 0, 0, newWidth, newHeight, null);
g2.dispose();
// creo nuova immagine scalata
image = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
// aggiorno punti start e end
startPoint = posizione;
endPoint = new Point(startPoint.x + newWidth, startPoint.y + newHeight);
} else {
startPoint = new Point(0,0);
endPoint = new Point(0,0);
// abilitare l’anti-aliasing e la qualità
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(original, 0, 0, newWidth, newHeight, null);
g2.dispose();
// aggiorno punti start e end
startPoint = posizione;
endPoint = new Point(startPoint.x + newWidth, startPoint.y + newHeight);
} else {
startPoint = new Point(0, 0);
endPoint = new Point(0, 0);
}
} catch (IOException ex) {
ex.printStackTrace();
startPoint = new Point(0, 0);
endPoint = new Point(0, 0);
}
} catch (IOException ex) {
ex.printStackTrace();
startPoint = new Point(0,0);
endPoint = new Point(0,0);
}
}
private Point localPoint(Point p){
return new Point(p.x-startPoint.x, p.y-startPoint.y);
private Point localPoint(Point p) {
return new Point(p.x - startPoint.x, p.y - startPoint.y);
}
public Color getPixelColor(Point globalPixel) {
if (image == null) return null;
if (image == null) {
return null;
}
if (globalPixel.x < startPoint.x || globalPixel.y < startPoint.y ||
globalPixel.x >= endPoint.x || globalPixel.y >= endPoint.y) {
if (globalPixel.x < startPoint.x || globalPixel.y < startPoint.y
|| globalPixel.x >= endPoint.x || globalPixel.y >= endPoint.y) {
return null;
}
int lx = globalPixel.x - startPoint.x;
int ly = globalPixel.y - startPoint.y;
if (lx < 0 || ly < 0 ||
lx >= image.getWidth() || ly >= image.getHeight()) {
if (lx < 0 || ly < 0
|| lx >= image.getWidth() || ly >= image.getHeight()) {
return null;
}
@@ -92,38 +97,231 @@ public Logo(String path, Point posizione, int percentuale) {
int rx2 = endPoint.x;
int ry2 = endPoint.y;
return lx1 < rx2 && lx2 > rx1 &&
ly1 < ry2 && ly2 > ry1;
return lx1 < rx2 && lx2 > rx1
&& ly1 < ry2 && ly2 > ry1;
}
public Rectangle getBoundsRect() {
return new Rectangle(
startPoint.x,
startPoint.y,
endPoint.x - startPoint.x,
endPoint.y - startPoint.y
startPoint.x,
startPoint.y,
endPoint.x - startPoint.x,
endPoint.y - startPoint.y
);
}
public void modificaLettera(Lettera l, Point colonnaPos){
BufferedImage img = l.getImage();
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < img.getWidth(); x++) {
int argb = img.getRGB(x, y);
Color lc = new Color(argb, true);
if (lc.getAlpha() == 0) continue;
public void modificaLettera(Lettera l, Point colonnaPos, int i) {
BufferedImage img_l = l.getImage();
switch (i) {
case 1:
for (int y = 0; y < img_l.getHeight(); y++) {
for (int x = 0; x < img_l.getWidth(); x++) {
int globalX = colonnaPos.x + l.getPosition().x + x;
int globalY = colonnaPos.y + l.getPosition().y + y;
int argb = img_l.getRGB(x, y);
Color lc = new Color(argb, true);
if (lc.getAlpha() == 0) {
continue;
}
Color logoColor = getPixelColor(new Point(globalX, globalY));
int globalX = colonnaPos.x + l.getPosition().x + x;
int globalY = colonnaPos.y + l.getPosition().y + y;
if (logoColor != null) {
img.setRGB(x, y, logoColor.getRGB());
Color logoColor = getPixelColor(new Point(globalX, globalY));
if (logoColor != null) {
img_l.setRGB(x, y, logoColor.getRGB());
}
}
}
break;
case 2:
int letterWidth = img_l.getWidth();
int letterHeight = img_l.getHeight();
// crea un'immagine finale dove mettere tutto
BufferedImage finalImg = new BufferedImage(letterWidth, letterHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = finalImg.createGraphics();
// --- Step 1: disegna cerchio sfumato ---
int radius = Math.max(letterWidth, letterHeight) - 10;
int centerX = letterWidth / 2;
int centerY = letterHeight / 2;
for (int y = 0; y < letterHeight; y++) {
for (int x = 0; x < letterWidth; x++) {
int dx = x - centerX;
int dy = y - centerY;
double dist = Math.sqrt(dx * dx + dy * dy);
if (dist > radius) {
continue;
}
int globalX = colonnaPos.x + l.getPosition().x + x;
int globalY = colonnaPos.y + l.getPosition().y + y;
Color bgColor = getPixelColor(new Point(globalX, globalY));
if (bgColor == null) {
continue;
}
float alphaFactor = 1.0f - (float) (dist / radius);
alphaFactor = Math.max(0, Math.min(1, alphaFactor));
int alpha = (int) (bgColor.getAlpha() * alphaFactor);
Color finalColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), alpha);
finalImg.setRGB(x, y, finalColor.getRGB());
}
}
// --- Step 2: disegna SOLO i pixel opachi della lettera ---
for (int y = 0; y < letterHeight; y++) {
for (int x = 0; x < letterWidth; x++) {
int argb = img_l.getRGB(x, y);
int alpha = (argb >>> 24) & 0xFF;
if (alpha == 0) {
continue;
}
Color lc = new Color(argb, true);
// usa l'alpha già dissolto dalla lettera
Color out = new Color(
lc.getRed(),
lc.getGreen(),
lc.getBlue(),
alpha
);
finalImg.setRGB(x, y, out.getRGB());
}
}
// --- Step 3: sostituisci l'immagine originale della lettera ---
l.setImage(finalImg);
break;
case 3:
int rgba= new Color(60, 60, 60, 255).getRGB();
for (int y = 0; y < img_l.getHeight(); y++) {
for (int x = 0; x < img_l.getWidth(); x++) {
int argb = img_l.getRGB(x, y);
Color lc = new Color(argb, true);
if (lc.getAlpha() == 0) {
continue;
}
int globalX = colonnaPos.x + l.getPosition().x + x;
int globalY = colonnaPos.y + l.getPosition().y + y;
Color logoColor = getPixelColor(new Point(globalX, globalY));
if (logoColor != null) {
img_l.setRGB(x, y, rgba);
}
}
}
break;
case 4:
for (int y = 0; y < img_l.getHeight(); y++) {
for (int x = 0; x < img_l.getWidth(); x++) {
int argb = img_l.getRGB(x, y);
Color lc = new Color(argb, true);
if (lc.getAlpha() == 0) {
continue; // identico a case 3
}
int globalX = colonnaPos.x + l.getPosition().x + x;
int globalY = colonnaPos.y + l.getPosition().y + y;
Color logoColor = getPixelColor(new Point(globalX, globalY));
if (logoColor == null) {
continue;
}
// ---- LUMINANZA del colore sottostante ----
int r = logoColor.getRed();
int g = logoColor.getGreen();
int b = logoColor.getBlue();
int lum = (int)(
0.2126 * r +
0.7152 * g +
0.0722 * b
);
// stesso alpha di case 3 (opaco)
int grayARGB =
(255 << 24) |
(lum << 16) |
(lum << 8) |
lum;
img_l.setRGB(x, y, grayARGB);
}
}
}
break;
case 5:
Color baseColor = new Color(0, 255, 0); // <-- COLORE SCELTO
for (int y = 0; y < img_l.getHeight(); y++) {
for (int x = 0; x < img_l.getWidth(); x++) {
int argb = img_l.getRGB(x, y);
Color lc = new Color(argb, true);
if (lc.getAlpha() == 0) {
continue; // stesso comportamento di case 3 / 4
}
int globalX = colonnaPos.x + l.getPosition().x + x;
int globalY = colonnaPos.y + l.getPosition().y + y;
Color logoColor = getPixelColor(new Point(globalX, globalY));
if (logoColor == null) {
continue;
}
// ---- LUMINANZA background ----
int r = logoColor.getRed();
int g = logoColor.getGreen();
int b = logoColor.getBlue();
int lum = (int)(
0.2126 * r +
0.7152 * g +
0.0722 * b
);
float factor = lum / 255f;
int rr = (int)(baseColor.getRed() * factor);
int gg = (int)(baseColor.getGreen() * factor);
int bb = (int)(baseColor.getBlue() * factor);
int colorARGB =
(255 << 24) |
(rr << 16) |
(gg << 8) |
bb;
img_l.setRGB(x, y, colorARGB);
}
}
break;
// default:
// throw new AssertionError();
}
}
}

View File

@@ -21,16 +21,16 @@ import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class MatrixForm extends javax.swing.JFrame {
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(MatrixForm.class.getName());
private int Maxcol=500;
private int Maxcol=700;
private Logo logo;
private Color background=Color.black;
private List <Colonna> colonne =new ArrayList<>();
private boolean sovrapposizione=true;
private int velocita=1;
private Min_Max dissolvenza=null;//new Min_Max(0.01f, 0.02f);
private boolean sovrapposizione=false;
private int velocita=2;
private Min_Max dissolvenza=new Min_Max(0.0f, 0.000f);
private Integer max_lettere=null;
private Integer spazio=null;
private Color c_lettere=new Color(0, 255, 0, 255);
private Color c_lettere=new Color(0, 100, 0, 255);
private Color c_colonna=null;
@@ -132,7 +132,7 @@ public class MatrixForm extends javax.swing.JFrame {
Colonna c = colonne.get(i);
for(Lettera l:c.getLettere()){
if (logo.isLetterInsideLogo(l.getPositionGlobal(c.getLocation()), l.getSize())){
logo.modificaLettera(l,c.getLocation());
logo.modificaLettera(l,c.getLocation(),1);
}
}
}

36
src/matrix2/Min_Max.java Normal file
View File

@@ -0,0 +1,36 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package matrix2;
/**
*
* @author mstc
*/
public class Min_Max {
private float min,max;
public Min_Max(int min, int max){
this.min=min;
this.max=max;
}
public Min_Max(float min, float max){
this.min=min;
this.max=max;
}
public int get_min(){
return (int) this.min;
}
public int get_max(){
return (int) this.max;
}
public float get_minf(){
return this.min;
}
public float get_maxf(){
return this.max;
}
}