sketch.js 2.4 KB

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