首页 > Sktech > 习作CA_简单求对角线交点
2017
12-14

习作CA_简单求对角线交点

习作CA_简单求对角线交点 - 第1张  | Processing编程艺术


简单地通过求直线斜线交点画方形对角线交点.


[Q]:退出程序


在2.0内制作, 用3.0以上运行可能会报错:


//- --- --- ---
//- public
//- --- --- ---
//-
int cmX,cmY,cmW,cmH;
int cmDpL, cmDpR;

public void setup() {size(320, 240);noStroke();frameRate(32);textAlign(LEFT, TOP);ellipseMode(CENTER);
  frame.setTitle("CharaMap");
  //--
  cmX=10;cmY=10;
  cmW=200;cmH=100;
  cmDpL=0;
  cmDpR=height;
  //--
}//+++

public void draw() {background(0);
  int pxX=mouseX;
  int pxY=mouseY;
  //--
  cmDpL=(pxX-cmX)*cmH/cmW+cmY;
  cmDpR=(cmX+cmW-pxX)*cmH/cmW+cmY;
  //--
  stroke(0xFF);noFill();{
    rect(cmX,cmY,cmW,cmH);
    line(cmX+cmW,cmY,cmX,cmY+cmH);
    line(cmX,cmY,cmX+cmW,cmY+cmH);
    line(mouseX,0,mouseX,cmY+cmH);
  }noStroke();
  fill(0xEE,0xEE,0x33);ellipse(mouseX,cmDpL,8,8);
  fill(0x33,0xEE,0xEE);ellipse(mouseX,cmDpR,8,8);
  //--
  fill(0xAA,0x11,0x11);ellipse(mouseX, mouseY, 4, 4);
  //--
}//+++

public void keyPressed(){switch(key){
  case 'q':fsPover();
  default:break;
}}//+++

void fsPover(){exit();}//+++

//EOF

 



最后编辑:
作者:constrain
constrain
nullpointerexception

留下一个回复

你的email不会被公开。