From 298705a6853528b72330aa4f1c2fb7cfb7dcb1a5 Mon Sep 17 00:00:00 2001 From: mstc Date: Mon, 2 Feb 2026 01:03:45 +0100 Subject: [PATCH] Matrix effect funzionante, scie fluide, visualizza immagine colorando le lettere pixel per pixel --- build.xml | 73 ++ manifest.mf | 3 + nbproject/build-impl.xml | 1771 +++++++++++++++++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 95 ++ nbproject/project.xml | 15 + src/matrix2/Colonna.java | 121 +++ src/matrix2/Lettera.java | 90 ++ src/matrix2/Logo.java | 129 +++ src/matrix2/Matrix2.java | 24 + src/matrix2/MatrixForm.form | 35 + src/matrix2/MatrixForm.java | 156 +++ 12 files changed, 2520 insertions(+) create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/matrix2/Colonna.java create mode 100644 src/matrix2/Lettera.java create mode 100644 src/matrix2/Logo.java create mode 100644 src/matrix2/Matrix2.java create mode 100644 src/matrix2/MatrixForm.form create mode 100644 src/matrix2/MatrixForm.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..a94f082 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Matrix2. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..da30613 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1771 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..dd77442 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=64142c2c +build.xml.script.CRC32=ef325a85 +build.xml.stylesheet.CRC32=f85dc8f2@1.117.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=64142c2c +nbproject/build-impl.xml.script.CRC32=9c908c72 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.117.0.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..eafde83 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,95 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Matrix2.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/Matrix2 +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=21 +javac.target=21 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=Matrix2 +main.class=matrix2.Matrix2 +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..305b112 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Matrix2 + + + + + + + + + diff --git a/src/matrix2/Colonna.java b/src/matrix2/Colonna.java new file mode 100644 index 0000000..19fc87d --- /dev/null +++ b/src/matrix2/Colonna.java @@ -0,0 +1,121 @@ +package matrix2; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import javax.swing.JPanel; + +public class Colonna extends JPanel { + public static final char[] MATRIX_CHARS = ( + "ヲァィゥェォャュョッ" + + "アイウエオカキクケコ" + + "サシスセソタチツテト" + + "ナニヌネノハヒフヘホ" + + "マミムメモヤユヨ" + + "ラリルレロワン" + + "01010101010101010101010101010" + ).toCharArray(); + private final List lettere = new ArrayList<>(); + private final int width; + private int nextY = 0; // ← posizione verticale corrente + 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 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; + + 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.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); + addRandomChar(); + } + + public void addChar(char c) { + //int size = 20; // oppure random + Point p = new Point(0, nextY); + + Lettera l = new Lettera(c, this.width, p); + lettere.add(l); + + nextY += this.width; // ← distanza coerente con la dimensione + 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); + } + public void addRandomChar(){ + char c = MATRIX_CHARS[ThreadLocalRandom.current().nextInt(MATRIX_CHARS.length)]; + addChar(c); + } + public int count(){ + return lettere.size(); + } + 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 List getLettere(){ + return lettere; + } + 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()){ + lettere.remove(i); + }else{ + l.dissolve(dissolvenza); + l.draw((Graphics2D) g); + } + } + if (letteraAggiunte= 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()) { + return null; + } + + int argb = image.getRGB(lx, ly); + Color c = new Color(argb, true); + + return (c.getAlpha() == 0) ? null : c; + } + + public boolean isLetterInsideLogo(Point letterPos, int letterSize) { + int lx1 = letterPos.x; + int ly1 = letterPos.y; + int lx2 = lx1 + letterSize; + int ly2 = ly1 + letterSize; + + int rx1 = startPoint.x; + int ry1 = startPoint.y; + int rx2 = endPoint.x; + int ry2 = endPoint.y; + + 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 + ); + } + 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; + + 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.setRGB(x, y, logoColor.getRGB()); + } + } + + } + + } +} \ No newline at end of file diff --git a/src/matrix2/Matrix2.java b/src/matrix2/Matrix2.java new file mode 100644 index 0000000..1b08e91 --- /dev/null +++ b/src/matrix2/Matrix2.java @@ -0,0 +1,24 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ +package matrix2; + +/** + * + * @author mstc + */ +public class Matrix2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + MatrixForm form= new MatrixForm(); + //form.setBounds(null); + + + } + +} diff --git a/src/matrix2/MatrixForm.form b/src/matrix2/MatrixForm.form new file mode 100644 index 0000000..b606cd5 --- /dev/null +++ b/src/matrix2/MatrixForm.form @@ -0,0 +1,35 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/matrix2/MatrixForm.java b/src/matrix2/MatrixForm.java new file mode 100644 index 0000000..8556217 --- /dev/null +++ b/src/matrix2/MatrixForm.java @@ -0,0 +1,156 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template + */ +package matrix2; + +import java.awt.Color; +import java.awt.Point; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JFrame; +import javax.swing.Timer; +import static javax.swing.WindowConstants.EXIT_ON_CLOSE; + +/** + * + * @author mstc + */ +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 Logo logo; + private List colonne =new ArrayList<>(); + /** + * Creates new form MatrixForm + */ + public MatrixForm() { + setDefaultCloseOperation(EXIT_ON_CLOSE); + setExtendedState(JFrame.MAXIMIZED_BOTH); + getContentPane().setBackground(Color.BLACK); + getContentPane().setLayout(null); +// logo= new Logo("/home/mstc/Scaricati/io.jpg",new Point(400,100),75); + logo= new Logo("/home/mstc/Scaricati/mondo2.png",new Point(400,100),200); + initComponents(); +// col = new Colonna(30,this.getHeight()); +// this.add(col); +// col.addChar('A'); +// col.addRandomChar(); +// Colonna c = new Colonna(); +// this.add(c); +// colonne.add(c); + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + if (getHeight() <= 0) { + return; + } + resetColonne(); + } + }); + this.setVisible(true); + + // === TIMER (30 FPS circa) === + Timer timer = new Timer(1, e -> aggiorna()); + timer.start(); + } + + + private void aggiorna(){ + + repaint(); + + if (colonne.size()= 0; i--) { + if (colonne.get(i).isDead()){ + this.remove(colonne.get(i)); + colonne.remove(i); + }else{ + if (colonne.get(i).getBoundsRect().intersects(logo.getBoundsRect())) { + // la colonna passa sopra al logo + Colonna c = colonne.get(i); + for(Lettera l:c.getLettere()){ + if (logo.isLetterInsideLogo(l.getPositionGlobal(c.getLocation()), l.getSize())){ + logo.modificaLettera(l,c.getLocation()); + } + } + } + } + } + + } + private int randomPointX(){ + int min=0; + int max=this.getWidth(); + return (int) (min + Math.random() * (max - min)); + } + private void resetColonne() { +// colonne.forEach(this::remove); +// colonne.clear(); +// calcolaColonne(); + for (Colonna col:colonne){ + col.setSize(col.getWidth(), this.getHeight()); + col.setHeight(this.getHeight()); + } + + } + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 300, Short.MAX_VALUE) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) { + logger.log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(() -> new MatrixForm().setVisible(true)); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +}