ニジカもんすたぁ!! トップ・ページ https://nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 lines
1.1 KiB

  1. class
  2. Talk
  3. {
  4. static
  5. main ()
  6. {
  7. const canvas = new Canvas;
  8. setInterval (() => canvas.resize (), 100);
  9. }
  10. }
  11. class
  12. Canvas
  13. {
  14. constructor ()
  15. {
  16. this.canvas = $ ('#canvas');
  17. this.ctx = this.canvas[0].getContext ('2d');
  18. this.bg = new Image ();
  19. this.bg.src = './assets/bg.jpg';
  20. this.bg.onload = () => this.resize ();
  21. }
  22. resize ()
  23. {
  24. this.canvas.width ($ (window).width ());
  25. this.canvas.height ($ (window).height ());
  26. this.redraw ();
  27. }
  28. redraw ()
  29. {
  30. this.putBG (this.canvas.width (), this.canvas.height ());
  31. }
  32. putBG (sizeX, sizeY)
  33. {
  34. const width = this.bg.width;
  35. const height = this.bg.height;
  36. const vertical = sizeY / sizeX > height / width;
  37. console.log (sizeX, sizeY, width, height);
  38. const zoom = vertical ? (sizeX / width) : (sizeY / height);
  39. const x = vertical ? 0 : ((sizeX - width * zoom) / 2);
  40. const y = vertical ? ((sizeY - height * zoom) / 2) : 0;
  41. this.ctx.drawImage (this.bg,
  42. 0, 0, width, height,
  43. x, y, width, height);
  44. }
  45. }
  46. Talk.main ();