From aae83af88acfb8921cf070f8931e0042c1a9b25a Mon Sep 17 00:00:00 2001 From: mstc Date: Tue, 27 Jan 2026 12:52:58 +0100 Subject: [PATCH] inizio progetto matrix --- build.xml | 73 ++ manifest.mf | 3 + nbproject/build-impl.xml | 1757 ++++++++++++++++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 98 ++ nbproject/project.xml | 13 + src/matrix/ColonnaLettere.java | 138 +++ src/matrix/Lettera.java | 108 ++ src/matrix/Logo.java | 84 ++ src/matrix/Matrix.java | 27 + src/matrix/MatrixForm.form | 35 + src/matrix/MatrixForm.java | 227 +++++ test/MatrixForm2NGTest.java | 44 + test/MatrixForm2Test.java | 44 + 14 files changed, 2659 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/matrix/ColonnaLettere.java create mode 100644 src/matrix/Lettera.java create mode 100644 src/matrix/Logo.java create mode 100644 src/matrix/Matrix.java create mode 100644 src/matrix/MatrixForm.form create mode 100644 src/matrix/MatrixForm.java create mode 100644 test/MatrixForm2NGTest.java create mode 100644 test/MatrixForm2Test.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..f5c10b5 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Matrix. + + + 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..0cff0c5 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1757 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set 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..4ceadd6 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=1634b6f8 +build.xml.script.CRC32=bfeaafa6 +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=1634b6f8 +nbproject/build-impl.xml.script.CRC32=dc01db55 +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..6c2399d --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,98 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Matrix +application.vendor=mstc +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}/Matrix.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/Matrix +endorsed.classpath= +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}:\ + ${libs.junit_5.classpath}:\ + ${libs.testng.classpath} +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=Matrix +main.class=matrix.Matrix +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 diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..7efca7b --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,13 @@ + + + org.netbeans.modules.java.j2seproject + + + Matrix + + + + + + + diff --git a/src/matrix/ColonnaLettere.java b/src/matrix/ColonnaLettere.java new file mode 100644 index 0000000..56ed7ee --- /dev/null +++ b/src/matrix/ColonnaLettere.java @@ -0,0 +1,138 @@ +package matrix; + +import java.awt.*; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import javax.swing.JPanel; + +public class ColonnaLettere extends JPanel { +private static final char[] MATRIX_CHARS = ( + "ヲァィゥェォャュョッ" + + "アイウエオカキクケコ" + + "サシスセソタチツテト" + + "ナニヌネノハヒフヘホ" + + "マミムメモヤユヨ" + + "ラリルレロワン" + + "0123456789@#$%&*+-/=<>()" +).toCharArray(); + + private final List lettere = new ArrayList<>(); + + private final int larghezza; + private final int yEnd; + + private boolean raggiuntoFondo = false; + + private final float dissolveStep; + private final int stepY; // distanza verticale tra lettere + public Logo logo; + private final int xPos; + + public ColonnaLettere(int x, int yStart, int yEnd, int larghezza) { + this.larghezza = larghezza; + this.yEnd = yEnd; + this.stepY = larghezza; + this.xPos = x; + this.dissolveStep = generaFloatCasuale(0.02f, 0.05f); + + setOpaque(false); + setBounds(x, yStart, larghezza, yEnd - yStart); + + creaNuovaLettera(); // prima lettera + } + + +// getter +public int getXPos() { + return xPos; +} +private char randomMatrixChar() { + return MATRIX_CHARS[ + ThreadLocalRandom.current().nextInt(MATRIX_CHARS.length) + ]; +} + + /* ===================== UPDATE ===================== */ + + // CHIAMATA DAL TIMER DEL FORM + public void aggiorna() { + + // dissolve lettere esistenti + for (Lettera l : lettere) { + l.dissolve(dissolveStep); + } + + lettere.removeIf(l -> l.getAlpha() <= 0); + + // aggiungi lettera finché non raggiungi il fondo + if (!raggiuntoFondo) { + float nuovaY = lettere.isEmpty() + ? 0 + : lettere.get(lettere.size() - 1).getPosition().y + stepY; + + if (nuovaY + stepY <= yEnd) { + creaNuovaLettera(nuovaY); + } else { + raggiuntoFondo = true; + } + } + + repaint(); + } + + public boolean isVuota() { + return raggiuntoFondo && lettere.isEmpty(); + } + + /* ===================== LETTERE ===================== */ + + private void creaNuovaLettera() { + creaNuovaLettera(0); + } + + private void creaNuovaLettera(float y) { + char c = randomMatrixChar(); + + + int fontSize = larghezza; + Font font = new Font("Monospaced", Font.BOLD, fontSize); + Canvas canvas = new Canvas(); + FontMetrics fm = canvas.getFontMetrics(font); + + int charWidth = fm.charWidth(c); + if (charWidth > 0) { + fontSize = (int) ((float) larghezza / charWidth * fontSize); + } + + Lettera l = new Lettera( + new Point2D.Float(0, y + fm.getAscent()), + Color.GREEN, + fontSize, + c + ); + + lettere.add(l); + } + + private float generaFloatCasuale(float min, float max) { + return min + (max - min) * ThreadLocalRandom.current().nextFloat(); + } + + /* ===================== DRAW ===================== */ + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D) g; + for (Lettera l : lettere) { + l.draw(g2); + } + } + + Iterable getLettere() { + return this.lettere; + } + +} diff --git a/src/matrix/Lettera.java b/src/matrix/Lettera.java new file mode 100644 index 0000000..cbacebd --- /dev/null +++ b/src/matrix/Lettera.java @@ -0,0 +1,108 @@ +package matrix; + +import java.awt.*; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.geom.AffineTransform; +import java.awt.geom.Area; +import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; + +public class Lettera { + private Point2D.Float position; + private Color colore; + private float alpha; + private int dimensione; + private char carattere; + private BufferedImage buffer; // immagine della lettera + private Shape shape; // shape della lettera + + + // Costruttore + public Lettera(Point2D.Float position, Color colore, int dimensione, char carattere) { + this.position = position; + this.colore = colore; + this.dimensione = dimensione; + this.carattere = carattere; + this.alpha = 1.0f; + + generaBuffer(); + } + private void generaBuffer() { + Font font = new Font("Monospaced", Font.BOLD, dimensione); + FontRenderContext frc = new FontRenderContext(null, true, true); + GlyphVector gv = font.createGlyphVector(frc, String.valueOf(carattere)); + shape = gv.getOutline(); + + Rectangle bounds = shape.getBounds(); + buffer = new BufferedImage(bounds.width + 2, bounds.height + 2, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = buffer.createGraphics(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setColor(colore); + g2.translate(-bounds.x, -bounds.y); // porta la lettera all'inizio del buffer + g2.fill(shape); + g2.dispose(); + } + + // Disegna la lettera sul Graphics2D + public void draw(Graphics2D g2) { + int x = (int) position.x; + int y = (int) position.y; + AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Math.min(1.0f, Math.max(0, alpha))); + g2.setComposite(ac); + g2.drawImage(buffer, x, y, null); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); + } + + // Aggiorna la trasparenza per far dissolvere la lettera + public void dissolve(float step) { + alpha -= step; + if (alpha < 0) alpha = 0; + } + + // Getter per alpha (utile per sapere se è scomparsa) + public float getAlpha() { + return alpha; + } + + // Setter e getter aggiuntivi se vuoi spostare o cambiare colore + public void setPosition(Point2D.Float pos) { + this.position = pos; + } + + public Point2D.Float getPosition() { + return position; + } + + public void setColore(Color colore) { + this.colore = colore; + } + + public Color getColore() { + return colore; + } + +public Shape getShapeAtPosition() { + AffineTransform at = AffineTransform.getTranslateInstance( + position.x, + position.y + ); + return at.createTransformedShape(shape); +} + +public Area getAreaAtPosition() { + AffineTransform at = AffineTransform.getTranslateInstance( + position.x, + position.y + ); + return new Area(at.createTransformedShape(shape)); +} +public Area getWorldArea(int colX, int colY) { + AffineTransform at = new AffineTransform(); + at.translate(colX + position.x, colY + position.y); + return new Area(at.createTransformedShape(shape)); +} + + // getter e setter + public int getDimensione() { return dimensione; } +} diff --git a/src/matrix/Logo.java b/src/matrix/Logo.java new file mode 100644 index 0000000..3ed6686 --- /dev/null +++ b/src/matrix/Logo.java @@ -0,0 +1,84 @@ +package matrix; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +public class Logo { + + private final BufferedImage image; // immagine del logo + private final int width, height; + private final float[][] pixelAlpha; // trasparenza dei pixel (0=spento, 1=acceso) + private final boolean[][] logoMask; // true se pixel fa parte del logo + + public Logo(String path) throws IOException { + image = ImageIO.read(new File(path)); + width = image.getWidth(); + height = image.getHeight(); + + pixelAlpha = new float[height][width]; + logoMask = new boolean[height][width]; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int alpha = (image.getRGB(x, y) >> 24) & 0xFF; + logoMask[y][x] = alpha > 10; // pixel del logo + pixelAlpha[y][x] = 0f; // inizialmente spento + } + } + } + + /** Sfuma tutti i pixel accesi */ + public void sfuma() { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + pixelAlpha[y][x] *= 0.9f; + } + } + } + + /** Disegna il logo sul Graphics2D nella posizione (posX, posY) */ + public void disegna(Graphics2D g, int posX, int posY) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + float alpha = pixelAlpha[y][x]; + if (alpha > 0) { + int rgb = image.getRGB(x, y); + Color c = new Color( + (rgb >> 16) & 0xFF, + (rgb >> 8) & 0xFF, + rgb & 0xFF, + Math.min(255, (int)(alpha * 255)) + ); + g.setColor(c); + g.fillRect(posX + x, posY + y, 1, 1); + } + } + } + } + + /** Accende i pixel del logo colpiti dalla lettera */ + public void accendiPixel(int xPos, int yPos, int dim, float alfa) { + for (int y = 0; y < dim; y++) { + for (int x = 0; x < dim; x++) { + int px = xPos + x; + int py = yPos + y; + + if (px >= 0 && px < width && py >= 0 && py < height && logoMask[py][px]) { + pixelAlpha[py][px] = alfa; + } + } + } + } + + /** Ritorna true se il pixel (px, py) è parte del logo */ + public boolean isLogoPixel(int px, int py) { + if (px < 0 || px >= width || py < 0 || py >= height) return false; + return logoMask[py][px]; + } + + public int getWidth() { return width; } + public int getHeight() { return height; } +} diff --git a/src/matrix/Matrix.java b/src/matrix/Matrix.java new file mode 100644 index 0000000..69c51a7 --- /dev/null +++ b/src/matrix/Matrix.java @@ -0,0 +1,27 @@ +/* + * 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 matrix; + +import java.awt.Color; + +/** + * + * @author mstc + */ +public class Matrix { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + MatrixForm x =new MatrixForm(); + x.setBackground(Color.black); + + x.setVisible(true); + + } + +} diff --git a/src/matrix/MatrixForm.form b/src/matrix/MatrixForm.form new file mode 100644 index 0000000..b606cd5 --- /dev/null +++ b/src/matrix/MatrixForm.form @@ -0,0 +1,35 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/matrix/MatrixForm.java b/src/matrix/MatrixForm.java new file mode 100644 index 0000000..c5006c1 --- /dev/null +++ b/src/matrix/MatrixForm.java @@ -0,0 +1,227 @@ +/* + * 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 matrix; + + + + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.geom.Area; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import javax.swing.JFrame; +import javax.swing.Timer; +/** + * + * @author mstc + */ +public class MatrixForm extends JFrame { + + private final List colonne = new ArrayList<>(); + + private int maxColonne = 100; + private final int yStart = 0; + private int yEnd = 600; + + private final int larghezzaMin = 5; + private final int larghezzaMax = 16; + + private Logo logo; + + // POSIZIONE LOGO (ORA ESISTE) + private int logoX; + private int logoY; + + public MatrixForm() { + + setTitle("Matrix Test"); + getContentPane().setBackground(Color.BLACK); + setExtendedState(JFrame.MAXIMIZED_BOTH); + setUndecorated(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(null); + + // listener resize (SENZA @Override) + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + yEnd = getHeight(); + maxColonne = Math.max(1, getWidth() / larghezzaMin); +// carica logo + try { + logo = new Logo("/home/mstc/Immagini/logo.png"); + + // posizione iniziale logo + logoX = (getWidth() - logo.getWidth()) / 2; + logoY = (getHeight() - logo.getHeight()) / 2; + + } catch (IOException ex) { + ex.printStackTrace(); + } + if (logo != null) { + logoX = (getWidth() - logo.getWidth()) / 2; + logoY = (getHeight() - logo.getHeight()) / 2; + } + } + }); + + setVisible(true); + + // crea colonne iniziali + for (int i = 0; i < maxColonne; i++) { + aggiungiNuovaColonna(); + } + + + + // timer principale + Timer timer = new Timer(16, e -> aggiornaColonne()); + timer.start(); + } + + + private void aggiungiNuovaColonna() { + + int larghezza = ThreadLocalRandom.current() + .nextInt(larghezzaMin, larghezzaMax + 1); + + int x = ThreadLocalRandom.current() + .nextInt(0, Math.max(1, getWidth() - larghezza)); + + ColonnaLettere col = new ColonnaLettere( + x, + yStart, + getHeight(), + larghezza + ); + + colonne.add(col); + add(col); + } + + + private void aggiornaColonne() { + + // aggiorna colonne + for (int i = colonne.size() - 1; i >= 0; i--) { + ColonnaLettere col = colonne.get(i); + col.aggiorna(); + + if (col.isVuota()) { + remove(col); + colonne.remove(i); + } + } + + // sostituisci colonne mancanti + while (colonne.size() < maxColonne) { + aggiungiNuovaColonna(); + } + + // controllo collisione lettere-logo + for (ColonnaLettere col : colonne) { + for (Lettera l : col.getLettere()) { + int lx = col.getXPos() + (int) l.getPosition().x; + int ly = (int) l.getPosition().y; + +// if (lx >= logoX && lx < logoX + logo.getWidth() && +// ly >= logoY && ly < logoY + logo.getHeight() && +// logo.isLogoPixel(lx - logoX, ly - logoY)) { +// +// l.dissolve(0.2f); +// logo.accendiPixel(lx - logoX, ly - logoY, l.getDimensione(), l.getAlpha()-0.10f); +// } + } + } + + logo.sfuma(); + repaint(); + } + + // DISEGNO + @Override + public void paint(Graphics g) { + super.paint(g); + + if (logo != null) { + logo.disegna((Graphics2D) g, logoX, logoY); + } + } + + +//private void aggiungiNuovaColonna() { +// int larghezza = ThreadLocalRandom.current().nextInt(16, 32); +// int x = ThreadLocalRandom.current().nextInt(0, Math.max(1, getWidth() - larghezza)); +// +// ColonnaLettere col = new ColonnaLettere( +// x, +// 0, +// getHeight(), +// larghezza +// ); +// +// colonne.add(col); +// add(col); +//} + + /** + * 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 +} diff --git a/test/MatrixForm2NGTest.java b/test/MatrixForm2NGTest.java new file mode 100644 index 0000000..bdc0d06 --- /dev/null +++ b/test/MatrixForm2NGTest.java @@ -0,0 +1,44 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/EmptyTestNGTest.java to edit this template + */ + +import static org.testng.Assert.*; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * + * @author mstc + */ +public class MatrixForm2NGTest { + + public MatrixForm2NGTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @BeforeMethod + public void setUpMethod() throws Exception { + } + + @AfterMethod + public void tearDownMethod() throws Exception { + } + + @Test + public void testSomeMethod() { + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + +} diff --git a/test/MatrixForm2Test.java b/test/MatrixForm2Test.java new file mode 100644 index 0000000..64f5f42 --- /dev/null +++ b/test/MatrixForm2Test.java @@ -0,0 +1,44 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit5TestClass.java to edit this template + */ + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * + * @author mstc + */ +public class MatrixForm2Test { + + public MatrixForm2Test() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + public void setUp() { + } + + @AfterEach + public void tearDown() { + } + + @Test + public void testSomeMethod() { + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + +}