effetti aggiunti, lettere in pixel immagine, lettere sopra ai pixel immagine, lettere piu scure o di altro colore se sopra all'immagine
This commit is contained in:
@@ -12,14 +12,16 @@ import javax.swing.JPanel;
|
||||
|
||||
public class Colonna extends JPanel {
|
||||
|
||||
public static final char[] MATRIX_CHARS = ("ヲァィゥェォャュョッ"
|
||||
+ "アイウエオカキクケコ"
|
||||
+ "サシスセソタチツテト"
|
||||
+ "ナニヌネノハヒフヘホ"
|
||||
+ "マミムメモヤユヨ"
|
||||
+ "ラリルレロワン"
|
||||
+ "01010101010101010101010101010"
|
||||
+ "Luca Mustacchio").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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
36
src/matrix2/Min_Max.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user