Skip to content

Commit

Permalink
Added clock to Lively
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandgrandRealMe committed Jun 28, 2024
1 parent 99493e5 commit e9c82cf
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 16 deletions.
57 changes: 57 additions & 0 deletions Lively/LivelyProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,63 @@
"type": "checkbox",
"value": false
},
"clockLabel": {
"type": "label",
"value": "CLOCK"
},
"clockEnabled": {
"type": "checkbox",
"value": false,
"text": "Enable Clock"
},
"clockSecondsEnabled": {
"type": "checkbox",
"value": false,
"text": "Enable Seconds"
},
"clockDateEnabled": {
"type": "checkbox",
"value": false,
"text": "Enable Date"
},
"clockDateFormat": {
"type": "dropdown",
"value": 3,
"text": "Date Format",
"items": [
"MM/DD/YYYY",
"DD/MM/YYYY",
"YYYY-MM-DD",
"MMMM DD, YYYY"
]
},
"clockColor": {
"text": "Clock Color",
"type": "color",
"value": "#ffffff"
},
"clockFontSize": {
"text" : "Clock Size",
"type" : "textbox",
"value" : "50"
},
"dateFontSize": {
"text" : "Date Size",
"type" : "textbox",
"value" : "30"
},
"clockPosition": {
"type": "dropdown",
"value": 0,
"text": "Date Format",
"items": [
"Middle",
"Top Right",
"Top Left",
"Bottom Right",
"Bottom Left"
]
},
"miscLabel": {
"type": "label",
"value": "MISC"
Expand Down
13 changes: 12 additions & 1 deletion Lively/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
<link href="./styles/style.css" rel="stylesheet" type="text/css" />
</head>

<div id="MATRIX"><canvas></canvas></div>
<div id="CLOCK-BOX" class="CLOCK-BOX">
<div id="CLOCK-ITEMS" class="CLOCK-ITEMS">
<div id="CLOCK-TIME" class="CLOCK-TIME"></div>
<div id="CLOCK-DATE" class="CLOCK-DATE"></div>
</div>
</div>

<div id="MATRIX" class="MATRIX">
<canvas></canvas>
</div>

<script src="./scripts/options.js"></script>
<script src="./scripts/matrix.js"></script>
<script src="./scripts/clock.js"></script>

</html>
112 changes: 112 additions & 0 deletions Lively/scripts/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
var timerId;

var clockBox = document.getElementById("CLOCK-BOX");
var clockItems = document.getElementById("CLOCK-ITEMS");
var clockDate = document.getElementById("CLOCK-DATE");
var clockTime = document.getElementById("CLOCK-TIME");

const formatRegexps = {
"MM/DD/YYYY": /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/,
"DD/MM/YYYY": /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/,
"YYYY-MM-DD": /^(\d{4})-(\d{1,2})-(\d{1,2})$/,
"MMMM DD, YYYY": /^(.+) (\d+), (\d{4})$/, // Capture month name, day, year
};

function formatDate(date, format) {
// Format the date according to the user-specified format
let formattedDate = "";
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

switch (format) {
case "MM/DD/YYYY":
formattedDate = `${date.getMonth()}/${date.getDate()}/${date.getFullYear()}`;
break;
case "DD/MM/YYYY":
formattedDate = `${date.getDate()}/${date.getMonth()}/${date.getFullYear()}`;
break;
case "YYYY-MM-DD":
formattedDate = `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
break;
case "MMMM DD, YYYY":
formattedDate = `${monthNames[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
break;
default:
alert("Unsupported date format! " + format);
return;
}

return formattedDate;
}


function ClockSetSizePos() {
clockTime.style.fontSize = clockFontSize + "px";
clockDate.style.fontSize = dateFontSize + "px";
if (clockPosition == "middle") {
clockBox.style.justifyContent = "center";
clockItems.style.alignItems = "center";
clockBox.style.alignItems = "center";
}
if (clockPosition == "top-right") {
clockBox.style.justifyContent = "right";
clockItems.style.alignItems = "flex-end";
clockBox.style.alignItems = "normal";
}
if (clockPosition == "top-left") {
clockBox.style.justifyContent = "left";
clockItems.style.alignItems = "flex-start";
clockBox.style.alignItems = "normal";
}
if (clockPosition == "bottom-right") {
clockBox.style.justifyContent = "right";
clockItems.style.alignItems = "flex-end";
clockBox.style.alignItems = "flex-end";
}
if (clockPosition == "bottom-left") {
clockBox.style.justifyContent = "left";
clockItems.style.alignItems = "flex-start";
clockBox.style.alignItems = "flex-end";
}
}

function ClockChangeTime() {
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();

// Format hours with leading zero if needed (01 instead of 1)
hours = hours % 12 || 12; // 0 for midnight, 12 for noon

// Format minutes with leading zero
minutes = minutes.toString().padStart(2, '0');

// Determine AM/PM
var ampm = hours >= 12 ? 'PM' : 'AM';

if (clockEnabled) {
clockBox.style.display = "flex";
if (clockSecondsEnabled) {
seconds = seconds.toString().padStart(2, '0');
var formattedTime = `${hours}:${minutes}:${seconds} ${ampm}`;
clockTime.innerHTML = formattedTime;
} else {
var formattedTime = `${hours}:${minutes} ${ampm}`;
clockTime.innerHTML = formattedTime;
}
if (clockDateEnabled) {
clockDate.innerHTML = formatDate(date, clockDateFormat);
}
} else {
clockBox.style.display = "none";
}
}

function ClockRefresh() {
if (timerId) clearInterval(timerId);
timerId = setInterval(ClockChangeTime, 30);
ClockSetSizePos()
}

ClockRefresh()
56 changes: 55 additions & 1 deletion Lively/scripts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ function invertNumber(number) {
return 101 - number;
}

var colors = { background: "#000000", foregroundPrimary: "#00ff00", foregroundSecondary: null, firstCharacter: "#ffffff"};
var colors = { background: "#000000", foregroundPrimary: "#00ff00", foregroundSecondary: null, firstCharacter: "#ffffff" };

var gradientEnabled = false;
var characters = "ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ";
var fallSpeed = 33;
var symbolSize = 15;

// Clock stuff
var clockEnabled = qs("clock") || false;
var clockSecondsEnabled = qs("clockseconds") || false;
var clockDateEnabled = qs("clockdate") || false;
var clockDateFormat = decodeURIComponent(qs("clockdateformat")) || "MMMM DD, YYYY";
var clockColor = qs("clockcolor") || "#ffffff";
var clockFontSize = qs("clockfontsize") || "50";
var dateFontSize = qs("datefontsize") || "30";
var clockPosition = qs("clockposition") || "middle";

function livelyPropertyListener(name, val) {
switch (name) {
Expand Down Expand Up @@ -42,5 +51,50 @@ function livelyPropertyListener(name, val) {
symbolSize = val;
refresh();
break;
case "clockEnabled":
clockEnabled = val;
ClockRefresh();
break;
case "clockSecondsEnabled":
clockSecondsEnabled = val;
ClockRefresh();
break;
case "clockDateEnabled":
clockDateEnabled = val;
ClockRefresh();
break;
case "clockDateFormat":
var Formats = [
"MM/DD/YYYY",
"DD/MM/YYYY",
"YYYY-MM-DD",
"MMMM DD, YYYY"
];
clockDateFormat = Formats[val];
ClockRefresh();
break;
case "clockColor":
clockColor = val;
ClockRefresh();
break;
case "clockFontSize":
clockFontSize = val;
ClockRefresh();
break;
case "dateFontSize":
dateFontSize = val;
ClockRefresh();
break;
case "clockPosition":
var Positions = [
"middle",
"top-right",
"top-left",
"bottom-right",
"bottom-left"
];
clockPosition = Positions[val];
ClockRefresh();
break;
}
}
44 changes: 30 additions & 14 deletions Lively/styles/style.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
* {
margin: 0;
padding: 0;
}

html {
height: 100%;
width: 100%;
}

canvas {
display: block;
height: 100%;
width: 100%;
}
margin: 0;
padding: 0;
}

html {
height: 100%;
width: 100%;
}

canvas {
display: block;
height: 100%;
width: 100%;
}

.CLOCK-BOX {
height: 100%;
width: 100%;
position: absolute;
color: white;
z-index: 1;
display: none;
font-family: Arial, sans-serif;
}

.CLOCK-ITEMS {
display: flex;
flex-direction: column;
margin: 20px;
}

0 comments on commit e9c82cf

Please sign in to comment.