Added documentation and original Java version.
This commit is contained in:
parent
52c3ec642d
commit
cf560f576d
69
README.md
69
README.md
|
@ -1,30 +1,57 @@
|
|||
# Dominoclock
|
||||
|
||||
This is code that's been around since 1996 or so, and is one of the
|
||||
three first Javascript programs I ever wrote. It's just the "time of
|
||||
day" counter for the fictional world that's the setting of my
|
||||
long-running [space opera
|
||||
series](https://www.pendorwright.com/journals/). It has its own
|
||||
calendar, and unlike Star Trek, I had in mind what the "star dates"
|
||||
would mean early on.
|
||||
It's nostalgia week at Pendorwright Labs, where toy programs are the
|
||||
order of the day. DominoClock is a simulation (or a re-implementation)
|
||||
of a nifty electromechanical watch I saw back about 25 years ago; it was
|
||||
a watch with a domino face, and the points on it elevated as the minutes
|
||||
slipped by. It was kinda-sorta meant for the blind, so re-implementing
|
||||
it as a web application is a bit silly. It only has a resolution of
|
||||
every five minutes, so implementing the seconds hand is also a bit
|
||||
silly, but it lets you see that the clock is working as planned.
|
||||
|
||||
# Motivation
|
||||
|
||||
This is a slightly modernized version, just to see what it would be
|
||||
like to write this in 2021. The answer is that not much has changed;
|
||||
the code runs just fine, although `getYear()` has been deprecated,
|
||||
replaced by `.geUTCFullYear()`. The syntax of 2021 Javascript is a lot
|
||||
nicer than 1996, although there is a limit to how much density one can
|
||||
achieve when it's a lot of fiddly calculations around converting
|
||||
human-readable dates into Pendorian-readable ones.
|
||||
In the `orginal/` folder, you'll find the Java (!) program I wrote back
|
||||
in 1996. This is literally my first and, if memory serves me correctly,
|
||||
only Java applet I ever wrote. It's written in Java so old it may even
|
||||
be before Java 1.0 was released. Sun used to send a sales team to nerdy
|
||||
offices and, while the main guy talked to the managers, the sales
|
||||
engineer would slip the devs a CD or two with labels like "Java 0.9
|
||||
beta" and "Sun Proprietary - Not for general release" handwritten on
|
||||
them. By the time management got around to asking the nerds, "Have you
|
||||
heard about this Java thing?" we'd already been playing with it for
|
||||
months.
|
||||
|
||||
What this project _really_ involves is preserving the basic elements
|
||||
of prettier, eslint, vitejs, and typescript that I routinely use these
|
||||
days as the basis of my Javascript work. Most of the configuration
|
||||
files are short, as you'd expect from a vanilla javascript project
|
||||
with a single source file and no framework, but they do include things
|
||||
like sourcemap inclusion, minification, and using rollup to generate
|
||||
proper EcmaScript-6.
|
||||
I just wanted to see it again.
|
||||
|
||||
I also wanted to practice a bit more with web components. I think
|
||||
they're more important than React, and I have a strong preference for
|
||||
the way they integrate with the browser ecosystem rather than fight
|
||||
against it the way React does.
|
||||
|
||||
# Running It
|
||||
|
||||
```
|
||||
$ npm install
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
It'll be on port 3000.
|
||||
|
||||
It's written using the original colors I chose back in 1996, so it's
|
||||
more than a bit ugly. This version, though, has rounded corners and
|
||||
dots, so there's that. It does respond to a variety of CSS variables, so
|
||||
you can change the size and colors. I *really* should make it resize
|
||||
the faces in response to the overall size of the container allocated to
|
||||
the `<domino-clock />` component, but that's a future task.
|
||||
|
||||
# TODO
|
||||
|
||||
- Add a few more CSS variables.
|
||||
- Make it respond to the size of the container, rather than forcing its
|
||||
size.
|
||||
- Make the faces aria-compliant. `aria-valuenow` seems like the safest
|
||||
bet.
|
||||
|
||||
# License
|
||||
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
//Draw a clock based upon the Domino display.
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.util.*;
|
||||
import java.lang.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DominoClock extends Applet implements Runnable {
|
||||
|
||||
int StartX, StartY, SquareD, DotRad;
|
||||
Color bgColor, dominoColor, dotColor;
|
||||
Thread clock = null;
|
||||
String background;
|
||||
|
||||
public void init() {
|
||||
|
||||
try {
|
||||
background = getParameter( "bgcolor" );
|
||||
} catch (NullPointerException e) {};
|
||||
|
||||
if (( background == null ) ||
|
||||
( background.charAt(0) != '#' ) ||
|
||||
( background.length() != 7 )) {
|
||||
Integer rgbValue = new Integer(0);
|
||||
bgColor = new Color(rgbValue.intValue());
|
||||
} else {
|
||||
Integer rgbValue = new Integer(0);
|
||||
rgbValue = Integer.valueOf( background.substring(1,7), 16 );
|
||||
bgColor = new Color(rgbValue.intValue());
|
||||
}
|
||||
|
||||
try {
|
||||
background = getParameter( "dominocolor" );
|
||||
} catch (NullPointerException e) {};
|
||||
if (( background == null ) ||
|
||||
( background.charAt(0) != '#' ) ||
|
||||
( background.length() != 7 )) {
|
||||
Integer rgbValue = new Integer(14331680);
|
||||
dominoColor = new Color(rgbValue.intValue());
|
||||
} else {
|
||||
Integer rgbValue = new Integer(14331680);
|
||||
rgbValue = Integer.valueOf( background.substring(1,7), 16 );
|
||||
dominoColor = new Color(rgbValue.intValue());
|
||||
}
|
||||
|
||||
try {
|
||||
background = getParameter( "dotcolor" );
|
||||
} catch (NullPointerException e) {};
|
||||
if (( background == null ) ||
|
||||
( background.charAt(0) != '#' ) ||
|
||||
( background.length() != 7 )) {
|
||||
Integer rgbValue = new Integer(3100495);
|
||||
dotColor = new Color(rgbValue.intValue());
|
||||
} else {
|
||||
Integer rgbValue = new Integer(3100495);
|
||||
rgbValue = Integer.valueOf( background.substring(1,7), 16 );
|
||||
dotColor = new Color(rgbValue.intValue());
|
||||
}
|
||||
|
||||
Dimension D = size();
|
||||
|
||||
if (D.height > (3 * D.width)) {
|
||||
SquareD = D.width;
|
||||
StartX = 0;
|
||||
StartY = 0; // (D.height / 3) - SquareD;
|
||||
}
|
||||
else {
|
||||
SquareD = (D.height / 3);
|
||||
StartY = 0;
|
||||
StartX = 0; //.width - (SquareD / 3);
|
||||
}
|
||||
|
||||
DotRad = (int) (Math.sqrt(2 * SquareD * SquareD) / 6);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
|
||||
int Hour, Min, Sec;
|
||||
Date D = new Date();
|
||||
|
||||
Hour = D.getHours();
|
||||
if (Hour > 12) Hour = Hour - 12;
|
||||
Min = D.getMinutes();
|
||||
Sec = D.getSeconds();
|
||||
|
||||
Tock(StartX, StartY, Hour, g);
|
||||
Tock(StartX, StartY + SquareD, (Min / 5), g);
|
||||
Tock(StartX, StartY + (2 * SquareD), (Sec / 5), g);
|
||||
}
|
||||
|
||||
public void update(Graphics g) {
|
||||
paint(g); // Overridden to prevent flicker.
|
||||
}
|
||||
|
||||
public void start() {
|
||||
clock = new Thread(this);
|
||||
clock.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
clock.stop();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(true) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch(InterruptedException e) {}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void Tock(int StartX, int StartY, int time, Graphics g) {
|
||||
|
||||
g.setColor(dominoColor);
|
||||
g.fillRect(StartX, StartY, SquareD, SquareD);
|
||||
g.setColor(dotColor);
|
||||
|
||||
if ((time == 1) || (time == 5) || (time == 8) || (time == 9) || (time == 11))
|
||||
g.fillOval(StartX + DotRad, StartY + DotRad, DotRad, DotRad);
|
||||
|
||||
if ((time == 2) || (time == 5) || (time == 6) || (time == 10) || (time == 11))
|
||||
g.fillOval(StartX + SquareD - (2 * DotRad), StartY + DotRad, DotRad, DotRad);
|
||||
|
||||
if ((time == 3) || (time == 6) || (time == 7) || (time == 9) || (time == 11))
|
||||
g.fillOval(StartX + SquareD - (2 * DotRad), StartY + SquareD - (2 * DotRad), DotRad, DotRad);
|
||||
|
||||
if ((time == 4) || (time == 7) || (time == 8) || (time == 10) || (time == 11))
|
||||
g.fillOval(StartX + DotRad, StartY + SquareD - (2 * DotRad), DotRad, DotRad);
|
||||
|
||||
g.drawLine(StartX, StartY + SquareD - 1, StartX + SquareD, StartY + SquareD - 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
Frame f1 = new Frame("Domino Clock");
|
||||
DominoClock s1 = new DominoClock();
|
||||
|
||||
f1.add("Center", s1);
|
||||
f1.resize(300, 300);
|
||||
f1.show();
|
||||
|
||||
s1.init();
|
||||
s1.start();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue