{"id":1430,"date":"2023-05-13T10:14:00","date_gmt":"2023-05-13T07:14:00","guid":{"rendered":"https:\/\/notes.profidev.online\/?p=1430"},"modified":"2023-05-14T22:20:18","modified_gmt":"2023-05-14T19:20:18","slug":"typographic-clock","status":"publish","type":"post","link":"https:\/\/notes.profidev.online\/ru\/other\/1430\/","title":{"rendered":"Typographic Clock"},"content":{"rendered":"\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img fetchpriority=\"high\" decoding=\"async\" width=\"701\" height=\"319\" src=\"https:\/\/notes.profidev.online\/wp-content\/uploads\/2023\/05\/peek-2023-05-12-11-16.gif\" alt=\"Typographic Clock\" class=\"wp-image-1431 size-full\"\/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">\n  &lt;div class=&quot;clock&quot;&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;0&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;1&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;2&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;3&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;4&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;5&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;6&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;7&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;8&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;9&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;10&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;11&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;12&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;13&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;14&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;15&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;16&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;17&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;18&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;19&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;20&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;21&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;22&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;23&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;24&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;25&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;26&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;27&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;28&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;29&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;30&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;31&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;32&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;33&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;34&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;35&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;36&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;37&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;38&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;39&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;40&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;41&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;42&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;43&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;44&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;45&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;46&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;47&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;48&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;49&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;50&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;51&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;52&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;53&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;54&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;55&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;56&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;57&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;58&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;block&quot; data-num=&quot;59&quot;&gt;&lt;\/div&gt;\n    &lt;div class=&quot;divider&quot;&gt;&lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;div class=&quot;switch-theme&quot;&gt;\n    &lt;p&gt;Change theme&lt;\/p&gt;\n    &lt;label class=&quot;switch&quot;&gt;\n      &lt;input type=&quot;checkbox&quot; onchange=&quot;changeTheme(event)&quot;\/&gt;&lt;span class=&quot;slider&quot;&gt;&lt;\/span&gt;\n    &lt;\/label&gt;\n  &lt;\/div&gt;<\/pre><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/css&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;CSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;css&quot;}\">body {\n\twidth: 100vw;\n\theight: 100vh;\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tbackground: linear-gradient(to bottom right, #0f0f0f, #1a1a1a);\n\ttransition: all 0.4s;\n\tfont-family: &quot;Roboto Mono&quot;, monospace;\n\tfont-weight: 300;\n  }\n  \n  .clock {\n\tposition: relative;\n\tdisplay: flex;\n\tflex-flow: column wrap;\n\twidth: 280px;\n\theight: 100px;\n  }\n  \n  .block {\n\twidth: calc(100% \/ 12);\n\theight: 20%;\n\tcolor: #474747;\n\ttransition: 0.4s;\n  }\n  .block:not(:nth-child(n+16)):nth-child(n+11), .block:not(:nth-child(n+46)):nth-child(n+41) {\n\tmargin-right: 10px;\n  }\n  .block:not(:nth-child(n+31)):nth-child(n+26) {\n\tmargin-right: 20px;\n  }\n  .block:before {\n\tcontent: attr(data-num);\n\tposition: relative;\n\tdisplay: block;\n\tfont-size: 16px;\n\twidth: 100%;\n\theight: 100%;\n\tline-height: 20px;\n\ttext-align: center;\n  }\n  .block:nth-child(-n+10):before {\n\tcontent: &quot;0&quot; attr(data-num);\n  }\n  .block.active:before {\n\tcolor: whitesmoke;\n\tfont-weight: 500;\n  }\n  .block.second:before {\n\tcolor: #FF8300;\n  }\n  \n  .divider {\n\tposition: absolute;\n\twidth: 2px;\n\tbackground-color: whitesmoke;\n\theight: 60%;\n\ttop: 20%;\n\tleft: calc(50% + 19px);\n  }\n  \n  body.light-theme {\n\tbackground: #e6e6e6;\n  }\n  body.light-theme .block {\n\toutline: 1px solid #dfdfdf;\n\tcolor: #acacac;\n  }\n  body.light-theme .block.active:before {\n\tcolor: #333;\n  }\n  body.light-theme .block.second {\n\tbackground: #d4d4d4;\n  }\n  body.light-theme .block.second:before {\n\tcolor: #333;\n  }\n  body.light-theme .divider {\n\tbackground: #333;\n  }\n  \n  .switch-theme {\n\tposition: absolute;\n\tbottom: 40px;\n\tright: 40px;\n\tcolor: grey;\n  }\n  \n  .switch {\n\tposition: relative;\n\tdisplay: inline-block;\n\twidth: 60px;\n\theight: 34px;\n\tmargin-left: 30px;\n  }\n  .switch input {\n\tdisplay: none;\n  }\n  \n  .slider {\n\tposition: absolute;\n\tcursor: pointer;\n\ttop: 0;\n\tleft: 0;\n\tright: 0;\n\tbottom: 0;\n\tbackground-color: #ccc;\n\ttransition: all 0.4s;\n\tborder-radius: 34px;\n  }\n  .slider:before {\n\tposition: absolute;\n\tcontent: &quot;&quot;;\n\theight: 26px;\n\twidth: 26px;\n\tleft: 4px;\n\tbottom: 4px;\n\tbackground-color: white;\n\ttransition: 0.4s;\n\tborder-radius: 50%;\n  }\n  \n  input:checked + .slider {\n\tbackground-color: #333;\n  }\n  \n  input:focus + .slider {\n\tbox-shadow: 0 0 1px #2196F3;\n  }\n  \n  input:checked + .slider:before {\n\ttransform: translateX(26px);\n  }<\/pre><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const numbers = [\n\t[1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1], \/\/ 0\n\t[1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1], \/\/ 1\n\t[1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1], \/\/ 2\n\t[1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1], \/\/ 3\n\t[1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1], \/\/ 4\n\t[1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1], \/\/ 5\n\t[1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1], \/\/ 6\n\t[1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0], \/\/ 7\n\t[1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1], \/\/ 8\n\t[1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1]  \/\/ 9\n];\n\nconst blocks = [];\nconst digits = Array.from(document.querySelectorAll('.block'));\n\nfor (let i = 0; i &lt; 4; i++) {\n\tblocks.push(digits.slice( i * 15, i * 15 + 15 ));\n}\n\nconst setNum = (block, num) =&gt; {\n\tlet n = numbers[num];\n\tfor (let i = 0; i &lt; block.length; i++) {\n\t\t block[i].classList[ n[i] === 1 ?  'add' : 'remove']('active');\n\t}\n};\n\nconst time = {\n\ts: '',\n\tm: '',\n\th: '',\n\tp: null\n};\n\n\/\/ time loop\nconst animator = () =&gt; {\n\tlet d = new Date(),\n\t\t h = d.getHours().toString(),\n\t\t m = d.getMinutes().toString(),\n\t\t s = d.getSeconds().toString();\n\t\n\ts = s.length === 1 ? '0' + s : s;\n\tm = m.length === 1 ? '0' + m : m;\n\th = h.length === 1 ? '0' + h : h;\n\t\n\tif (s !== time.s) {\n\t\tfor (let i = 0; i &lt; digits.length; i++) {\n\t\t\tlet d = digits[i];\n\t\t\tif (i === +s) {\n\t\t\t\td.classList.add('second');\n\t\t\t\tif (time.p !== null)\n\t\t\t\t\tdigits[time.p].classList.remove('second');\n\t\t\t\ttime.p = i;\n\t\t\t\ttime.s = s;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tif (m !== time.m) {\n\t\tsetNum(blocks[2], m[0]);\n\t\tsetNum(blocks[3], m[1]);\n\t\ttime.m = m;\n\t}\n\t\n\tif (h !== time.h) {\n\t\tsetNum(blocks[0], h[0]);\n\t\tsetNum(blocks[1], h[1]);\n\t\ttime.h = h;\n\t}\n \twindow.requestAnimationFrame(animator)\n}\n\n\/\/ init\nwindow.requestAnimationFrame(animator)\n\n\/\/ toggle button\n\nconst body = document.querySelector('body');\nchangeTheme = ev =&gt; {\n\tbody.classList.toggle('light-theme');\n};<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":1431,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[79],"class_list":["post-1430","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other","tag-clock"],"_links":{"self":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/1430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/comments?post=1430"}],"version-history":[{"count":2,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/1430\/revisions"}],"predecessor-version":[{"id":1441,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/1430\/revisions\/1441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/media\/1431"}],"wp:attachment":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/media?parent=1430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/categories?post=1430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/tags?post=1430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}