<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; JS: Цифровые часы (HTML5)]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=8789</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8789&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «JS: Цифровые часы (HTML5)».]]></description>
		<lastBuildDate>Sat, 08 Mar 2014 05:37:29 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=80598#p80598</link>
			<description><![CDATA[<p><strong>ufopera</strong><br /></p><div class="codebox"><pre><code>    backColor: &#039;transparent&#039;, // цвет фона</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (shiz)]]></author>
			<pubDate>Sat, 08 Mar 2014 05:37:29 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=80598#p80598</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=80597#p80597</link>
			<description><![CDATA[<p>А как прозрачный фон сделать для этих часов ( DigitalClock ) ?</p>]]></description>
			<author><![CDATA[null@example.com (ufopera)]]></author>
			<pubDate>Sat, 08 Mar 2014 02:54:21 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=80597#p80597</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76518#p76518</link>
			<description><![CDATA[<p>Еще одна <a href="http://snapsvg.io/">ссылка</a> по теме - JavaScript библиотека SVG.</p>]]></description>
			<author><![CDATA[null@example.com (dab00)]]></author>
			<pubDate>Sun, 27 Oct 2013 05:41:09 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76518#p76518</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76297#p76297</link>
			<description><![CDATA[<p>off: Коммерсы считают денежки, а &quot;оптимизировано&quot; вы решили или &quot;компактно&quot; - им <a href="http://www.youtube.com/watch?v=mhofVKGZIyI">параллельно</a> (кто не смотрел - рекомендую - не пожалеете <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />).<br />Работали иначе? Повезло, мне не случалось.<br />Не вижу ничего предосудительного в том, чтобы использовать фреймворки и прочие полуфабрикаты, сокращает: количество &quot;бутылок&quot;, времени, &quot;непечатных слов&quot; и т.п.<br />По <a href="https://www.google.ru/search?q=html5+canvas+clock">запросу в Google</a> понравились варианты часов (и не только) <a href="http://techslides.com/learning-html5-canvas-through-jsfiddle-examples/">здесь</a>. По-моему классная подборка.<br />Всем мир <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />.</p>]]></description>
			<author><![CDATA[null@example.com (dab00)]]></author>
			<pubDate>Mon, 21 Oct 2013 17:06:25 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76297#p76297</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76239#p76239</link>
			<description><![CDATA[<div class="quotebox"><cite>dab00 пишет:</cite><blockquote><p>Есть же js-фреймворки...</p></blockquote></div><p>Да полно! ВотЪ только смысл брать за основу чужие ошибки и на них возводить что-то? Понимаю, если время не терпит и заказчик некого проекта грозит словами непечатными, тогда шиш с ним. Так что <strong>Arigato</strong> больше заслуживает похвалы за проделанный труд.<br /></p><div class="quotebox"><cite>Arigato пишет:</cite><blockquote><p>В FF наблюдаются проблемы со сглаживанием секундной стрелки.</p></blockquote></div><p>FF довольно капризный интернет обозреватель.</p>]]></description>
			<author><![CDATA[null@example.com (greg zakharov)]]></author>
			<pubDate>Mon, 21 Oct 2013 07:41:16 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76239#p76239</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76190#p76190</link>
			<description><![CDATA[<div class="quotebox"><cite>greg zakharov пишет:</cite><blockquote><p>Помнится писал я про аналоговые часы.</p></blockquote></div><p>В FF наблюдаются проблемы со сглаживанием секундной стрелки.</p>]]></description>
			<author><![CDATA[null@example.com (Arigato)]]></author>
			<pubDate>Sun, 20 Oct 2013 13:50:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76190#p76190</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76184#p76184</link>
			<description><![CDATA[<p>Есть же js-фреймворки, использование которых может сократить количество &quot;бутылок&quot;, например&nbsp; <a href="http://kineticjs.com/">KineticJS</a>, <a href="http://threejs.org/">Three.js</a> (этот не пробовал - слишком для меня) и пр.</p>]]></description>
			<author><![CDATA[null@example.com (dab00)]]></author>
			<pubDate>Sun, 20 Oct 2013 13:20:46 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76184#p76184</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76172#p76172</link>
			<description><![CDATA[<p>Canvas вообще-то довольно мощная штука, но не без недостатков: написать код без бутылки, а то и двух порой довольно сложно, если речь заходит о коде оптимизированном и компактном. Тем паче, что HTML5 крашен не только canvas, но и другими вещами, скажем, svg, который в купе с javascript делает код гораздо проще и читабельней. Помнится писал я про аналоговые часы (<em><a href="http://code.activestate.com/recipes/578686-analog-clock/?in=user-4184115">см. здесь</a></em>), после - цифровые. В обоих случаях svg сводит к минимуму написание кода на javascript.</p>]]></description>
			<author><![CDATA[null@example.com (greg zakharov)]]></author>
			<pubDate>Sun, 20 Oct 2013 07:57:39 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76172#p76172</guid>
		</item>
		<item>
			<title><![CDATA[JS: Цифровые часы (HTML5)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76167#p76167</link>
			<description><![CDATA[<p>Отрисовывает цифровые часы по размерам канвы. Имеется возможность менять некоторые настройки (цвета и прочее).</p><p><span class="postimg"><img src="http://s020.radikal.ru/i723/1310/a3/3cfbe8e35891.png" alt="http://s020.radikal.ru/i723/1310/a3/3cfbe8e35891.png" /></span></p><p>Код скрипта:</p><div class="codebox"><pre><code>/*

    Copyright 2013 Arigato Software

    Скрипт цифровых часов на Canvas
    
    Взято с http://programmersforum.ru/showthread.php?t=245008

*/

var DigitalClock = {
    
    // Параметры часов
    backColor: &#039;#000&#039;, // цвет фона
    darkColor: &#039;#010&#039;, // цвет выключенного элемента
    lightColor: &#039;#0F0&#039;, // цвет включенного элемента
    lineWidth: 24, // толщина линий
    lineLength: 100, // длина линий
    
    /*
         -     0
        | |   1 2
         -     3
        | |   4 5
         -     6
    */
    digits: [
        [1,1,1,0,1,1,1], // 0
        [0,0,1,0,0,1,0], // 1
        [1,0,1,1,1,0,1], // 2
        [1,0,1,1,0,1,1], // 3
        [0,1,1,1,0,1,0], // 4
        [1,1,0,1,0,1,1], // 5
        [1,1,0,1,1,1,1], // 6
        [1,0,1,0,0,1,0], // 7
        [1,1,1,1,1,1,1], // 8
        [1,1,1,1,0,1,1]  // 9
    ],
    
    // Запуск часов
    start: function(canvasId) {
        var canvas = document.getElementById(canvasId);
        if ( canvas.getContext ) {
            var context = canvas.getContext(&#039;2d&#039;);
            this.context = context;
            var xScale = canvas.width / this.offset(18, 4);
            var yScale = canvas.height / this.offset(4, 2);
            context.scale(xScale, yScale);
            this.tick();
            setInterval(function(){DigitalClock.tick()}, 1000);
        }
    },
    
    // Получить цвет элемента
    getColor: function(bool) {
        return ( bool ) ? this.lightColor : this.darkColor;
    },
    
    // Рассчитать смещение элемента
    offset: function(countWidth, countLength) {
        return countWidth * this.lineWidth + countLength * this.lineLength;
    },
    
    // Отображение цифры на канве
    drawDigit: function(x, y, digit) {
        var ctx = this.context;
        
        ctx.save();
        ctx.translate(x, y);
        ctx.lineWidth = this.lineWidth;
        ctx.lineCap = &#039;round&#039;;
        
        // рисуем горизонтальные линии
        for (var i = 0; i &lt; 3; i++) {
            var y = i * this.offset(1, 1);
            ctx.beginPath();
            ctx.strokeStyle = this.getColor(this.digits[digit][i*3]);
            ctx.moveTo(this.offset(1, 0), y);
            ctx.lineTo(this.offset(0, 1), y);
            ctx.stroke();
        }
        
        // рисуем вертикальные линии
        for (var j = 0; j &lt; 2; j++) {
            var y = j * this.offset(1, 1);
            for (var i = 0; i &lt; 2; i++) {
                var x = i * this.offset(1, 1);
                ctx.beginPath();
                ctx.strokeStyle = this.getColor(this.digits[digit][1+j*3+i]);
                ctx.moveTo(x, y + this.offset(1, 0));
                ctx.lineTo(x, y + this.offset(0, 1));
                ctx.stroke();
            }
        }
        
        ctx.restore();
    },
    
    // Отображение числа на канве
    drawNumber: function(x, y, number, digits) {
        x += this.offset(4, 1) * (digits - 1);
        for ( ; digits--; ) {
            this.drawDigit(x, y, number % 10);
            number = Math.floor(number / 10);
            x -= this.offset(4, 1);
        }
    },
    
    // Отрисовка часов
    tick: function() {
        // получаем текущее время
        var now = new Date();
        var hr = now.getHours();
        var mn = now.getMinutes();
        var sc = now.getSeconds();
        
        // выводим на канву
        this.context.fillStyle = this.backColor;
        this.context.fillRect(0, 0, this.offset(18, 4), this.offset(4, 2));
        this.drawNumber(this.offset(1, 0), this.offset(1, 0), hr, 2);
        this.drawNumber(this.offset(12, 2), this.offset(1, 0), mn, 2);
        
        // рисуем точки
        this.context.beginPath();
        this.context.arc(this.offset(9, 2), this.offset(1.5, 0.5), this.lineWidth, 0, 2 * Math.PI, true);
        this.context.arc(this.offset(9, 2), this.offset(2.5, 1.5), this.lineWidth, 0, 2 * Math.PI, true);
        this.context.fillStyle = this.getColor(sc % 2);
        this.context.strokeStyle = this.backColor;
        this.context.lineWidth = 1;
        this.context.fill();
        this.context.stroke();
    }
    
};</code></pre></div><p>Готовый пример в аттаче.</p>]]></description>
			<author><![CDATA[null@example.com (Arigato)]]></author>
			<pubDate>Sat, 19 Oct 2013 20:14:48 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76167#p76167</guid>
		</item>
	</channel>
</rss>
