sketch.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var _mgr;
  2. var _w,_h;
  3. var poi01 = {
  4. x: 252,
  5. y: 144,
  6. id: "Poi01",
  7. img: null,
  8. _img: null,
  9. area: function(){
  10. let square = {
  11. x1: this.x+random(-1, 1),
  12. y1: this.y+random(-1, 1),
  13. x2: this.x-7+random(-1, 1),
  14. y2: this.y+7+random(-1, 1),
  15. x3: this.x+7+random(-1, 1),
  16. y3: this.y+7+random(-1, 1)
  17. }
  18. let delta=0;
  19. if(mouseX >= square.x2 && mouseX <= square.x3 && mouseY >= square.y1 && mouseY <= square.y3){
  20. delta = delta + 5;
  21. }
  22. square.y1-=delta;
  23. square.x2-=delta;
  24. square.y2+=delta;
  25. square.x3+=delta;
  26. square.y3+=delta;
  27. return square;
  28. },
  29. pin: function(){
  30. let square = this.area();
  31. if(this.overMe()){
  32. return image(this._img, square.x1,square.y1 );
  33. }
  34. return image(this.img, square.x1,square.y1 );
  35. },
  36. adapt: function(){
  37. // this.img.resize(20, 20);
  38. //this._img= Object.assign({},this.img));
  39. //this._img.resize(50, 50);
  40. },
  41. setIcon: function(filename){
  42. //small
  43. this.img=loadImage(filename,
  44. function(img){
  45. img.resize(20,20);
  46. });
  47. //big
  48. this._img=loadImage(filename,
  49. function(img){
  50. img.resize(50,50);
  51. });
  52. },
  53. overMe: function(){
  54. let square = this.area();
  55. return (mouseX >= square.x1 && mouseX <= (square.x1+this.img.width) && mouseY >= square.y1 && mouseY <= (square.y1+this.img.height));
  56. }
  57. };
  58. var pois=[];
  59. function setup()
  60. {
  61. createCanvas(600, 500);
  62. console.log("STARTED");
  63. var poi=Object.create(poi01);
  64. poi.x= 346;
  65. poi.y= 332;
  66. poi.id="First One";
  67. poi.setIcon('icona_testo.png');
  68. pois.push(poi);
  69. poi=Object.create(poi01);
  70. poi.x= 746;
  71. poi.y= 432;
  72. poi.id="Two";
  73. poi.setIcon('icona_testo.png');
  74. pois.push(poi);
  75. _mgr = new SceneManager();
  76. _w = 1270
  77. _h = 520
  78. // Preload scenes. Preloading is normally optional
  79. // ... but needed if showNextScene() is used.
  80. _mgr.addScene ( Screensaver );
  81. _mgr.addScene ( River );
  82. console.log("Try to display screensaver");
  83. _mgr.showScene(Screensaver);
  84. }
  85. function draw()
  86. {
  87. _mgr.draw();
  88. }
  89. function mousePressed()
  90. {
  91. _mgr.handleEvent("mousePressed");
  92. }
  93. function mouseClicked()
  94. {
  95. _mgr.handleEvent("mouseClicked");
  96. }