function7.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. function FingerComponent(obj_list,sync_obj,canvas){
  2. //alert("!!!");
  3. this.TRANSFORM_PREFIXED = this.getVendorPrefixed(["transform", "msTransform", "MozTransform", "webkitTransform", "OTransform"]);
  4. this.canvas=canvas;
  5. //alert("!!!!");
  6. this.boxList = [];
  7. this.car = this.assignBox(sync_obj);
  8. this.car["beginRun"]=false;
  9. this.car["newStage"]=0;
  10. this.car["yforLine"]=[0];
  11. this.car["dragDeg"]=[];
  12. this.boxList.push(this.car);
  13. for(var i = 0,objId;objId=obj_list[i];i++){
  14. var temp = this.assignBox(objId);
  15. this.boxList.push(temp);
  16. this.listen(temp);
  17. }
  18. this.arrow=this.boxList[1];
  19. var _this=this;
  20. var loop=function(){
  21. _this.moveCar();
  22. for(var i=0; i<_this.boxList.length; i++) {
  23. _this.transform(_this.boxList[i]);
  24. }
  25. requestAnimationFrame(loop);
  26. };
  27. loop();
  28. this.loop=loop;
  29. }
  30. FingerComponent.prototype.moveCar=function() {
  31. if(this.car.beginRun){
  32. var xMargin=[0,430,640,0,0];
  33. var maxStage= 9; //¨F­±
  34. var step=1; //¦æ¶i³t«×
  35. var ctx = this.canvas.getContext("2d");
  36. //ctx.moveTo(xMargin[this.car.newStage-1],this.car.yforLine[this.car.newStage-1]);
  37. ctx.lineTo(this.car.x+30,this.car.y-10);
  38. ctx.lineWidth = 5;
  39. ctx.lineLength = 6;
  40. ctx.strokeStyle = "red";
  41. ctx.stroke();
  42. this.car.isUpdated = true;
  43. if(this.car.x==212){
  44. //console.log("!!!");
  45. var tol=5e-1;
  46. if(this.car.rad < this.arrow.rad && this.arrow.rad-this.car.rad>=tol){
  47. this.car.rad += 0.2;
  48. return;
  49. }
  50. else if(this.car.rad > this.arrow.rad && this.car.rad-this.arrow.rad>=tol){
  51. this.car.rad -= 0.2;
  52. return;
  53. }
  54. /*else{
  55. }*/
  56. }
  57. if(this.car.x>212)
  58. step=0.5;
  59. var deltay=step*Math.tan(this.car.rad*Math.PI/180); //¦æ¶i¨¤«×
  60. this.car.x+=step;
  61. this.car.y+=deltay;
  62. //this.car.style.transformOrigin="20% 40%";
  63. if(this.car.x>=xMargin[this.car.newStage]){
  64. this.car.beginRun=false;
  65. this.car.yforLine.push(this.car.y);
  66. var $normal_line=$("#normal-line").clone().attr("id","");//.css("left","0px");
  67. var left=(this.car.x-70);
  68. var carWidth=10;
  69. var carHeight=50;
  70. var top=this.car.y+((carHeight/3)/Math.tan(this.car.rad*Math.PI/850)+carWidth)*Math.sin(this.car.rad*Math.PI/180);
  71. var style="position:absolute;left:"+left+"px;top:"+top+"px;";
  72. this.arrow.x=this.car.x;
  73. this.arrow.y=this.car.y;
  74. //this.arrow.isUpdated=true;
  75. saveRecordr(0,this.car.x,0,0,0);
  76. saveRecordr(0,0,this.car.y,0,0);
  77. if(this.car.x == 430 && this.car.y >= 100 && this.car.y<=350){
  78. this.arrow.element.className="arrow-begin hidden";
  79. var _this=this;
  80. check.style.display = "inline";
  81. check.style.top = 650;
  82. check.style.left = 500;
  83. saveRecord(250);
  84. saveRecord(100);
  85. setTimeout(
  86. function(){
  87. correct.style.display = "inline";
  88. correct.style.top = 650;
  89. correct.style.left = 500;
  90. next.style.display = "inline";
  91. next.style.top =600;
  92. next.style.left = 750;
  93. back.style.display = "inline";
  94. back.style.top =600;
  95. back.style.left = 630;
  96. next.setAttribute("data-url","406A.php?correct=true&x="+_this.car.x+"&y="+_this.car.y+"&rad="+_this.car.rad);
  97. }
  98. ,3000);
  99. }
  100. if(this.car.x == 430 && this.car.y < 100 || this.car.y >351){
  101. this.arrow.element.className="arrow-begin hidden";
  102. check.style.display = "inline";
  103. check.style.top = 650;
  104. check.style.left = 500;
  105. saveRecord(250);
  106. saveRecord(200);
  107. setTimeout(
  108. function(){
  109. wrong.style.display = "inline";
  110. wrong.style.top = 650;
  111. wrong.style.left = 500;
  112. next.style.display = "inline";
  113. next.style.top =600;
  114. next.style.left = 750;
  115. back.style.display = "inline";
  116. back.style.top =600;
  117. back.style.left = 630;
  118. }
  119. ,3000)
  120. }
  121. }
  122. else{
  123. this.arrow.element.className="arrow-begin hidden";
  124. }
  125. }
  126. }
  127. function nextPage(code,url){
  128. saveRecord(code);
  129. setTimeout(1500,location.replace(url));
  130. }
  131. function dragPic(){
  132. dragTime = Math.floor(Date.now() / 1000);
  133. }
  134. FingerComponent.prototype.checkRes=function() {
  135. document.getElementById("Answer1").style.display="inline";
  136. }
  137. FingerComponent.prototype.assignBox=function(picS) {
  138. var pic = document.getElementById(picS);
  139. //console.log(pic);
  140. return {
  141. element: pic,
  142. isUpdated: true,
  143. x: 120,//Math.random() * (window.innerWidth - 200),
  144. y: 50,//Math.random() * (window.innerHeight - 300),
  145. rad: 45,//Math.random()*Math.PI * 2,
  146. scale: 1,
  147. rafId: 0,
  148. zIndex: 0,
  149. degx: 0,
  150. degy: 0
  151. }
  152. }
  153. FingerComponent.prototype.listen=function(pBoxO) {
  154. var finger = new Fingers(pBoxO.element);
  155. var flag=false;
  156. var _this=this;
  157. finger.addGesture(Fingers.gesture.Drag, null).addHandler(function(pEventType, pData, pFingers) {
  158. if(pEventType === Fingers.Gesture.EVENT_TYPE.move) {
  159. var x=pFingers[0].getDeltaX();
  160. var y=pFingers[0].getDeltaY();
  161. var temp=pBoxO.rad+y/3;
  162. if(temp>=0 && temp<=55)
  163. pBoxO.rad = temp;
  164. //_this.arrow.rad = pBoxO.rad;
  165. //_this.arrow.isUpdated=true
  166. //_this.car.isUpdated=true
  167. pBoxO.isUpdated = true;
  168. }
  169. else if(pEventType === Fingers.Gesture.EVENT_TYPE.end) {
  170. //pBoxO.element.className+=" hidden";
  171. _this.car.dragDeg.push(_this.car.rad);
  172. _this.car.beginRun=true;
  173. _this.car.newStage++;
  174. _this.car.lastRad=_this.car.rad;
  175. }
  176. });
  177. pBoxO.fingers = finger ;
  178. }
  179. FingerComponent.prototype.transform=function(pBoxO) {
  180. if(pBoxO.isUpdated) {
  181. pBoxO.element.style[this.TRANSFORM_PREFIXED] = "translateZ(0) " +
  182. "translate(" + pBoxO.x + "px, " + pBoxO.y + "px) " +
  183. "scale(" + pBoxO.scale + ") " +//+ "rotate3d(0,0,0," + pBoxO.rad + "rad) ";
  184. "rotate(" + pBoxO.rad + "deg) ";
  185. pBoxO.element.style.zIndex = pBoxO.zIndex;
  186. pBoxO.isUpdated = false;
  187. }
  188. }
  189. FingerComponent.prototype.getVendorPrefixed=function(pArrayOfPrefixes) {
  190. var result = null;
  191. for (var i=0; i<pArrayOfPrefixes.length; i++) {
  192. if (document.body.style[pArrayOfPrefixes[i]] !== undefined) {
  193. result = pArrayOfPrefixes[i];
  194. break;
  195. }
  196. }
  197. return result;
  198. }
  199. function saveRecord(code){
  200. xmlhttp = new XMLHttpRequest();
  201. xmlhttp.onreadystatechange = function() {
  202. if (xmlhttp.readyState==4) {
  203. if(xmlhttp.status==200) {
  204. xmlhttp.abort();
  205. }
  206. }
  207. };
  208. xmlhttp.open("POST","saveRecord.php",true);
  209. xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  210. xmlhttp.send("codenum=" + code + "&time=" + Math.floor(Date.now() / 1000));
  211. }
  212. function saveRecords(code,time){
  213. xmlhttp = new XMLHttpRequest();
  214. xmlhttp.onreadystatechange = function() {
  215. if (xmlhttp.readyState==4) {
  216. if(xmlhttp.status==200) {
  217. xmlhttp.abort();
  218. }
  219. }
  220. };
  221. xmlhttp.open("POST","saveRecord.php",true);
  222. xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  223. xmlhttp.send("codenum=" + code + "&dragtime=" + time);
  224. }
  225. function saveRecordr(code,rotX,rotY,rotZ,rotS){
  226. xmlhttp = new XMLHttpRequest();
  227. xmlhttp.onreadystatechange = function() {
  228. if (xmlhttp.readyState==4) {
  229. if(xmlhttp.status==200) {
  230. xmlhttp.abort();
  231. }
  232. }
  233. };
  234. xmlhttp.open("POST","saveRecord.php",true);
  235. xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  236. xmlhttp.send("codenum=" + code + "&time=" + Math.floor(Date.now() / 1000) + "&rotx="+rotX+"&roty="+rotY+"&rotz="+rotZ+"&scale="+rotS);
  237. }