paint-by-numbers

Relaxing paint-by-numbers game  https://p.ce9e.org/paint-by-numbers/
git clone https://git.ce9e.org/paint-by-numbers.git

commit
26194502cfe09dc99d20293cbeb3cd763a700614
parent
ece7fb8f35c7a821aba30ac1d76c4786d6e72ddf
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-02-12 17:42
throttle onClick

Diffstat

M paint.js 8 ++++----

1 files changed, 4 insertions, 4 deletions


diff --git a/paint.js b/paint.js

@@ -41,11 +41,11 @@ var makeContrast = function(a) {
   41    41 
   42    42 var onAnimation = function(fn) {
   43    43     var called = false;
   44    -1     return () => {
   -1    44     return (...args) => {
   45    45         if (!called) {
   46    46             called = true;
   47    47             window.requestAnimationFrame(() => {
   48    -1                 fn();
   -1    48                 fn(...args);
   49    49                 called = false;
   50    50             });
   51    51         }
@@ -230,7 +230,7 @@ var drawLine = function(x1, y1, x2, y2, color) {
  230   230 
  231   231 var last_click = null;
  232   232 
  233    -1 var onClick = function(event) {
   -1   233 var onClick = onAnimation(function(event) {
  234   234     if (event.buttons & 1) {
  235   235         var rect = canvas.getBoundingClientRect();
  236   236         var cx = event.clientX - rect.x;
@@ -250,7 +250,7 @@ var onClick = function(event) {
  250   250     } else {
  251   251         last_click = null;
  252   252     }
  253    -1 };
   -1   253 });
  254   254 
  255   255 window.addEventListener('mousemove', onClick);
  256   256 window.addEventListener('mousedown', onClick);