lsc 3 éve
szülő
commit
0d272ca4de
3 módosított fájl, 64 hozzáadás és 15 törlés
  1. 2 2
      src/components/blockly.vue
  2. 1 1
      src/components/fan.vue
  3. 61 12
      src/components/functionFan.vue

+ 2 - 2
src/components/blockly.vue

@@ -86,7 +86,7 @@ export default {
     return {
       that: this,
       workspace: null,
-      type: this.$route.query.type,
+      type: this.$route.query.typeN,
     };
   },
 
@@ -94,7 +94,7 @@ export default {
     // 代码生成器
     myUpdateFunction(event) {
       var code = Blockly.JavaScript.workspaceToCode(this.workspace);
-            debugger;
+            // debugger;
       return code;
     },
     // 获取blockly工作区中的code和xml结构

+ 1 - 1
src/components/fan.vue

@@ -505,7 +505,7 @@ export default {
   },
   methods: {
     go() {
-      this.$router.push("/blockly?type=fan");
+      this.$router.push("/blockly?typeN=fan");
     },
     setPan(value) {
       this.panThing = value;

+ 61 - 12
src/components/functionFan.vue

@@ -195,7 +195,7 @@ export default {
       timer: null,
       detector: null,
       hand: 0,
-      isC:false,
+      isC: false,
     };
   },
   methods: {
@@ -209,16 +209,25 @@ export default {
       }
     },
     start() {
-      if(!this.isC){
+      if (!this.isC) {
         return;
       }
+
+      var a = this.$store.state.function
+        .replace(/\ +/g, "")
+        .replace(/[\r\n]/g, "")
+        .replace("screen=1;", "");
+      if (a.indexOf("while") != 0) {
+        return;
+      }
+      console.log(a);
       this.isZuan = true;
       this.isCamera = true;
       let video = this.$refs["video"];
       setInterval(() => {
-      this.handsFind(video);
+        this.handsFind(video);
 
-      // window.requestAnimationFrame(this.start);
+        // window.requestAnimationFrame(this.start);
       }, 1000);
     },
     zhuan(num) {
@@ -261,27 +270,69 @@ export default {
         let _1316y = handsA[13].y / handsA[16].y;
         let _1720y = handsA[17].y / handsA[20].y;
 
+        var a = this.$store.state.function
+          .replace(/\ +/g, "")
+          .replace(/[\r\n]/g, "")
+          .replace("screen=1;");
+        var array = a.split("if");
+        array.splice(0, 1);
+        /*石头剪刀布的转速 */
+        let buNum = 0;
+        let sNum = 0;
+        let jNum = 0;
+        /**1布2石头3剪刀 */
+        for (var i in array) {
+          if (array[i].indexOf("==(1)") != -1) {
+            buNum = parseInt(array[i].split("motor=")[1].split("}")[0]);
+          }
+          if (array[i].indexOf("==(2)") != -1) {
+            sNum = parseInt(array[i].split("motor=")[1].split("}")[0]);
+          }
+          if (array[i].indexOf("==(3)") != -1) {
+            jNum = parseInt(array[i].split("motor=")[1].split("}")[0]);
+          }
+        }
+
         if (_58y > 1 && _912y > 1 && _1316y > 1 && _1720y > 1) {
           console.log("布");
           if (this.hand == 1) {
             return;
           }
           this.hand = 1;
-          this.zhuan(20);
+          if (this.timer) {
+            clearInterval(this.timer);
+            this.timer = null;
+            this.zhuan(buNum);
+          } else {
+            this.zhuan(buNum);
+          }
         } else if (_58y < 1 && _912y < 1 && _1316y < 1 && _1720y < 1) {
           console.log("石头");
           if (this.hand == 2) {
             return;
           }
           this.hand = 2;
-          this.zhuan(0);
+          if (this.timer) {
+            clearInterval(this.timer);
+            this.timer = null;
+            this.zhuan(sNum);
+          } else {
+            this.zhuan(sNum);
+          }
         } else if (_58y > 1 && _912y > 1 && _1316y < 1 && _1720y < 1) {
           console.log("剪刀");
           if (this.hand == 3) {
             return;
           }
           this.hand = 3;
-          this.zhuan(20);
+
+          if (this.timer) {
+            clearInterval(this.timer);
+            this.timer = null;
+            this.zhuan(jNum);
+          } else {
+            this.zhuan(jNum);
+          }
         }
       }
     },
@@ -301,7 +352,7 @@ export default {
         })
         .catch((error) => {
           // console.error("摄像头开启失败,请检查摄像头是否可用!");
-          _this.isC = false
+          _this.isC = false;
           _this.$message.error("摄像头开启失败,请检查摄像头是否可用!");
         });
     },
@@ -348,7 +399,6 @@ export default {
     },
 
     async fnInit() {
-      // debugger;
       const model = handPoseDetection.SupportedModels.MediaPipeHands;
       const detectorConfig = {
         runtime: "mediapipe", // or 'tfjs'
@@ -356,15 +406,14 @@ export default {
         // solutionPath: `https://cdn.jsdelivr.net/npm/@mediapipe/hands@${mpHands.VERSION}`,
         solutionPath: `/static/hands`,
       };
-      // debugger;
       this.detector = await handPoseDetection.createDetector(
         model,
         detectorConfig
       );
-      if (this.$store.state.function.indexOf("screen=1;") != -1) {
+      if (this.$store.state.function.indexOf("screen=1;") == 0) {
         this.callCamera();
         this.isC = true;
-      }else{
+      } else {
         this.isC = false;
       }
     },