Показать сообщение отдельно
  #2 (permalink)  
Старый 30.06.2018, 20:15
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,074

Sevic,
строки 38 и 58
<!doctype html>
<html>
<head>
 <meta charset="utf-8" />
 <title>...</title>

</head>
<body>

 <script type="text/javascript">

   var canvas = document.createElement('canvas');
   canvas.id = 'canvas';
   canvas.style.border = 'double black 4px';
   document.body.appendChild(canvas)

   var cnvWidth = canvas.width = window.innerWidth-30;
   var cnvHeight = canvas.height = window.innerHeight-30;

   var ctx = canvas.getContext('2d');

   function Shkale(c, x) {

     var self = this;
     this.x = x;

     Shkale.prototype.gorLine = function() {

       c.beginPath();
       c.strokeStyle = '#396';
       c.moveTo(0, cnvHeight/2);
       c.lineTo(cnvWidth, cnvHeight/2);
       c.stroke();

     };

     Shkale.prototype.verLine = function() {
       for (var i = 0; i < cnvWidth +45; i += 45) {
         c.beginPath();
         c.strokeStyle = '#00f';
         c.moveTo(this.x + i, cnvHeight/2 - 50);
         c.lineTo(this.x + i, cnvHeight/2 + 50);
         c.stroke();
       }
     };

   };

   var shkale = new Shkale(ctx, 50);

   function move() {
     ctx.clearRect(0, 0, cnvWidth, cnvHeight);
     shkale.gorLine();
     shkale.verLine();
     shkale.x -= 2;

   if (shkale.x < 0) {
      shkale.x = 45
    };

     requestAnimationFrame(move);
     console.log(shkale.x);
   };

   move();

 </script>
</body>
</html>
Ответить с цитированием