inizio progetto matrix
This commit is contained in:
73
build.xml
Normal file
73
build.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="Matrix" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Matrix.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="Matrix-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
3
manifest.mf
Normal file
3
manifest.mf
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
1757
nbproject/build-impl.xml
Normal file
1757
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@@ -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
|
||||
98
nbproject/project.properties
Normal file
98
nbproject/project.properties
Normal file
@@ -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
|
||||
13
nbproject/project.xml
Normal file
13
nbproject/project.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>Matrix</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots/>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
138
src/matrix/ColonnaLettere.java
Normal file
138
src/matrix/ColonnaLettere.java
Normal file
@@ -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<Lettera> 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<Lettera> getLettere() {
|
||||
return this.lettere;
|
||||
}
|
||||
|
||||
}
|
||||
108
src/matrix/Lettera.java
Normal file
108
src/matrix/Lettera.java
Normal file
@@ -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; }
|
||||
}
|
||||
84
src/matrix/Logo.java
Normal file
84
src/matrix/Logo.java
Normal file
@@ -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; }
|
||||
}
|
||||
27
src/matrix/Matrix.java
Normal file
27
src/matrix/Matrix.java
Normal file
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
35
src/matrix/MatrixForm.form
Normal file
35
src/matrix/MatrixForm.form
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="3"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
||||
227
src/matrix/MatrixForm.java
Normal file
227
src/matrix/MatrixForm.java
Normal file
@@ -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<ColonnaLettere> 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* 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);
|
||||
// }
|
||||
//</editor-fold>
|
||||
|
||||
/* 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
|
||||
}
|
||||
44
test/MatrixForm2NGTest.java
Normal file
44
test/MatrixForm2NGTest.java
Normal file
@@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
44
test/MatrixForm2Test.java
Normal file
44
test/MatrixForm2Test.java
Normal file
@@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user