Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,106 @@
::Draw a Clock Task from Rosetta Code Wiki
::Batch File Implementation
::
::Directly open the Batch File...
@echo off & mode 44,8
title Sample Batch Clock
setlocal enabledelayedexpansion
::Set the characters...
set "#0_1=ÛÛÛÛÛ"
set "#0_2=Û Û"
set "#0_3=Û Û"
set "#0_4=Û Û"
set "#0_5=ÛÛÛÛÛ"
set "#1_1= Û"
set "#1_2= Û"
set "#1_3= Û"
set "#1_4= Û"
set "#1_5= Û"
set "#2_1=ÛÛÛÛÛ"
set "#2_2= Û"
set "#2_3=ÛÛÛÛÛ"
set "#2_4=Û "
set "#2_5=ÛÛÛÛÛ"
set "#3_1=ÛÛÛÛÛ"
set "#3_2= Û"
set "#3_3=ÛÛÛÛÛ"
set "#3_4= Û"
set "#3_5=ÛÛÛÛÛ"
set "#4_1=Û Û"
set "#4_2=Û Û"
set "#4_3=ÛÛÛÛÛ"
set "#4_4= Û"
set "#4_5= Û"
set "#5_1=ÛÛÛÛÛ"
set "#5_2=Û "
set "#5_3=ÛÛÛÛÛ"
set "#5_4= Û"
set "#5_5=ÛÛÛÛÛ"
set "#6_1=ÛÛÛÛÛ"
set "#6_2=Û "
set "#6_3=ÛÛÛÛÛ"
set "#6_4=Û Û"
set "#6_5=ÛÛÛÛÛ"
set "#7_1=ÛÛÛÛÛ"
set "#7_2= Û"
set "#7_3= Û"
set "#7_4= Û"
set "#7_5= Û"
set "#8_1=ÛÛÛÛÛ"
set "#8_2=Û Û"
set "#8_3=ÛÛÛÛÛ"
set "#8_4=Û Û"
set "#8_5=ÛÛÛÛÛ"
set "#9_1=ÛÛÛÛÛ"
set "#9_2=Û Û"
set "#9_3=ÛÛÛÛÛ"
set "#9_4= Û"
set "#9_5=ÛÛÛÛÛ"
set "#C_1= "
set "#C_2=Û"
set "#C_3= "
set "#C_4=Û"
set "#C_5= "
:clock_loop
::Clear display [leaving a whitespace]...
for /l %%C in (1,1,5) do set "display%%C= "
::Get current time [all spaces will be replaced to zero]...
::Also, all colons will be replaced to "C" because colon has a function in variables...
set "curr_time=%time: =0%"
set "curr_time=%curr_time::=C%"
::Process the numbers to display [we will now use the formats we SET above]...
for /l %%T in (0,1,7) do (
::Check for each number and colons...
for %%N in (0 1 2 3 4 5 6 7 8 9 C) do (
if "!curr_time:~%%T,1!"=="%%N" (
::Now, barbeque each formatted char in 5 rows...
for /l %%D in (1,1,5) do set "display%%D=!display%%D!!#%%N_%%D! "
)
)
)
::Refresh the clock...
cls
echo.
echo.[%display1%]
echo.[%display2%]
echo.[%display3%]
echo.[%display4%]
echo.[%display5%]
echo.
timeout /t 1 /nobreak >nul
goto :clock_loop

View file

@ -1,29 +1,27 @@
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import static java.lang.Math.*;
import java.time.LocalTime;
import javax.swing.*;
class Clock extends JPanel {
final float degrees06 = (float) Math.toRadians(6);
final float degrees06 = (float) (PI / 30);
final float degrees30 = degrees06 * 5;
final float degrees90 = degrees30 * 3;
final int size = 550;
final int spacing = 20;
final int size = 590;
final int spacing = 40;
final int diameter = size - 2 * spacing;
final int x = diameter / 2 + spacing;
final int y = diameter / 2 + spacing;
final int cx = diameter / 2 + spacing;
final int cy = diameter / 2 + spacing;
public Clock() {
setPreferredSize(new Dimension(size, size));
setBackground(Color.white);
new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
new Timer(1000, (ActionEvent e) -> {
repaint();
}).start();
}
@ -34,46 +32,50 @@ class Clock extends JPanel {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.black);
g.drawOval(spacing, spacing, diameter, diameter);
drawFace(g);
Calendar date = Calendar.getInstance();
int hours = date.get(Calendar.HOUR);
int minutes = date.get(Calendar.MINUTE);
int seconds = date.get(Calendar.SECOND);
final LocalTime time = LocalTime.now();
int hour = time.getHour();
int minute = time.getMinute();
int second = time.getSecond();
float angle = degrees90 - (degrees06 * seconds);
float angle = degrees90 - (degrees06 * second);
drawHand(g, angle, diameter / 2 - 30, Color.red);
float minsecs = (minutes + seconds / 60.0F);
float minsecs = (minute + second / 60.0F);
angle = degrees90 - (degrees06 * minsecs);
drawHand(g, angle, diameter / 3 + 10, Color.black);
float hourmins = (hours + minsecs / 60.0F);
float hourmins = (hour + minsecs / 60.0F);
angle = degrees90 - (degrees30 * hourmins);
drawHand(g, angle, diameter / 4 + 10, Color.black);
}
private void drawFace(Graphics2D g) {
g.setStroke(new BasicStroke(2));
g.setColor(Color.white);
g.fillOval(spacing, spacing, diameter, diameter);
g.setColor(Color.black);
g.drawOval(spacing, spacing, diameter, diameter);
}
private void drawHand(Graphics2D g, float angle, int radius, Color color) {
int x2 = x + (int) (radius * Math.cos(angle));
int y2 = y + (int) (radius * Math.sin(-angle)); // flip y-axis
int x = cx + (int) (radius * cos(angle));
int y = cy - (int) (radius * sin(angle));
g.setColor(color);
g.drawLine(x, y, x2, y2);
g.drawLine(cx, cy, x, y);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Clock");
f.setResizable(false);
f.add(new Clock(), BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
SwingUtilities.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Clock");
f.setResizable(false);
f.add(new Clock(), BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
});
}
}