Skip to content

Commit

Permalink
Implemented matrix has you screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
okiktiev committed Apr 2, 2022
1 parent d44895b commit ced3ae2
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 9 deletions.
22 changes: 16 additions & 6 deletions src/main/java/com/delfin/matrix/$1999/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.delfin.matrix.HasYouScreen;
import com.delfin.matrix.settings.Settings.Position;

public class Matrix implements com.delfin.matrix.Matrix {
Expand All @@ -37,24 +38,25 @@ public void draw(Component canvas) {
Settings settings = Settings.getInstance();

Graphics g = canvas.getGraphics();

Dimension dim = canvas.getSize();

Image img = canvas.createImage(dim.width, dim.height);
Graphics g2 = img.getGraphics();

g2.setColor(Color.BLACK);
g2.fillRect(0, 0, dim.width, dim.height);

List<Line> accumulator = new ArrayList<>();



int[] pairRange = settings.getPairRange();
long drawBit = settings.getDrawBit();
topPosition = settings.getTopPosition();
midPosition = settings.getMidPosition();
botPosition = settings.getBotPosition();


long matrixHasYouTime = System.currentTimeMillis();

while (!isDestroyed && !Thread.interrupted()) {
int count = -1;
if (matrix.size() > 0) {
Expand Down Expand Up @@ -102,6 +104,14 @@ public void draw(Component canvas) {
matrix.get(i).draw(g2);
}
g.drawImage(img, 0, 0, canvas);
if (settings.isShowMatrixHasYouScreen() && System.currentTimeMillis() - matrixHasYouTime > 60_000) {
HasYouScreen.draw(g, dim);
matrix.clear();
xAllocations.clear();
matrixHasYouTime = System.currentTimeMillis();
g2.setColor(Color.BLACK);
g2.fillRect(0, 0, dim.width, dim.height);
}
}
delay(drawBit);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/delfin/matrix/$2021/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.delfin.matrix.HasYouScreen;
import com.delfin.matrix.settings.Settings.Position;

public class Matrix implements com.delfin.matrix.Matrix {
Expand Down Expand Up @@ -51,6 +52,8 @@ public void draw(Component canvas) {
midPosition = settings.getMidPosition();
botPosition = settings.getBotPosition();

long matrixHasYouTime = System.currentTimeMillis();

while (!isDestroyed && !Thread.interrupted()) {
int count = -1;
if (matrix.size() > 0) {
Expand Down Expand Up @@ -83,6 +86,14 @@ public void draw(Component canvas) {
matrix.get(i).draw(g2);
}
g.drawImage(img, 0, 0, canvas);
if (settings.isShowMatrixHasYouScreen() && System.currentTimeMillis() - matrixHasYouTime > 60_000) {
HasYouScreen.draw(g, dim);
matrix.clear();
xAllocations.clear();
matrixHasYouTime = System.currentTimeMillis();
g2.setColor(Color.BLACK);
g2.fillRect(0, 0, dim.width, dim.height);
}
}
delay(drawBit);
}
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/delfin/matrix/HasYouScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.delfin.matrix;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

public class HasYouScreen {

private static final Font FONT = new Font("Courier New", Font.BOLD, 28);
private static final Color COLOR = new Color(128, 255, 255);
private static final List<String> data = new ArrayList<>();
static {
data.add("Wake up, Neo...");
data.add("The Matrix has you...");
data.add("Follow the white rabbit.");
data.add("Knock, knock, Neo.");
}

private static int x = 10;
private static int y = 100;

public static void draw(Graphics g, Dimension dim) {
Font prevFont = g.getFont();
Color prevColor = g.getColor();

g.setFont(FONT);
for (int i = 0; i < data.size(); ++i) {
clr(g, dim);
int offset = 0;
String line = data.get(i);
if (i == data.size() - 1) {
offset = (int) g.getFontMetrics().getStringBounds(Character.toString(line.charAt(0)), g).getWidth();
g.drawString(line, x + offset, y);
} else {
for (char c : line.toCharArray()) {
String ch = Character.toString(c);
offset += (int) g.getFontMetrics().getStringBounds(ch, g).getWidth();
g.drawString(ch, x + offset, y);
Utils.delay(150);
}
}
Utils.delay(2000);
}

g.setFont(prevFont);
g.setColor(prevColor);
}

private static void clr(Graphics g, Dimension dim) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, dim.width, dim.height);
g.setColor(COLOR);
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/delfin/matrix/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class Settings {
protected Position topPosition;
protected Position midPosition;
protected Position botPosition;
private boolean isShowMatrixHasYouScreen;

protected static volatile boolean doReload;

Expand All @@ -51,6 +52,7 @@ protected void load() {
initTopPosition();
initMidPosition();
initBotPosition();
initShowMatrixHasYouScreen();

doReload = false;
} catch (Exception e) {
Expand Down Expand Up @@ -148,6 +150,10 @@ public final Position getBotPosition() {
return botPosition;
}

public boolean isShowMatrixHasYouScreen() {
return isShowMatrixHasYouScreen;
}

private void initFontName() throws FontFormatException, IOException {
fontName = getProperty("font.name");
InputStream is = CLASS_LOADER.getResourceAsStream("fonts/" + fontName + ".ttf");
Expand Down Expand Up @@ -189,6 +195,11 @@ private void initBotPosition() {
botPosition = new Position(Integer.parseInt(position[0]), parseRange(position[1]));
}

private void initShowMatrixHasYouScreen() {
String propValue = getProperty("show.matrix.has.you");
isShowMatrixHasYouScreen = Boolean.parseBoolean(propValue);
}

protected int[] parseRange(String propValue) {
String[] range = propValue.trim().split(",");
return new int[] { Integer.parseInt(range[0]), Integer.parseInt(range[1]) };
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/delfin/matrix/voluntary/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.delfin.matrix.HasYouScreen;

import static java.util.stream.Stream.generate;
import static java.util.stream.Collectors.toList;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -43,8 +45,9 @@ public void draw(Component canvas) {

Image img = canvas.createImage(dim.width, dim.height);
Graphics g2 = img.getGraphics();

ExecutorService executor = Executors.newCachedThreadPool();
long matrixHasYouTime = System.currentTimeMillis();

try {
while (!isDestroyed && !Thread.interrupted()) {
Expand Down Expand Up @@ -83,6 +86,13 @@ public Void call() throws Exception {
matrix.removeFirst();
}
matrix.add(lines);

if (settings.isShowMatrixHasYouScreen() && System.currentTimeMillis() - matrixHasYouTime > 60_000) {
HasYouScreen.draw(g, dim);
matrix.clear();
matrixHasYouTime = System.currentTimeMillis();
}

}
} catch (Exception e) {
if (e instanceof InterruptedException) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/matrix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#1999,2021,voluntary
app.matrix.type=1999

show.matrix.has.you=true

# settings for voluntary(initial) matrix
font.name=jpn_boot
Expand Down
2 changes: 1 addition & 1 deletion todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ implemented matrix 1999 ................... 20Jan2022
implemented matrix 2021 ................... 22Jan2022
implemented settings management ........... 29Jan2022
released 2.0.0.0 .......................... 29Jan2022
imp matrix has you screen ................. 02Apr2022


imp snapshot image to file
imp screen saver
imp yelow matrix
imp avoid tick-tack raining
imp system tray
imp matrix has you screen
imp find alternative font

0 comments on commit ced3ae2

Please sign in to comment.