Matrix digital rain: Difference between revisions

m
Minor code improvement.
m (Minor code improvement.)
m (Minor code improvement.)
Line 1,365:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
DigitalRain digitalRain = new DigitalRain(820800, 600);
frame.add(digitalRain);
frame.setLocationByPlatform(true);
Line 1,381:
setBackground(Color.BLACK);
columnCount = aWidth / spacing( 2 * halfColumnWidth ) - 1;
rowCount = aHeight / spacing( 2 * halfFontSize );
setCursor(getToolkit().createCustomCursor(
Line 1,401:
public DrawingCycle(int rowCount) {
columns = Stream.generate( () -> new Column(rowCount) )
.limit(columnCount / 2).collect(Collectors.toList());
bufferStrategy = getBufferStrategy();
scheduler = Executors.newSingleThreadScheduledExecutor();
Line 1,416:
graphics2D.fillRect(0, 0, getWidth(), getHeight());
for ( int col = 0; col < columnCount / 2 - 1; col++ ) {
for ( int row = 0; row < rowCount; row++ ) {
Symbol symbol = columns.get(col).symbols.get(row);
graphics2D.setFont(symbol.font);
graphics2D.setColor(symbol.color());
final int size = symbol.font.getSize();
graphics2D.drawString(symbol.element, ( 2 * col + 1 ) * spacing, row * spacing);
graphics2D.drawString(
symbol.element,
2 * halfColumnWidth * col + halfColumnWidth + ( 6 * halfFontSize - size ) / 2,
row * 2 * halfFontSize);
}
}
Line 1,471 ⟶ 1,475:
private void setFont() {
final int fontSize = ( random.nextInt(2) == 0 ) ? 12 : ( random.nextInt(2) == 0 ) ? 9 : 18;
2 * halfFontSize : ( random.nextInt(2) == 0 ) ?
(int) ( 1.5 * halfFontSize ) : 3 * halfFontSize;
final int fontStyle = ( random.nextInt(3) == 0 ) ? Font.BOLD : Font.PLAIN;
font = new Font("Dialog", fontStyle, fontSize);
Line 1,518 ⟶ 1,524:
private final int rowCount;
private final ExecutorService executiveService;
private final int spacinghalfFontSize = 106;
private final int halfColumnWidth = 10;
private final ThreadLocalRandom random;
private final List<String> elements = List.of(
Line 1,540 ⟶ 1,547:
} // End DigitalRain class
 
} // End MatrixDigitalRain class
</syntaxhighlight>
{{ out }}
884

edits