Matrix digital rain: Difference between revisions

m
Uploaded a new screenshot.
m (Adding a screenshot to output section.)
m (Uploaded a new screenshot.)
 
(5 intermediate revisions by the same user not shown)
Line 1,349:
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
Line 1,380 ⟶ 1,381:
setBackground(Color.BLACK);
columnCount = aWidth / spacing( 2 * halfColumnWidth ) - 1;
rowCount = aHeight / spacing( 2 * halfFontSize );
setCursor(getToolkit().createCustomCursor(
Line 1,392 ⟶ 1,393:
public void start() {
requestFocus();
createBufferStrategy(2);
executiveService.execute( new DrawingCycle(rowCount) );
}
Line 1,400 ⟶ 1,401:
public DrawingCycle(int rowCount) {
columns = Stream.generate( () -> new Column(rowCount) )
.limit(columnCount / 2).collect(Collectors.toList());
bufferStrategy = getBufferStrategy();
scheduler = Executors.newSingleThreadScheduledExecutor();
}
 
@Override
public void run() {
scheduler.scheduleAtFixedRate( () -> { draw(); update(); }, 0, 100, TimeUnit.MILLISECONDS);
while ( true ) {
draw();
update(100);
}
}
 
Line 1,417 ⟶ 1,416:
graphics2D.fillRect(0, 0, getWidth(), getHeight());
for ( int col = 0; col < columnCount / 2; 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,430 ⟶ 1,433:
}
private void update(long delay) {
for ( Column column : columns ) {
if ( column.index >= 0 ) {
Line 1,443 ⟶ 1,446:
column.reset();
}
}
}
try {
private final List<Column> columns;
TimeUnit.MILLISECONDS.sleep(delay);
private final BufferStrategy bufferStrategy;
} catch (InterruptedException ie) {
private final ScheduledExecutorService scheduler;
Thread.currentThread().interrupt();
}
}
private final BufferStrategy bufferStrategy;
private final List<Column> columns;
 
} // End DrawingCycle class
private static final class Column {
public Column(int aRowCount) {
Line 1,477 ⟶ 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,490:
} // End Column class
private static final class Symbol {
public Symbol(String aElement, Font aFont, int aBrightness) {
Line 1,524:
private final int rowCount;
private final ExecutorService executiveService;
private final int spacinghalfFontSize = 106;
private final int halfColumnWidth = 10;
private staticfinal ThreadLocalRandom random;
private final List<String> elements = List.of(
"M", "Ї", "Љ", "Њ", "Ћ", "Ќ", "Ѝ", "Ў", "Џ", "Б", "Г", "Д", "Ж", "И", "Й", "Л", "П", "Ф", "Ц", "Ч", "Ш",
Line 1,541 ⟶ 1,543:
"⳩", "∀", "∁", "∂", "∃", "∄", "∅", "∆", "∇", "∈", "∉", "∊", "∋", "∌", "∍", "∎", "∏", "∐", "∑", "∓",
"ℇ", "ℏ", "℥", "Ⅎ", "ℷ", "⩫", "⨀", "⨅", "⨆", "⨉", "⨍", "⨎", "⨏", "⨐", "⨑", "⨒", "⨓", "⨔", "⨕", "⨖",
"⨗", "⨘", "⨙", "⨚", "⨛", "⨜", "⨝", "⨿", "⩪" );
private static ThreadLocalRandom random;
} // End DigitalRain class
Line 1,550:
</syntaxhighlight>
{{ out }}
A screenshot from the running program.
[[Media: MatrixDigitalRainJavaJavaMatrixDigitalRain.png]]
 
=={{header|Javascript}}==
884

edits