Interactive Erotic Toy Code - Processing

This is a code for 8051 chip, which you have to use "keilC" to compile it. There might be some omissions in the code due to the error of web past function. Please go to this page to get the full code. 

import processing.serial.*;

Serial port;

float val,oldVal,X,Y,Z,gap=12.5,zeroPoint=4000,delta,mapDelta;

byte[] inPackage=new byte[5];

void setup(){

  size(800,600); 

//frameRate(30);

  smooth();

  String ArdPort = Serial.list()[0]; 

port = new Serial(this, ArdPort, 9600); 

background(148,164,219);

  PFont font;  font = loadFont("Arial-BoldMT-48.vlw");

  textFont(font,48);  textAlign(CENTER);

}    

void draw(){

  pushMatrix();

  translate(200,0);

  strokeWeight(5);

  textSize(48);

  fill(0);

  text("Z",300,90);

  text("Y",540,500);

  text("X",60,500);

  textSize(24);

  text("Motion",-125,500); 

text("Magnitude",-70,530);

  text("Max",-40,110);

  text("0",-60,480);

    text("1G",335,232);

  fill(148,164,219,100);

  rect(25,25,550,550);

  rect(-175,25,175,550);

  if(port.available()>4){

    inPackage=port.readBytes();

    if(inPackage[0]==99&&inPackage[4]==-32){

      port.clear();

      X=abs(inPackage[1]);

      Y=abs(inPackage[2]);

      Z=abs(inPackage[3]);

      X=map(X,0,255,0,450);

      Y=map(Y,0,255,0,450);

      Z=map(Z,0,255,0,450);

      val=sq(inPackage[1])+sq(inPackage[2])+sq(inPackage[3]);

      val=sqrt(val);

      println("val="+val);

      for(int i=0; i<=4; i++){

          switch(i){

          case 0: println("Start="+inPackage[0]);break;

          case 1: print("X="+inPackage[1]);break;

          case 2: print("  Y="+inPackage[2]);break;

          case 3: println("  Z="+inPackage[3]);break;

          case 4: println("End="+inPackage[4]);

                         println();break;

          default: break;

           }

      }

  }

 delay(150);

  }

// draw three coordinate axes    strokeWeight(1); 

  line(-87.5,100,-87.5,475);

    for(int i=0; i<=30; i++){

        if(i%5==0){

              if(i==0||i==5||i==15)

              line(-99.5,475-gap*i,-75.5,475-gap*i); 

              else

              line(-102.5,475-gap*i,-72.5,475-gap*i); 

         }

         else

         line(-94.5,475-gap*i,-80.5,475-gap*i); 

     }

     pushMatrix();

     translate(300,350);

     line(0,0,0,-250);

     for(int i=1; i<=20; i++){

          if(i%5==0){

               if(i==5||i==15)

               line(-12,-gap*i,12,-gap*i);

               else

               line(-15,-gap*i,15,-gap*i);

            }

            else

            line(-7,-gap*i,7,-gap*i);

     }

     pushMatrix();

     rotate(2*PI/3);

     line(0,0,0,-250);

     for(int i=1; i<=20; i++){

           if(i%5==0){

                if(i==5||i==15)

                 line(-12,-gap*i,12,-gap*i);

                 else

                  line(-15,-gap*i,15,-gap*i);

           }

          else 

          line(-7,-gap*i,7,-gap*i);

     }

     pushMatrix();

     rotate(2*PI/3);

     line(0,0,0,-250);

     for(int i=1; i<=20; i++){

            if(i%5==0){

                 if(i==5||i==15)

                 line(-12,-gap*i,12,-gap*i);

                 else

                  line(-15,-gap*i,15,-gap*i); 

              }

             else

             line(-7,-gap*i,7,-gap*i);

     }

          popMatrix();

        popMatrix();

      popMatrix();

      /*  line(300,350,300,100);  line(300,350,300-cos(PI/6)*250,350+sin(PI/6)*250);  line(300,350,300+cos(PI/6)*250,350+sin(PI/6)*250);*/ 

  //draw data

    strokeWeight(20);

   if(oldVal==0)

   oldVal=val;

   delta=abs(val-oldVal);

   if(delta>2){                             // delta 大於700才動作

          strokeCap(PROJECT);

          mapDelta=map(delta,0,50,0,375);

          if(mapDelta>=375) 

          mapDelta=375;

          line(-87.5,465,-87.5,465-mapDelta);

   }

   oldVal=val;

   println("delta="+delta);

strokeCap(ROUND);

      pushMatrix();

      translate(300,350);

      line(0,0,0,-Z);

        pushMatrix();

        rotate(2*PI/3);

        line(0,0,0,-Y);

          pushMatrix();

          rotate(2*PI/3);

          line(0,0,0,-X);

          popMatrix();

        popMatrix();

      popMatrix();

   popMatrix();

 }

  • HOME

  • ABOUT

  • WORK

  • CONTACT

  • More

    TIAN-JIA HSIEH ENGINEERING & DESIGN