freealise commited on
Commit
d78ecb0
1 Parent(s): f9b1af2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -361,13 +361,23 @@ with gr.Blocks(css=css) as demo:
361
  pts += i+\",\"+parseInt(Math.sin(i/256*Math.PI/2)*15)+\" \";
362
  }
363
  document.getElementById(\"pl\").setAttribute(\"points\", pts.slice(0,-1));
 
 
 
 
364
  this.onpointermove = function(event) {
365
- if (this.title == \"Pointer down\") {
366
  var x = parseInt(event.clientX - event.target.getBoundingClientRect().x);
367
  var y = parseInt(event.clientY - event.target.getBoundingClientRect().y);
368
  if (x < 0) { x = 0; } else if (x > 255) { x = 255; }
369
  if (y < 0) { y = 0; } else if (y > 31) { y = 31; }
370
  var pl_a = document.getElementById(\"pl\").getAttribute(\"points\").split(\" \");
 
 
 
 
 
 
371
  pl_a[x] = x+\",\"+y;
372
  document.getElementById(\"pl\").setAttribute(\"points\", pl_a.join(\" \"));
373
  }
@@ -381,11 +391,11 @@ with gr.Blocks(css=css) as demo:
381
  var evt = document.createEvent(\"Event\");
382
  evt.initEvent(\"input\", true, false);
383
  document.getElementsByTagName(\"textarea\")[1].dispatchEvent(evt);
384
- this.title = \"Pointer up\";
385
  }
386
  this.onpointerleave = this.onpointerup;
387
  }
388
- this.title = \"Pointer down\";
389
  }catch(e){alert(e);}
390
  '>
391
  <defs>
 
361
  pts += i+\",\"+parseInt(Math.sin(i/256*Math.PI/2)*15)+\" \";
362
  }
363
  document.getElementById(\"pl\").setAttribute(\"points\", pts.slice(0,-1));
364
+ var xold = 0;
365
+ var yold = 0;
366
+ function lerp(y1, y2, mu) { return y1*(1-mu)+y2*mu; }
367
+
368
  this.onpointermove = function(event) {
369
+ if (this.title != \"\") {
370
  var x = parseInt(event.clientX - event.target.getBoundingClientRect().x);
371
  var y = parseInt(event.clientY - event.target.getBoundingClientRect().y);
372
  if (x < 0) { x = 0; } else if (x > 255) { x = 255; }
373
  if (y < 0) { y = 0; } else if (y > 31) { y = 31; }
374
  var pl_a = document.getElementById(\"pl\").getAttribute(\"points\").split(\" \");
375
+
376
+ var minx = Math.min(xold, x);
377
+ var maxx = Math.max(xold, x);
378
+ for (var i=minx+1; i<maxx; i++) {
379
+ pl_a[i] = x+\",\"+parseInt(lerp( yold, y, (i-minx)/(maxx-minx) ));
380
+ }
381
  pl_a[x] = x+\",\"+y;
382
  document.getElementById(\"pl\").setAttribute(\"points\", pl_a.join(\" \"));
383
  }
 
391
  var evt = document.createEvent(\"Event\");
392
  evt.initEvent(\"input\", true, false);
393
  document.getElementsByTagName(\"textarea\")[1].dispatchEvent(evt);
394
+ this.title = \"\";
395
  }
396
  this.onpointerleave = this.onpointerup;
397
  }
398
+ this.title = xold+\",\"+yold;
399
  }catch(e){alert(e);}
400
  '>
401
  <defs>