-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalog2digital.php
65 lines (60 loc) · 1.73 KB
/
analog2digital.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<html>
<head>
<title>a2d</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="clock.css">
</head>
<body>
<h1 class=center>Analog > Digital</h1>
<?php
function digit($min, $max, $step) {
return str_pad(round(rand($min, $max)/$step)*$step,2,0,STR_PAD_LEFT);
}
function hour2deg($value, $min) {
$fromRange = 12;
$toRange = 360;
$offset = $min / 2; // 60min = 30deg
$scaleFactor = $toRange / $fromRange;
// Re-zero the value within the from range
$tmpValue = $value;
// Rescale the value to the to range
$tmpValue *= $scaleFactor;
// Re-zero back to the to range
return $tmpValue + $offset;
}
function min2deg($value) {
$fromRange = 60;
$toRange = 360;
$scaleFactor = $toRange / $fromRange;
// Re-zero the value within the from range
$tmpValue = $value;
// Rescale the value to the to range
$tmpValue *= $scaleFactor;
// Re-zero back to the to range
return $tmpValue;
}
$icon = array("moon.png", "sun.png");
echo "<table>";
for ($row = 0; $row < 7; $row++) {
echo "<tr>";
for ($col = 0; $col < 2; $col++) {
$minute = digit(1,60,5);
$minuteDeg = min2deg($minute);
$hourDeg = hour2deg(digit(1,12,1), $minute);?>
<td class="clock" style="height: 20px;">
<div class="minutes-container">
<div class="minutes" style="transform: rotate(<?php echo $minuteDeg?>deg)"></div>
</div>
<div class="hours-container">
<div class="hours" style="transform: rotate(<?php echo $hourDeg?>deg)"></div>
</div>
<?php
echo "<img src=" . $icon[rand(0,1)] . " width=20 height=20>";?>
</td>
<td class=left>= ____ :____</td>
<?php }
echo "</tr>";
} ?>
</table>
</body>
</html>