import processing.core.*; 
import processing.xml.*; 

import java.applet.*; 
import java.awt.Dimension; 
import java.awt.Frame; 
import java.awt.event.MouseEvent; 
import java.awt.event.KeyEvent; 
import java.awt.event.FocusEvent; 
import java.awt.Image; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class ELROS extends PApplet {

///////////////////////////////////////////////////////////////
//    Crowbar\uff08\u30af\u30ed\u30a6\u30d0\u30fc\uff09
///////////////////////////////////////////////////////////////

// \u52d5\u4f5c\u306b\u95a2\u308f\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\uff0e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u8aad\u3093\u3067\u7406\u89e3\u3057\u305f\u3089\u81ea\u7531\u306b\u8a2d\u5b9a\u3057\u3066\u69cb\u3044\u307e\u305b\u3093\uff0e
public void Options() {
  // \u4ee5\u4e0b\u306f\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u4e00\u4f8b\uff08crowbarClass\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u53c2\u7167\uff09
  // crowbar.disableDisplay();            // \u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\u30a8\u30ea\u30a2\u306b\u6587\u5b57\u8868\u793a\u3057\u306a\u3044
  // crowbar.disableTextArea();           // \u753b\u9762\u4e0b\u306e\u30c6\u30ad\u30b9\u30c8\u30a8\u30ea\u30a2\u306b\u6587\u5b57\u8868\u793a\u3057\u306a\u3044
  // crowbar.noShowParameters();          // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u5f8c\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5024\u78ba\u8a8d\u306a\u3057
  // crowbar.enableLogOutput();           // default.txt\u306b\u30ed\u30b0\u3092\u8a18\u9332\u3059\u308b
  // crowbar.setcolor(#ffffff, #000000);  // \u767d\u9ed2\u53cd\u8ee2
  // crowbar.setFontSize(24);             // \u30c7\u30ab\u6587\u5b57

  // Main()\u7d42\u4e86\u5f8c\u306buserDraw()\u3092\u7e70\u308a\u8fd4\u3057\u5b9f\u884c\u3059\u308b\u306a\u3089\u3070\u4ee5\u4e0b\u306ecrowbar.nonStop()\u3092\u6709\u52b9\u306b\u3059\u308b
  crowbar.nonStop();
}

// \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u524d\u306b\u884c\u3063\u3066\u304a\u304d\u305f\u3044\u51e6\u7406\uff08setup()\u306e\u6700\u521d\u306b\u81ea\u52d5\u5b9f\u884c\uff09
public void initializeMain() {
  // \u4ee5\u4e0b\u306e\u884c\u306f\u524a\u9664\u3057\u3066\u306f\u3044\u3051\u306a\u3044\uff0e\u4e8c\u3064\u306e\u5f15\u6570\u306e\u5024\u3092\u5909\u66f4\u3059\u308b\u3068\u30a6\u30a3\u30f3\u30c9\u30a6\u30b5\u30a4\u30ba\u304c\u5909\u308f\u308b
  crowbar = new crowbarClass(60, 40);

  ELROS = new TELROS();
}

///////////////////////////////////////////////////////////////////////////////////
// \u3053\u3053\u304b\u3089\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u30e6\u30fc\u30b6\u304c\u7a4d\u6975\u7684\u306b\u8a18\u8ff0\u3057\u3066\u69cb\u308f\u306a\u3044
///////////////////////////////////////////////////////////////////////////////////
// \u30b7\u30b9\u30c6\u30e0\u521d\u671f\u8a2d\u5b9a
public void Setup()
{
  // \u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30e1\u30f3\u30c8\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u524d\u306b\u4e00\u5ea6\u3060\u3051\u753b\u9762\u8868\u793a\u3055\u308c\u307e\u3059\uff0e\u8907\u6570\u5ba3\u8a00\u53ef\uff0c\u7701\u7565\u53ef\uff09
  crowbar.programComment("\u5e73\u9762\u4e09\u30ea\u30f3\u30af\u30ed\u30dc\u30c3\u30c8\u30b7\u30df\u30e5\u30ec\u30fc\u30bf");
  crowbar.programComment("ELROS");

  // \u4ee5\u4e0b\u306b\uff0c\u5165\u529b\u304c\u5fc5\u8981\u306a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5ba3\u8a00
  // crowbar.define("\u8aac\u660e"); \u8907\u6570\u500b\u3092\u5ba3\u8a00\u3057\u3066\u3082\u69cb\u308f\u306a\u3044\uff0e\u5ba3\u8a00\u304c\u7121\u304f\u3066\u3082\u69cb\u308f\u306a\u3044\uff0e
/*
  crowbar.defineSel("\u30ea\u30f3\u30af\u6570", "2 3", 1);
  crowbar.defineNum("\u30ea\u30f3\u30af\uff11\u306e\u9577\u3055", 1.0);
  crowbar.defineNum("\u30ea\u30f3\u30af\uff12\u306e\u9577\u3055", 1.0);
  crowbar.defineNum("\u30ea\u30f3\u30af\uff13\u306e\u9577\u3055", 1.0);
  crowbar.defineNum("\u30ea\u30f3\u30af\uff11\u306e\u5e45", 0.1);
  crowbar.defineNum("\u30ea\u30f3\u30af\uff12\u306e\u5e45", 0.1);
  crowbar.defineNum("\u30ea\u30f3\u30af\uff13\u306e\u5e45", 0.1);
  crowbar.defineNum("\u30d4\u30af\u30bb\u30eb\u6bd4\uff08pixel/m)", 200);
  crowbar.defineNum("\u8a31\u5bb9\u4f4d\u7f6e\u8aa4\u5dee[m]", 0.001); // 1[mm]
*/
  crowbar.define("\u30ea\u30f3\u30af\u306e\u9577\u3055", 1.0f);
  crowbar.define("\u30ea\u30f3\u30af\u306e\u5e45", 0.1f);
}

// \u30e1\u30a4\u30f3\u30eb\u30fc\u30c1\u30f3
// \u30e6\u30fc\u30b6\u306e\u30e1\u30a4\u30f3\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\uff08\uff11\u5ea6\u3057\u304b\u5b9f\u884c\u3055\u308c\u306a\u3044\uff09\u3092\u4ee5\u4e0b\u306b\u8a18\u8ff0
// void Main() \u306e\u95a2\u6570\u540d\u3092\u5909\u3048\u3066\u306f\u3044\u3051\u306a\u3044\uff0e
public void Main() {
  // \u5909\u6570\u306e\u4ee3\u5165
/*
  ELROS.Robot.RobotConfig.LinkNumber = crowbar.getInt();
  ELROS.Robot.RobotConfig.L1_Length  = crowbar.getFloat();
  ELROS.Robot.RobotConfig.L2_Length  = crowbar.getFloat();
  ELROS.Robot.RobotConfig.L3_Length  = crowbar.getFloat();
  ELROS.Robot.RobotConfig.L1_Width   = crowbar.getFloat();
  ELROS.Robot.RobotConfig.L2_Width   = crowbar.getFloat();
  ELROS.Robot.RobotConfig.L3_Width   = crowbar.getFloat();
  ELROS.World.PixelRatio             = crowbar.getFloat();
  ELROS.Robot.RC.allowableError      = crowbar.getFloat();
*/
  ELROS.Robot.RobotConfig.L1_Length  = crowbar.getFloat();
  ELROS.Robot.RobotConfig.L1_Width   = crowbar.getFloat();

  // \u81ea\u52d5\u8a08\u7b97
  ELROS.Robot.RobotConfig.LinkNumber = 3;  // \u5f8c\u65e5\uff12\u30ea\u30f3\u30af\u306b\u3082\u62e1\u5f35\u4e88\u5b9a
  ELROS.Robot.RobotConfig.L2_Length  = ELROS.Robot.RobotConfig.L1_Length;
  ELROS.Robot.RobotConfig.L3_Length  = ELROS.Robot.RobotConfig.L1_Length;
  ELROS.Robot.RobotConfig.L2_Width   = ELROS.Robot.RobotConfig.L1_Width;
  ELROS.Robot.RobotConfig.L3_Width   = ELROS.Robot.RobotConfig.L1_Width;
  ELROS.World.PixelRatio             = 200.0f;
  ELROS.Robot.RC.allowableError      = 0.001f;
  ELROS.Robot.RobotConfig.J1_Radius  = ELROS.Robot.RobotConfig.L1_Width;
  ELROS.Robot.RobotConfig.J2_Radius  = ELROS.Robot.RobotConfig.L2_Width;
  ELROS.Robot.RobotConfig.J3_Radius  = ELROS.Robot.RobotConfig.L3_Width;
}

// \u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\uff08\u30e6\u30fc\u30b6\uff09\u3092\u4ee5\u4e0b\u306b\u8a18\u8ff0
TELROS ELROS;

///////////////////////////////////////////////////////////////
// Processing\u306b\u3088\u308b\u4e8c\u5206\u6cd5\u306e\u5bfe\u8a71\u7684\u30d7\u30ed\u30b0\u30e9\u30e0\u958b\u767a\u7528\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af
//    Crowbar\uff08\u30af\u30ed\u30a6\u30d0\u30fc\uff09
//                                  \u767d\u4e95\u3000\u9054\u4e5f\uff08Tatsuya Shirai)
//                       shirai\uff20mech.suzuka-ct.ac.jp, @tatsuva
//                                       2012/04/20    Ver. 0.9
//                                       2012/05/14    Ver. 1.0
///////////////////////////////////////////////////////////////
//
// [A] Main()\u4e2d\u3067\u4f7f\u7528\u3057\u305f\u3044\u30d1\u30e9\u30e1\u30fc\u30bf\u3092setup()\u5185\u3067\u5ba3\u8a00\u3059\u308b
// setup()\u5185\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5b9a\u7fa9\uff1a 
//  \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5024\u306f\u57fa\u672c\u7684\u306b\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3046\uff0e
//  \u305d\u308c\u3092getFloat()\u3084getInt()\u306a\u3069\u306e\u5f62\u3067\u6570\u5024\u306b\u5909\u63db\u3057\u3066\u53d6\u5f97\u3059\u308b\uff0e\u52ff\u8ad6\uff0cgetStr()\u3067\u6587\u5b57\u5217\u306e\u307e\u307e\u53d7\u3051\u53d6\u308b\u3053\u3068\u3082\u53ef\u80fd\uff0e
//  \u305f\u3060\u3057\u5b9f\u969b\u306b\u306f\u6570\u5024\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u53d7\u3051\u53d6\u308b\u3053\u3068\u304c\u5927\u534a\u3060\u3068\u601d\u308f\u308c\u308b\u306e\u3067\uff0c\u57fa\u672c\u5f62\u306f\u6570\u5024\u5165\u529b\u3092\u524d\u63d0\u3068\u3057\u305f\u30ad\u30fc\u5165\u529b
//  \u5236\u9650\u898f\u5247\u3068\u3057\uff0c\u6587\u5b57\u5217\u5168\u3066\u3092\u53d7\u3051\u5165\u308c\u308b\u306b\u306fdefineStr()\u3092\u7528\u3044\u308b\u3053\u3068\u3068\u3059\u308b\uff0e
//  0) \u57fa\u672c\u5f62
//     crowbar.define(String)\uff1a\u6570\u5024\u5165\u529b\u3092\u524d\u63d0\u3068\u3057\u305f\u30ad\u30fc\u5165\u529b\u5236\u9650\u898f\u5247\uff0eString\u306f\u753b\u9762\u306b\u8868\u793a\u3055\u308c\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u8aac\u660e\u6587
//  1) \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5165\u529b\u53ef\u80fd\u6587\u5b57\u5236\u7d04\uff08\u6570\u5b57\u5165\u529b\u306e\u307f/\u5168\u3066\u306e\u6587\u5b57\u5217\u3092\u53d7\u3051\u5165\u308c\u308b\uff09
//     \u57fa\u672c\u5f62\u306f\u6570\u5024\u5165\u529b\u306b\u5fc5\u8981\u306a\u30ad\u30fc\u4ee5\u5916\u306f\u7121\u8996\u3059\u308b\uff080-9 + - .\u306e\u307f\uff09\uff1a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u898f\u5236\u3059\u308b\u8a33\u3067\u306f\u306a\u3044
//     \u6587\u5b57\u5217\u5165\u529b\u5168\u822c\u3092\u8a31\u53ef\u3059\u308b\u5834\u5408\u306fdefineStr(String)\u3092\u7528\u3044\u308b\uff0e
//     \u4f8b\uff09crowbar.defineStr(String)
//  2) \u521d\u671f\u5024\u3092\u4e0e\u3048\u308b\uff1aENTER\u30ad\u30fc\u306e\u307f\u306e\u5165\u529b\u3067\u9078\u629e\u3055\u308c\u308b\uff08trim()\u306f\u884c\u308f\u306a\u3044\u306e\u3067\u7a7a\u767d\u30b9\u30da\u30fc\u30b9\u304c\u6df7\u5165\u3057\u305f\u3089\uff2e\uff27\uff09
//     \u4f8b\uff09crowbar.define(String1, String2): String2\u304c\u521d\u671f\u5024\uff0e\u6587\u5b57\u5217\u3067\u4e0e\u3048\u308b\u3053\u3068
//  3) \u9078\u629e\u80a2\uff080-9\u306e\u30ad\u30fc\u3067\u9078\u629e\u306e\u5341\u629e\u306e\u307f\uff09
//     \u4f8b\uff09crowbar.defineSel(String, String):    \u534a\u89d2\u30b9\u30da\u30fc\u30b9\u3067\u533a\u5207\u3063\u305f\u6587\u5b57\u5217\u3067\u4e0e\u3048\u308b\u3053\u3068
//     \u4f8b\uff09crowbar.defineSel(String, String, 0); \u30ad\u30fc\u306b\u5bfe\u5fdc\u3059\u308b\u521d\u671f\u5024\u3092\u4e0e\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff0e
//  \u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u4e00\u3064\u3082\u4e0e\u3048\u306a\u304f\u3066\u3082\uff2f\uff2b
//  \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u8aad\u307f\u51fa\u3057\u306f\uff0ccrowbar.getFloat()\u306e\u3088\u3046\u306b\u81ea\u52d5\u8aad\u307f\u51fa\u3057\u3084
//                          crowbar.getFloat(0)\u306e\u3088\u3046\u306bIndex\u3092\u4e0e\u3048\u3066\u8aad\u307f\u51fa\u3059\uff0e
//  \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4e0e\u3048\u305f\u5834\u5408\uff0c\u81ea\u52d5\u8aad\u307f\u51fa\u3057\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u305d\u306e\u6b21\u306eIndex\u306b\u306a\u308b\u70b9\u306b\u6ce8\u610f
//
// [B] Main()\u5185\u306b\u30e6\u30fc\u30b6\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8a18\u8ff0
// Main()\u5185\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u30e6\u30fc\u30b6\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5909\u6570\u306b\u6e21\u3059
//   crowbar.getFloat(int), crowbar.getInt(int), crowbar.getStr(int)
//   crowbar.getFloat/Int/Str()\u306b\u5f15\u6570\u3092\u660e\u793a\u7684\u306b\u4e0e\u3048\u306a\u304b\u3063\u305f\u5834\u5408\u306f\u6700\u5f8c\u306b\u8aad\u307f
//   \u51fa\u3055\u308c\u305findex\u306e\u6b21\u306e\u5f15\u6570\u914d\u5217\u306e\u30c7\u30fc\u30bf\u304c\u81ea\u52d5\u7684\u306b\u8aad\u307f\u3060\u3055\u308c\u308b
//  Main()\u95a2\u6570\u306f\u4e00\u5ea6\u3060\u3051\u5b9f\u884c\u3057\u3066\u505c\u6b62\u3059\u308b\uff0e\u7121\u9650\u30eb\u30fc\u30d7\u306b\u5165\u3063\u305f\u3089'Q'\u30ad\u30fc\u3092\u62bc\u3057\u3066\u3082\u6b62\u307e\u3089\u306a\u3044\uff0e
//
// \u3010\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\u753b\u9762\u306b\u3064\u3044\u3066\u3011
// \u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\u753b\u9762\u306e\u30b5\u30a4\u30ba\u306f\u6a2a\u306e\u6587\u5b57\u6570\uff0c\u7e26\u306e\u884c\u6570\uff0c\u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\u306b\u3088\u308a\u81ea\u52d5\u8a08\u7b97\u3055\u308c\u307e\u3059\uff0e
// setup()\u5185\u306e   crowbar = new crowbarClass(60, 40); \u306e\u5f15\u6570\u3067\u5909\u66f4\u3055\u308c\u307e\u3059\uff0e
// crowbar.clrscr()\u3067\u5b9f\u884c\u753b\u9762\u3092\u6d88\u53bb\u3059\u308b\uff0e\u305f\u3060\u3057\uff0c\u3053\u306e\u5834\u5408\u306f\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u3082\u30af\u30ea\u30a2\u3055\u308c\u308b\uff0e
// \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u306f\u6d88\u53bb\u3057\u305f\u304f\u306a\u3044\u5834\u5408\u306f\uff0ccrowbar._clrscr()\u3092\u5b9f\u884c\u3059\u308c\u3070\u826f\u3044\uff0e
//
// crowbar.windowSize(pixel, pixel)\u3067\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u7528\u306e\u30a6\u30a3\u30f3\u30c9\u30a6\u306e\u30b5\u30a4\u30ba\u3092\u81ea\u7531\u306b\u5909\u3048\u3089\u308c\u308b
// \uff08\u305d\u308c\u306b\u5408\u308f\u305b\u3066\u6700\u5927\u306e\u6587\u5b57\u6570\uff0f\u884c\u6570\u306e\u5024\u3092\u518d\u8a2d\u5b9a\u3057\u306a\u3044\uff09
//
// crowbar.enableOverlap()\u3067\uff0c\u30a6\u30a3\u30f3\u30c9\u30a6\u304b\u3089\u306f\u307f\u51fa\u308b\u6587\u5b57\u5217\u3092\u6298\u308a\u8fd4\u3057\u3066\u6b21\u884c\u306b\u8868\u793a\u3059\u308b\uff0e
// crowbar.disableOverlap()\u3067\uff0c\u306f\u307f\u51fa\u3057\u305f\u6587\u5b57\u5217\u306f\u8868\u793a\u3057\u306a\u3044\uff0e
//
// crowbar.disableDisplay()\u3067\uff0ccrowbar.write()/writeln()\u306e\u51fa\u529b\u3092\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9
// \u3000\u9818\u57df\u306b\u306f\u51fa\u529b\u3057\u306a\u3044\uff0e
// crowbar.enableDisplay()\u3067\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\u51fa\u529b\u3092\u518d\u958b
// crowbar.switchDisplay(boolean)\u3067\u5909\u6570\u306b\u3088\u308a\u5909\u66f4\u53ef\u80fd
//
// \u9006\u306b\uff0cPDE\u306e\u30c6\u30ad\u30b9\u30c8\u30a8\u30ea\u30a2\u306b\u6587\u5b57\u5217\u3092\u8868\u793a\u3059\u308b\u306e\u3092\u6291\u5236\u3057\u305f\u3044\u5834\u5408\u3082\u3042\u308b\uff0e
// \u305d\u306e\u6642\u306b\u306f\u9069\u6642\uff0c\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\uff0e
// crowbar.disableTextArea()\u3067\u6291\u5236
// crowbar.enableTextArea()\u3067\u51fa\u529b
//
// \u5168\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5165\u529b\u3057\u305f\u5f8c\u306b\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u5165\u529b\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\uff0e
// \u3082\u3057\u3053\u308c\u3092\u7701\u304d\u305f\u3044\u306a\u3089\u3070\uff0csetup()\u4e2d\u306a\u3069\u306b\uff0ccrowbar.noShowParameters()\u3092\u8a18\u8ff0\u3059\u308b\uff0e
//
// crowbar.nonStop()\u6307\u5b9a\u6642\u306fMain()\u3092\u5b9f\u884c\u7d42\u4e86\u5f8c\uff0cdraw()\u306e\u7d42\u7aef\u306b\u8a18\u8ff0\u3055\u308c\u305f\u30e6\u30fc\u30b6
// \u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7e70\u308a\u8fd4\u3057\uff08Processing\u672c\u6765\u306e\u52d5\u4f5c\u3068\u3057\u3066\uff09\u5b9f\u884c\u3059\u308b\uff0e
// \u5b89\u5168\u306b\u7d42\u4e86\u3059\u308b\u306b\u306f\uff0ccrowbar.stop()\u3092\u5b9f\u884c\u3059\u308b\uff0e
// crowbar.nonStop()\u6642\u306b\u306f[q]/[Q]\u30ad\u30fc\u306b\u3088\u308b\u5f37\u5236\u7d42\u4e86\u306f\u6a5f\u80fd\u3057\u306a\u3044\uff0e
// crowbar.nonStop()\u306f\u3067\u304d\u308b\u3060\u3051setup()\u5185\u306b\u8a18\u8ff0\u3057\u3066\u4e0b\u3055\u3044\uff0e
//
// Main()\u3068userDraw()\u5b9f\u884c\u4e2d\u306ecrowbar.write()/writeln()\u306e\u51fa\u529b\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092
// setup()\u5185\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\uff0e
// \u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u306f\u30b9\u30b1\u30c3\u30c1\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u3067\u3059\uff0e\uff08Ctrl+K\uff09
// crowbar.enableLogOutput() : \u30d5\u30a1\u30a4\u30eb\u540d\u306f default.txt
// crowbar.enableLogOutput(\u30d5\u30a1\u30a4\u30eb\u540d) : \u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u8a18\u9332
//
// \u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8aac\u660e\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u524d\u306b\u4e00\u5ea6\u3060\u3051\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\uff0e
// setup()\u5185\u306b\uff0ccrowbar.programComment(\u6587\u5b57\u5217) \u3092\u8a18\u8ff0\u3057\u3066\u4e0b\u3055\u3044\uff0e
// \u3053\u308c\u306f\u7701\u7565\u53ef\u80fd\u3067\u3059\u3057\uff0c\u8907\u6570\u500b\u306e\u5ba3\u8a00\u3082\u53ef\u80fd\u3067\u3059\uff0e
//
// \u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u518d\u3073\u59cb\u3081\u308b\u304b\u3069\u3046\u304b\u306e\u78ba\u8a8d\u4e2d\u306b\u30c6\u30ad\u30b9\u30c8\u753b\u9762\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u4e0a\u4e0b\u306b\u30b9\u30af\u30ed\u30fc\u30eb\u53ef\u80fd\u3067\u3059\uff0e
// \u30ad\u30fc\u30dc\u30fc\u30c9\u306e[-]\u307e\u305f\u306f[\u2190]\u3067\u4e0a\u306b\uff0c[+}\u307e\u305f\u306f[\u2192]\u3067\u4e0b\u306b\u534a\u30da\u30fc\u30b8\u4e0b\u304c\u308a\u307e\u3059\uff0e
// \u30ad\u30fc\u30dc\u30fc\u30c9\u306e[\u2191]\u3068[\u2193]\u3067\u4e00\u884c\u5358\u4f4d\u3067\u4e0a\u3068\u4e0b\u306b\u753b\u9762\u304c\u30b9\u30af\u30ed\u30fc\u30eb\u3057\u307e\u3059\uff0e
// [y]\u3092\u62bc\u3057\u3066\u518d\u3073\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u304b\u3089\u3084\u308a\u76f4\u3059\u969b\u306b\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u5f8c\u306e\u753b\u9762\u307e\u3067\u623b\u308a\u307e\u3059\uff0e

// \u30e1\u30a4\u30f3\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u5ba3\u8a00\uff08\u7d76\u5bfe\u306b\u524a\u9664\u3057\u3066\u306f\u3044\u3051\u307e\u305b\u3093\uff09
crowbarClass crowbar;

///////////////////////////
// \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u306e\u30af\u30e9\u30b9
// \uff08\u30b9\u30af\u30ed\u30fc\u30eb\u5bfe\u5fdc\u7528\uff09
///////////////////////////
// \u30e1\u30e2\u30ea\u306e\u78ba\u4fdd\u3092\u30ea\u30b9\u30c8\u69cb\u9020\u306b\u3059\u308b\u304b\u914d\u5217\u306b\u3059\u308b\u304b
// \u52b9\u7387\u3092\u8003\u3048\u3066\u914d\u5217\u306b\u3088\u308b\u30da\u30fc\u30b8\u5358\u4f4d\u306e\u78ba\u4fdd\u3092\u5f53\u521d\u306f\u9078\u629e\u3057\u305f\u304c\uff0c\u5fdc\u7528\u6027\u304c\u60aa\u3044\uff0e
// \u305f\u3068\u3048\u3070\uff11\u30da\u30fc\u30b8\u306e\u884c\u6570\u3092\u9014\u4e2d\u3067\u81ea\u7531\u306b\u5909\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\uff0e
// \u306a\u304a\uff0c\u3042\u3068\u304b\u3089\u884c\u304c\u633f\u5165\u3055\u308c\u308b\u3053\u3068\u306f\u8003\u3048\u3066\u3044\u306a\u3044\uff0e
// \u3057\u304b\u3057\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u306b\u3088\u308b\u884c\u6570\u306e\u518d\u8a08\u7b97\u306e\u3053\u3068\u3092\u8003\u3048\u308b\u3068\u30ea\u30b9\u30c8\u69cb\u9020\u3067\u3082\u5927\u5dee\u306a\u3044\u53ef\u80fd\u6027\u304c\u9ad8\u3044\uff0e
// \u518d\u63cf\u753b\u3082\u4e0b\u304b\u3089\u4e0a\u306b\u9061\u308b\u3053\u3068\u306f\u7121\u3044\u306e\u3067\u5358\u5411\u306e\u30ea\u30b9\u30c8\u69cb\u9020\u3067\u826f\u3044\u3068\u8003\u3048\u305f
// \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u304b\u3064\u30b9\u30af\u30ed\u30fc\u30eb\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306e\u6226\u7565\uff1a
// \u3000\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3057\u3066\u6298\u308a\u8fd4\u3059\u5206\u306f\u6b21\u306e\u30e9\u30a4\u30f3\u30c7\u30fc\u30bf\u306b\u5165\u308c\u308b\uff0e\u5f8c\u65e5\uff0c\u5b9f\u884c\u30a6\u30a3\u30f3\u30c9\u30a6\u306e\u30b5\u30a4\u30ba\u5909\u66f4\u306b
// \u5bfe\u5fdc\u3059\u308b\u969b\u306b\u306f\uff0c\u4e00\u65e6\uff0c\u6539\u884c\u3055\u308c\u305f\u30e9\u30a4\u30f3\u30c7\u30fc\u30bf\u3092\u7e4b\u3052\u76f4\u3057\u3066\uff0c\u305d\u308c\u304b\u3089\u307e\u305f\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3057\u76f4\u3059\uff0e
// \u305d\u306e\u969b\u306b\u884c\u6570\u304c\u6e1b\u308b\u304b\u3082\u77e5\u308c\u306a\u3044\uff0e\u4e0d\u8981\u306b\u306a\u3063\u305f\u30e9\u30a4\u30f3\u30c7\u30fc\u30bf\u306f\u30ea\u30b9\u30c8\u69cb\u9020\u304b\u3089\u5207\u308a\u96e2\u3057\uff0cGC\u306b\u958b\u653e\u3055\u305b\u308b\uff0e
// \u4e00\u884c\u5206\u306e\u30af\u30e9\u30b9\uff08\u6700\u5c0f\u5358\u4f4d\uff09
class lineClass {
  protected int     no;    // \u884c\u756a\u53f7\uff0e\uff10\u304b\u3089\u59cb\u307e\u308b
  protected String  line;
  protected boolean flag;  // \u5165\u529b\u6e08\u307f\u304b\uff1f\uff08\u7a7a\u884c\u3092\u8003\u616e\uff0eline\u306e\u6587\u5b57\u6570\u3067\u306f\u5224\u65ad\u3067\u304d\u306a\u3044\u305f\u3081\uff0e\u3055\u3089\u306bnew\u306f\u3067\u304d\u3066\u3082\u30e1\u30e2\u30ea\u306f\u89e3\u653e\u3067\u304d\u306a\u3044\uff1f\u305f\u3081\uff09
  protected boolean overlap;  // \u524d\u306e\u884c\u306e\u6298\u308a\u8fd4\u3057\u304b\uff08\u5f8c\u65e5\uff0c\u5b9f\u884c\u30a6\u30a3\u30f3\u30c9\u30a6\u306e\u30b5\u30a4\u30ba\u5909\u66f4\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306b\uff09
  lineClass         next;  // \u6b21\u306e\u884c\u306e\u4f4d\u7f6e
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  lineClass() {
    clear();
  }
  // \u30af\u30ea\u30a2
  public void clear() {
    no         = 0;
    line       = "";
    flag       = false;
    overlap    = false;
    next       = null;
  }
  // \u884c\u5358\u4f4d\u306e\u30c7\u30fc\u30bf\u306e\u30bb\u30c3\u30c8
  public void set(String str, boolean over) {
    line    = str;
    flag    = true;
    overlap = over;
    if (next == null) next = new lineClass();  // \u30ea\u30b9\u30c8\u69cb\u9020\u3092\u518d\u5229\u7528\u3059\u308b\u5834\u5408\u306f\u78ba\u4fdd\u3057\u306a\u3044
    next.no = no + 1;
  }
}

///////////////////////////////
// \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u672c\u4f53\u306e\u30af\u30e9\u30b9
class textbufferClass {
  private int   cwidth;              // \u5b9f\u884c\u30a6\u30a3\u30f3\u30c9\u30a6\u306e\u30c6\u30ad\u30b9\u30c8\u306e\u6587\u5b57\u6570
  private int   fontSize;            // \u5b9f\u884c\u30a6\u30a3\u30f3\u30c9\u30a6\u306e\u30c6\u30ad\u30b9\u30c8\u306e\u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba
  lineClass     currentWriteLine;    // \u73fe\u5728\u306e\u66f8\u304d\u8fbc\u307f\u53ef\u80fd\u306a\u884c\u30c7\u30fc\u30bf
  lineClass     topLine;             // \u4e00\u756a\u6700\u521d\u306e\u884c\u30c7\u30fc\u30bf
  protected int totalLines;          // \u51fa\u529b\u6e08\u307f\u306e\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u306e\u884c\u6570\u3092\u5358\u7d14\u306b\u8fd4\u3059\uff08\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u306f\u8003\u616e\u3057\u306a\u3044\uff09
  protected int readingLine;         // \u73fe\u5728\u306e\u8aad\u307f\u51fa\u3057\u3055\u308c\u3066\u3044\u308b\u884c\u756a\u53f7
  private String buff;               // \u73fe\u5728\u306e\u672a\u6539\u884c\u306e\u30d0\u30c3\u30d5\u30a1

// \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  textbufferClass(int max_x, int fsize) {
    cwidth           = max_x;
    fontSize         = fsize;
    topLine          = new lineClass();
    totalLines       = 0;
    currentWriteLine = topLine;
    readingLine      = 0;
    buff = "";
  }
  // \u7dcf\u884c\u6570\u3092\u6b63\u78ba\u306b\u53d6\u5f97\u3059\u308b\u969b\u306b\u7528\u3044\u308b\uff08\u3044\u307e\u306e\u3068\u3053\u308d\u4f7f\u7528\u7b87\u6240\u306f\u7121\u3044\uff09
  public int refreshTotalLines() {
    lineClass temp = topLine;
    totalLines = 0;
    while (temp.next != null) {
      if (temp.flag != true) break;  // GC\u3092\u671f\u5f85\u3057\u306a\u3044\u3067\uff0c\u53e4\u3044\u30ea\u30b9\u30c8\u69cb\u9020\u3092\u518d\u5229\u7528\u3059\u308b\u601d\u60f3\u3067\u884c\u304f
      temp = temp.next;
      totalLines++;
    }
    return totalLines;
  }
  ///////////////////////
  // \u30aa\u30fc\u30d0\u30fc\u30e9\u30fc\u30c3\u30d7\u95a2\u4fc2
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u6307\u5b9a\u3055\u308c\u305f\u4e00\u884c\u306e\u6587\u5b57\u6570\u3084\u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3059\u308b\u5834\u5408\u306b\uff08\u672a\u5bfe\u5fdc\uff09
  public void changeConditions(int max_x, int fsize) {
    cwidth   = max_x;
    fontSize = fsize;
    // TODO: \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u884c\u3092\u518d\u5ea6\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3057\u76f4\u3059\u51e6\u7406\u3092\u4ee5\u4e0b\u306b\u8a18\u8ff0
  }
  // \u4e0e\u3048\u3089\u308c\u305f\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8fd4\u3059
  public float getStringLength(String str) {
    return textWidth(str) / fontSize; // \u3053\u308c\u3067OK\u3060\u3063\u305f
  }
  // \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u51e6\u7406
  
  ///////////////////
  // \u305d\u306e\u4ed6
  ///////////////////
  // \u5168\u30c7\u30fc\u30bf\u306e\u30af\u30ea\u30a2
  // GC\u3067\u6d88\u3048\u308b\u306e\u3092\u671f\u5f85\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u53e4\u3044\u30ea\u30b9\u30c8\u69cb\u9020\u3092\u518d\u5229\u7528\u3059\u308b
  public void clear() {
    lineClass  temp, next;
    temp = topLine;
    while (true) {
      if (temp.next == null)  break;
      if (temp.flag == false) break;
      next = temp.next;
      temp.clear();
      temp = next;
    }
    buff = "";
    totalLines  = 0;
    currentWriteLine = topLine;
    readingLine = 0;
  }
  // \u73fe\u5728\u306e\u884c\u306e\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b\uff08\u672a\u6539\u884c\uff09
  public void set(String str) {
    buff += str;
  }
  // \u30c7\u30fc\u30bf\u66f8\u304d\u8fbc\u307f\u306e\u672c\u4f53
  public void _setLine(String str, boolean overlap) {
    currentWriteLine.set(str, overlap);
    currentWriteLine = currentWriteLine.next;
    totalLines++;
  }
  // \u81ea\u52d5\u7684\u306b\u4e00\u884c\u5206\u306e\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b \uff08\u5b9f\u969b\u306b\u306fstr\u306f""\u3057\u304b\u6765\u306a\u3044\u304c\u2026\uff09
  // \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u6709\u52b9\u6642\u306b\u6298\u308a\u8fd4\u3057\u5206\u3092\u65b0\u305f\u306b\u884c\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u3066\u305d\u3061\u3089\u306b\u7d9a\u3051\u308b\uff0e
  public void setLine(String str, boolean overlap) {
    str = buff + str;
    if (!overlap) {
      _setLine(str, false);
    } else {
      // \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u6709\u52b9\u6642\u306e\u5206\u5272\u51e6\u7406
      // lineClass\u306eoverlap\u306f\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u306e\u201d\u767a\u751f\u3057\u305f\u201d\u884c\u306e\u307ftrue\u3068\u3059\u308b
      String buffer;  // \u5206\u5272\u3059\u308b\u969b\u306e\u982d\u5074\u306e\u6587\u5b57\u5217
      int    df;      // str\u304b\u3089buffer\u306b\u79fb\u52d5\u3059\u308b\u6587\u5b57\u5217\u306e\u9577\u3055
      while (true) {
        // \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u306e\u767a\u751f\u3057\u3066\u3044\u306a\u3044\u884c\uff08\u3042\u308b\u3044\u306f\u6b8b\u308a\u306e\u90e8\u5206\uff09
        if (getStringLength(str) < cwidth) {
          _setLine(str, false);
          break;
        }
        // \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3057\u3066\u3044\u308b\u5206\u3092\uff11\u884c\u5206\uff0c\u5207\u308a\u53d6\u308b\uff0e
        // \u7e70\u308a\u8fd4\u3057\u30eb\u30fc\u30d7\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u306f\uff0c\u30ad\u30e3\u30e9\u30af\u30bf\u6570\u3068\u6587\u5b57\u5e45\u304c\u4e00\u81f4\u3057\u306a\u3044\u305f\u3081\uff0e
        // \u534a\u89d2\u6587\u5b57\u306f0.5\u6587\u5b57\u5e45\u3068\u30ab\u30a6\u30f3\u30c8\u3059\u308b\u306e\u3067\uff0c\u3068\u308a\u3042\u3048\u305a\u5168\u89d2\u3068\u4eee\u5b9a\u3057\u3066\u79fb\u52d5\u3059\u308b\uff0e
        // \u305d\u3057\u3066\u8db3\u308a\u3066\u3044\u306a\u3044\u5206\u304c\u30bc\u30ed\u306b\u306a\u308b\u307e\u3067\u6f38\u8fd1\u7684\u306b\u79fb\u52d5\u3057\u3066\u884c\u304f\uff0e
        buffer  = "";
        while ((df = cwidth - PApplet.parseInt(getStringLength(buffer))) > 0) {
          // \u8db3\u308a\u3066\u3044\u306a\u3044\u3068\u601d\u308f\u308c\u308b\u6587\u5b57\u6570\u5206\u3092str\u304b\u3089buffer\u306b\u201d\u79fb\u52d5\u201d\u3059\u308b\uff0e
          buffer += str.substring(0, df);
          str = str.substring(df);
        }
        // \u3053\u308c\u306f\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3057\u305f\u5206\u306a\u306e\u3067\u7b2c2\u5f15\u6570\u306ftrue
        _setLine(buffer, true);
      }
    }
    buff = "";
  }
  // \u30d0\u30c3\u30d5\u30a1\u3092\u30d5\u30e9\u30c3\u30b7\u30e5\uff08\u66f8\u304d\u51fa\u3059\uff09
  public void flushBuffer(boolean overlap) {
    if (buff.length() > 0) setLine("", overlap);
  }
  // \u6307\u5b9a\u3055\u308c\u305f\u884c\u756a\u53f7\u306e\u884c\u30c7\u30fc\u30bf\u3092\u8fd4\u3059\uff08\uff10\u884c\u304b\u3089\u59cb\u3081\u308b\uff09
  public lineClass getTargetLine(int line) {
    lineClass temp = topLine;
    int  num;
    for (num = 0; num < line; num++) {
      if (temp.next == null) break;
      if (temp.flag != true) break;
      temp = temp.next;
    }
    return temp;
  }
  // \u8868\u793a\u958b\u59cb\u884c\u3092\u30c0\u30a4\u30ec\u30af\u30c8\u306b\u6307\u5b9a\u3059\u308b
  public void setReadingLine(int num) {
    if (num < 0) num = 0;
    if (num >= totalLines - 1) num = totalLines - 1;
    readingLine = num;
  }
  // \u8868\u793a\u958b\u59cb\u884c\u6570\u3092\u6307\u5b9a\u884c\u6570\u5206\uff0c\u5897\u52a0\u3059\u308b
  public void incrementReadingLine(int num) {
    setReadingLine(readingLine + num);
  }
  // \u30c7\u30d0\u30c3\u30b0\u7528\uff1a\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u3092\u5168\u3066\u8868\u793a
  public void displayAllTextBuffer() {
    int  i;
    lineClass temp;
    temp = topLine;
    i = 0;
    while (true) {
      if (temp == null) break;
      print(str(i) + ":" + str(temp.no) + ":" + str(temp.flag) +":" + str(temp.overlap) + ":" + str(temp.line.length()));
      println("[" + temp.line + "]");
      if (temp.next == null) break;
      temp = temp.next;
      i++;
    }
  }
}

// \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u898f\u5247\u306e\u30af\u30e9\u30b9
class keyInputConstraintClass {
  private boolean point;   // [.]\u30ad\u30fc\u304c\u62bc\u3055\u308c\u305f\u304b
  private boolean sign;    // [+],[-]\u30ad\u30fc\u304c\u62bc\u3055\u308c\u305f\u304b
  private boolean inputted; // \u6570\u5b57\u304c\u65e2\u306b\u5165\u529b\u6e08\u307f\u304b
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  keyInputConstraintClass() { reset(); }
  // \u521d\u671f\u5316
  public void reset() {
    point = sign = inputted = false;
  }
  // \u6d6e\u52d5\u5c0f\u6570\u70b9\u6642\u306e\u5165\u529b\u898f\u5247\u30c1\u30a7\u30c3\u30af
  public boolean checkFloat(char c) {
    boolean flag = true;
    switch (c) {
      case '+' :
      case '-' :
        if ((sign) || (inputted)) flag = false;
          else sign = true;
        break;
      case '.' :
        if ((point) || (!inputted)) flag = false;
          else point = true;
        break;
      default :
        if (isNumberChar(c)) inputted = true;
          else               flag = false;
        break;
    }
    return flag;    
  }
  // \u6574\u6570\u5165\u529b\u6642\u306e\u5165\u529b\u898f\u5247\u30c1\u30a7\u30c3\u30af\uff08\u73fe\u72b6\u306f\u4f7f\u308f\u308c\u3066\u3044\u306a\u3044\uff09
  public boolean checkInt(char c) {
    if (c == '.') return false;
    return checkFloat(c);
  }
}

// \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u8a18\u9332\u7528\u30af\u30e9\u30b9
class loggingClass {
  private String       _defaultFileName = "default.txt";
  protected String     logFileName;    // \u30d5\u30a1\u30a4\u30eb\u540d\uff08\u30b9\u30b1\u30c3\u30c1\u30d5\u30a9\u30eb\u30c0\u306b\u4fdd\u5b58\uff09
  private boolean      logging;        // true\u306e\u9593\u306f\u30ed\u30b0\u3092\u8a18\u9332\u3059\u308b
  private PrintWriter  output;         // \u30ed\u30b0\u51fa\u529b\u7528\u30d5\u30a1\u30a4\u30eb\u30dd\u30a4\u30f3\u30bf
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  loggingClass() {
    logFileName   = _defaultFileName;
    logging       = false;
  }
  // \u30ed\u30b0\u95a2\u4fc2
  // \u72b6\u614b\u78ba\u8a8d\u3068\u30d5\u30e9\u30b0\u30bb\u30c3\u30c8\uff08\u30e6\u30fc\u30b6\u306f\u4f7f\u7528\u3057\u306a\u3044\u3067\u4e0b\u3055\u3044\uff09
  public void setFileName(String filename) {
    if (filename.length() > 0) logFileName = filename;
      else                     logFileName = _defaultFileName;
  }
  // \u30ed\u30b0\u8a18\u9332\u958b\u59cb
  public void startLogging() {
    output = createWriter(logFileName);    
    logging = true;
    println2Log("--- Logging start : " + nowDateTime() + "---");
  }
  // \u30ed\u30b0\u8a18\u9332\u7d42\u4e86
  public void stopLogging() {
    println2Log("--- Logging finished : " + nowDateTime() + "---");
    logging = false;
    output.flush();
    output.close();
  }
  // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u306e\u307fprint()
  public void print2Log(String str) { if (logging) output.print(str); }
  // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u306e\u307fprintln()
  public void println2Log(String str) { if (logging) output.println(str); }
  // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u306e\u307fnewline()
  public void newline2Log() { println2Log(""); }
}

/////////////////////////////////////////
// \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u306e\u30af\u30e9\u30b9
/////////////////////////////////////////
class consoleClass {
  // \u5b9f\u884c\u30a6\u30a3\u30f3\u30c9\u30a6\u95a2\u4fc2\u306e\u8a2d\u5b9a
  private float cx = 0.0f, cy = 0.0f;        // \u30ad\u30e3\u30e9\u30af\u30bf\u306e\u8868\u793a\u4f4d\u7f6e\uff08\u30ab\u30ec\u30f3\u30c8\u30dd\u30b8\u30b7\u30e7\u30f3\uff09\uff0c\u534a\u89d2\u6587\u5b57\u306f0.5\u6587\u5b57
  private int   cwidth, cheight;           // \u30ad\u30e3\u30e9\u30af\u30bf\u306e\u6a2a\u6587\u5b57\u6570\uff0c\u884c\u6570
  private int   gwx, gwy;                  // \u30b9\u30af\u30ea\u30fc\u30f3\u30b5\u30a4\u30ba
  private int   colwidth, rowheight;       // \u4e00\u6587\u5b57\u306e\u6587\u5b57\u9001\u308a\uff0c\u884c\u9593\uff08pixel\uff09
  private int   frameWidth;                // \u984d\u7e01\u306e\u5e45
  private int   fontSize;                  // \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba
  // \u8272\u306e\u521d\u671f\u5024
  int backgroundColor = 0xffffffee;  // \u80cc\u666f\u8272
  int textColor       = 0xff000000;  // \u6587\u5b57\u306e\u8272
  // \u6a5f\u80fd\u9078\u629e\u306e\u30d5\u30e9\u30b0
  protected boolean nodisplay   = false;   // \u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\u8868\u793a\u306e\u6291\u5236
  protected boolean noTextArea  = false;   // PDE\u306e\u30c6\u30ad\u30b9\u30c8\u30a8\u30ea\u30a2\u3078\u306e\u6587\u5b57\u5217\u306e\u8868\u793a\u306e\u6291\u5236
  protected boolean noOverlap   = true;    // \u30a6\u30a3\u30f3\u30c9\u30a6\u304b\u3089\u306f\u307f\u51fa\u3059\u6587\u5b57\u5217\u3092\u6298\u308a\u8fd4\u3057\u3066\u6b21\u884c\u306b\u8868\u793a\u3057\u306a\u3044
  // \u30c6\u30ad\u30b9\u30c8\u753b\u9762\u306e\u30b9\u30af\u30ed\u30fc\u30eb\u8868\u793a\u95a2\u4fc2
  textbufferClass      textbuffer;         // \u30d0\u30c3\u30d5\u30a1\u95a2\u4fc2\u306e\u30af\u30e9\u30b9
  private boolean      recordTextBuffer;   // true\u306e\u9593\u306f\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u306b\u8a18\u9332\u3059\u308b
  // \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u898f\u5247\u306e\u30c1\u30a7\u30c3\u30af
  keyInputConstraintClass  keyCheck;
  // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u95a2\u4fc2
  loggingClass         textLog;
  private boolean      enableLogging;  // \u30c6\u30ad\u30b9\u30c8\u30ed\u30b0\u3092\u8a18\u9332\u3059\u308b\uff08setup()\u3067\u306e\u307f\u6709\u52b9\uff09

  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\uff08\u5f15\u6570\u306f\u6a2a\u65b9\u5411\u306e\u6700\u5927\u6587\u5b57\u6570\u3068\u7e26\u65b9\u5411\u306e\u6700\u5927\u884c\u6570\uff09
  consoleClass(int max_x, int max_y) {
    // \u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u95a2\u4fc2
    cwidth     = max_x;
    cheight    = max_y;
    fontSize   = 14;
    colwidth   = PApplet.parseInt(fontSize * 1.2f);
    rowheight  = PApplet.parseInt(fontSize * 1.4f);
    frameWidth = 10;
    gwx        = cwidth  * colwidth  + frameWidth * 2;
    gwy        = cheight * rowheight + frameWidth * 2;
    // \u30b9\u30af\u30ea\u30fc\u30f3\u306e\u8a2d\u5b9a
    size(gwx, gwy);
    _clrscr();  
    // \u30d5\u30a9\u30f3\u30c8\u95a2\u4fc2
    PFont font = createFont("MS Gothic",fontSize,true);  // \u30d5\u30a9\u30f3\u30c8\u3092\u5909\u63db
    textFont(font);         // \u30d5\u30a9\u30f3\u30c8\u3092\u8a2d\u5b9a
    textSize(fontSize);     // \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\u3092\u8a2d\u5b9a\uff08\u4e0d\u8981\uff1f\uff09
    textAlign(LEFT, TOP);   // \u914d\u7f6e
    // \u30b9\u30af\u30ed\u30fc\u30eb\u8868\u793a\u7528\u306e\u30d0\u30c3\u30d5\u30a1\u95a2\u9023
    textbuffer       = new textbufferClass(cwidth, fontSize);
    recordTextBuffer = true;
    // \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u898f\u5247\u30c1\u30a7\u30c3\u30af
    keyCheck = new keyInputConstraintClass();
    // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u95a2\u4fc2
    textLog  = new loggingClass();
    enableLogging = false;
  }

  // ----------- \u753b\u9762\u51fa\u529b\u95a2\u4fc2-----------------
  // \u6587\u5b57\u4f4d\u7f6e\u3092\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\u5ea7\u6a19\u306b\u5909\u63db
  public int px(float x) { return PApplet.parseInt(x * colwidth  + frameWidth); }
  public int py(float y) { return PApplet.parseInt(y * rowheight + frameWidth); }

  // \u51fa\u529b\u4f4d\u7f6e\u6307\u5b9a\uff08\u5ec3\u6b62\u4e88\u5b9a\uff1a\u4f7f\u3063\u3066\u3082\u826f\u3044\u304c\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u306f\u975e\u5bfe\u5fdc\uff09
  public void locate(int x, int y) {
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    cx = x;
    cy = y;
  }
  // \u884c\u6570\u304c\u6700\u5927\u5024\u306b\u9054\u3057\u305f\u304b
  public boolean rowCheck() {
    // \u9054\u3057\u305f\u306a\u3089\u3070\u753b\u9762\u6d88\u53bb
    if (cy >= cheight) {
      _clrscr();
      textbuffer.readingLine += cheight;  // \u3053\u3053\u3060\u3051\u306f\u5f37\u5236\u7684\u306b\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\uff08\u307e\u3060\u51fa\u529b\u3057\u3066\u3044\u306a\u3044\uff09
      return true;
    }
    return false;
  }
  // BS\u30ad\u30fc\u304c\u62bc\u3055\u308c\u305f\u5834\u5408\u306e\u51e6\u7406
  public void backSpace() {
    if (keyBufferLength() > 0) {
      keyBuffer = keyBuffer.substring(0, keyBuffer.length() - 1);
      writeBS();
    }
  }
  // \u30c6\u30ad\u30b9\u30c8\u6587\u5b570.5\u6587\u5b57\u5206\u3092\u524a\u9664\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u6642\u306e\u307f\u6709\u52b9\u306a\u305f\u3081\uff09
  public void writeBS() {
    if (cx <= 0) return;
    if (!nodisplay) {
      cx -= 0.5f;
      noStroke();
      fill(backgroundColor);    // \u80cc\u666f\u8272
      rect(px(cx), py(cy), colwidth/2, rowheight);
      fill(textColor);          // \u5857\u308a\u3064\u3076\u3057\u8272
      stroke(textColor);
    }
//  if (!noTextArea) print("\b");  // backspace\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u306f\u7121\u52b9\u306e\u6a21\u69d8\uff0e
  }
  // \u4e0e\u3048\u3089\u308c\u305f\u6587\u5b57\u306e\u5927\u304d\u3055\u3092\u8fd4\u3059\uff0e\u5168\u89d2\u306a\u3089\u3070\uff11\uff0c\u534a\u89d2\u306a\u3089\u30700.5
  public float charLength(char c) {
    return textWidth(c) / fontSize;
  }
  // \u4e0e\u3048\u3089\u308c\u305f\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8fd4\u3059
  public float getStringLength(String str) {
    return textWidth(str) / fontSize; // \u3053\u308c\u3067OK\u3060\u3063\u305f
  }
  // \u4e00\u6587\u5b57\u8868\u793a\uff08\u6587\u5b57\u5217\u306f\u5168\u3066\u3053\u306e\u95a2\u6570\u3092\u4ecb\u3057\u3066text()\u3067\u8868\u793a\u3059\u308b
  public void putchar(char c) {
    text(c, px(cx), py(cy));
    cx += charLength(c);
  }

  ///////////////////////
  // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u95a2\u9023
  ///////////////////////
  // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u3078\u306e\u8a18\u9332\u3092\u4e00\u6642\u7684\u306b\u505c\u6b62\u3059\u308b
  public void stopRecordTextBuffer()  { recordTextBuffer = false; }
  // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u3078\u306e\u8a18\u9332\u3092\u518d\u958b\u3059\u308b
  public void startRecordTextBuffer() { recordTextBuffer = true;  }
  // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u306e\u6307\u5b9a\u3055\u308c\u305f\u884c\u304b\u3089\uff11\u30da\u30fc\u30b8\u5206\u3092\u518d\u63cf\u753b\u3059\u308b
  public void redrawPage() {
    redrawPage(textbuffer.readingLine);
  }
  public void redrawPage(int line) {
    int       lineCount, dcy;
    lineClass thisline;

    // \u8868\u793a\u958b\u59cb\u884c\u6570\u306e\u30c1\u30a7\u30c3\u30af
    textbuffer.incrementReadingLine(0);
    // \u521d\u671f\u5316
    _clrscr();
    thisline = textbuffer.getTargetLine(line);
    // \u518d\u63cf\u753b
    // \u30b9\u30af\u30ed\u30fc\u30eb\u8868\u793a\u6642\u306f\u4e00\u6642\u7684\u306b\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3092\u5f37\u5236\u7684\u306b\u30aa\u30d5\u306b\u3059\u308b
    boolean over_flag = noOverlap;
    disableOverlap();
    for (lineCount = 0; lineCount < cheight; lineCount += dcy) {
      if (!thisline.flag) break; // \u3053\u308c\u4ee5\u964d\uff0c\u30c6\u30ad\u30b9\u30c8\u304c\u51fa\u529b\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u629c\u3051\u308b
      dcy = writeln(thisline.line);
      thisline = thisline.next;
    }
    // \u5143\u306e\u72b6\u614b\u306b\u623b\u3059
    noOverlap = over_flag;
  }
  // \u30da\u30fc\u30b8\u5358\u4f4d\u306e\u30b9\u30af\u30ed\u30fc\u30eb
  // page\u304c\u6b63\u3067\u4e0b\uff0c\u8ca0\u3067\u4e0a\u306b\u30b9\u30af\u30ed\u30fc\u30eb
  public void pageScroll(float page) {
    textbuffer.incrementReadingLine(PApplet.parseInt(cheight * page));
    redrawPage();
  }
  // \u6307\u5b9a\u3057\u305f\u884c\u6570\u3060\u3051\u4e0a/\u4e0b\u306b\u30b9\u30af\u30ed\u30fc\u30eb\u3059\u308b
  // num \u304c\u6b63\u3067\u4e0b\uff0c\u8ca0\u3067\u4e0a\u306b\u30b9\u30af\u30ed\u30fc\u30eb
  public void pageLineScroll(int num) {
    textbuffer.incrementReadingLine(num);
    redrawPage();
  }
  // \u6700\u65b0\u306e\u30da\u30fc\u30b8\u3092\u518d\u63cf\u753b\uff08\u30ab\u30fc\u30bd\u30eb\u4f4d\u7f6e\u304c\u5fa9\u5143\u3055\u308c\u306a\u3044\u306e\u306f\u4ed5\u65b9\u304c\u7121\u3044
  public void redrawNewestPage() {
    int  linenumber;
    if (textbuffer.totalLines < cheight) {
      textbuffer.setReadingLine(0);
    } else {
      textbuffer.setReadingLine(textbuffer.totalLines - PApplet.parseInt(cheight / 2.0f));
    }
    redrawPage();
  }

  // \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\u306e\u521d\u671f\u8a2d\u5b9a\uff08setup()\u4ee5\u5916\u3067\u5909\u66f4\u3057\u305f\u5834\u5408\u306f\u5909\u306a\u3053\u3068\u304c\u8d77\u3053\u308b\u3067\u3057\u3087\u3046\uff09
  public void setFontSize(int size) {
    fontSize   = size;
    colwidth   = PApplet.parseInt(fontSize * 1.2f);
    rowheight  = PApplet.parseInt(fontSize * 1.4f);
    gwx        = cwidth  * colwidth  + frameWidth * 2;
    gwy        = cheight * rowheight + frameWidth * 2;
    // \u30b9\u30af\u30ea\u30fc\u30f3\u306e\u8a2d\u5b9a
    size(gwx, gwy);
    _clrscr();  
    // \u30d5\u30a9\u30f3\u30c8\u95a2\u4fc2
    PFont font = createFont("MS Gothic",fontSize,true);  // \u30d5\u30a9\u30f3\u30c8\u3092\u5909\u63db
    textFont(font);         // \u30d5\u30a9\u30f3\u30c8\u3092\u8a2d\u5b9a
    textSize(fontSize);     // \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\u3092\u8a2d\u5b9a\uff08\u4e0d\u8981\uff1f\uff09
  }
  // \u6587\u5b57\u8272\u3068\u80cc\u666f\u8272\u306e\u521d\u671f\u8a2d\u5b9a\uff08setup()\u4ee5\u5916\u3067\u5909\u66f4\u3057\u305f\u5834\u5408\u306f\u5909\u306a\u3053\u3068\u304c\u8d77\u3053\u308b\u3067\u3057\u3087\u3046\uff09
  public void setcolor(int textcolor, int backgroundcolor) {
    textColor = textcolor;
    backgroundColor = backgroundcolor;
//  _clrscr();
  }
  // \u753b\u9762\u6d88\u53bb\uff08\u753b\u9762\u306e\u307f\u30af\u30ea\u30a2\uff09
  public void _clrscr() {
    background(backgroundColor);    // \u80cc\u666f\u8272
    fill(textColor);                // \u5857\u308a\u3064\u3076\u3057\u8272
    cx = cy = 0;
  }
  // \u753b\u9762\u6d88\u53bb\uff08\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u3082\u30af\u30ea\u30a2\uff09
  public void clrscr() {
    _clrscr();
    textbuffer.clear();
  }
  // \u30c6\u30ad\u30b9\u30c8\u51fa\u529b\uff08\u5358\u7d14\u306b\u63cf\u753b\u3059\u308b\u3060\u3051\uff09: userDraw()\u4e2d\u3067\u5229\u7528\u3059\u308b\u306e\u306b\u9069\u3057\u3066\u3044\u308b
  public int _write(String message) {
    int  i, num = 1;
    for (i = 0; i < message.length(); i++) {
      putchar(message.charAt(i));
      // \u6298\u308a\u8fd4\u3057\u8868\u793a\u306b\u95a2\u3059\u308b\u51e6\u7406
      if (noOverlap != true) {
        if (cx >= cwidth) {
          cx = 0;
          cy++;
          num++;
        }
      }
    }
    return num;
  }
  public void _write(int x, int y, String message) {
    locate(x, y);
    _write(message);
  }
  // \u30c6\u30ad\u30b9\u30c8\u51fa\u529b\uff08\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\uff0c\u30ed\u30b0\u8a18\u9332\uff0c\u30d0\u30c3\u30af\u30b9\u30da\u30fc\u30b9\u306b\u3088\u308b\u6d88\u53bb\u306b\u5bfe\u5fdc\uff09
  // \u623b\u308a\u5024\u306f\u5b9f\u884c\u30a6\u30a3\u30f3\u30c9\u30a6\u306b\u51fa\u529b\u3057\u305f\u5b9f\u969b\u306e\u884c\u6570\uff08\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3092\u8003\u616e\uff09
  public int write(String message) {
    int i;
    int num = 0;
    if (!nodisplay) {
      rowCheck();
      num = _write(message);
      if (recordTextBuffer) textbuffer.set(message);
    }
    // \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b
    if (!noTextArea) {
      if (recordTextBuffer) print(message);
    }
    // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332
    if (enableLogging) textLog.print2Log(message);
    return num;
  }
  // \u30c6\u30ad\u30b9\u30c8\u51fa\u529b\uff08\u6539\u884c\uff09
  public int writeln(String message) {
    int num;

    num = write(message);
    // \u4ee5\u4e0b\u6539\u884c\u306e\u307f\u51fa\u529b
    if (!nodisplay) {
      if (recordTextBuffer) textbuffer.setLine("", !noOverlap);
      cy++;
      cx = 0;
    }
    // \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b
    if (!noTextArea) {
      if (recordTextBuffer) println();
    }
    // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332
    if (enableLogging) textLog.println2Log("");
    return num;
  }
  // \u6539\u884c
  public void newline() { writeln(""); }
  // \u30a6\u30a3\u30f3\u30c9\u30a6\u30b5\u30a4\u30ba\u306e\u5909\u66f4
  public void windowSize(int x, int y) {
    gwx = x;
    gwy = y;
    size(gwx, gwy);
  }
  // \u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u8868\u793a\u306e\u30c1\u30a7\u30f3\u30b8
  public void displaySwitch(boolean flag) { nodisplay = flag; }
  // \u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u8868\u793a\u306e\u6291\u5236\u3068\u8a31\u53ef
  public void disableDisplay() { nodisplay = true;  }
  public void enableDisplay()  { nodisplay = false; }
  // \u30c6\u30ad\u30b9\u30c8\u30a8\u30ea\u30a2\u8868\u793a\u306e\u30c1\u30a7\u30f3\u30b8
  public void textAreaSwitch(boolean flag) { noTextArea = flag; }
  // \u30c6\u30ad\u30b9\u30c8\u30a8\u30ea\u30a2\u8868\u793a\u306e\u6291\u5236\u3068\u8a31\u53ef
  public void disableTextArea() { noTextArea = true;  }
  public void enableTextArea()  { noTextArea = false; }
  // \u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u8868\u793a\uff08\u6298\u308a\u8fd4\u3057\uff09\u306e\u6291\u5236\u3068\u8a31\u53ef
  public void disableOverlap()  { noOverlap = true;  }
  public void enableOverlap()   { noOverlap = false; }
  
  // Main() \u3068 userDraw()\u5b9f\u884c\u4e2d\u306ecrowbar.write()/writeln()\u3092\u30ed\u30b0\u306b\u8a18\u9332
  // \u3053\u306e\u30b9\u30a4\u30c3\u30c1\u306f\u5fc5\u305asetup()\u5185\u3067\u5229\u7528\u3057\u3066\u4e0b\u3055\u3044\uff0e\u305d\u308c\u4ee5\u5916\u3060\u3068\u7121\u610f\u5473\u3067\u3059\uff0e
  // 1) \u5f15\u6570\u7121\u3057\uff1a\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u4fdd\u5b58
  public void enableLogOutput() { enableLogOutput(""); }
  // 2) \u30d5\u30a1\u30a4\u30eb\u540d\u6307\u5b9a\u3042\u308a
  public void enableLogOutput(String fname) {
    textLog.setFileName(fname);
    println("\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\uff1a" + textLog.logFileName);
    enableLogging = true;
  }
  public boolean isEnableLogging() { return enableLogging; }

  // --------------- \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u95a2\u9023 -------------------
  // \u4ee5\u4e0b\u306e\u95a2\u6570\u3084\u5909\u6570\u3092\u30e6\u30fc\u30b6\u306f\u5229\u7528\u3057\u306a\u3044\u3053\u3068\u304c\u671b\u307e\u3057\u3044
  //
  private String keyBuffer = "";
  boolean inputNow = false;    // \u30a8\u30b3\u30fc\u30d0\u30c3\u30af\u3042\u308a
  boolean inputFixed = false;  // ENTER\u304c\u5165\u529b\u3055\u308c\u305f\u3089true
  // \u30d0\u30c3\u30d5\u30a1\u30af\u30ea\u30a2  
  public void flushKeyBuffer() {
    keyBuffer = "";
    inputFixed = false;
  }
  // \u6587\u5b57\u5217\u9577\u3092\u8fd4\u3059
  public int keyBufferLength() {
    return keyBuffer.length();
  }
  // \u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u3092\u958b\u59cb
  public void startInput() {
    inputFixed = false;
    inputNow   = true;
  }
  // \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u5b8c\u4e86
  public void inputFinish() {
    inputFixed = true;
    inputNow   = false;
  }
  // \u6587\u5b57\u5217\u306e\u8ffd\u52a0
  public void strcat(String str) {
    keyBuffer += str;
  }
  // \u30ad\u30fc\u30d0\u30c3\u30d5\u30a1\u30fc\u3092\u8aad\u307f\u51fa\u3059
  public String getKeyBuffer() {
    String buf;
    buf = keyBuffer;  // \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30af\u30ed\u30fc\u30f3\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u306a\u3089\u826f\u3044\u3051\u308c\u3069\uff0e
    keyBuffer = "";
    inputNow   = false;
    inputFixed = false;
    return buf;  // \u6587\u5b57\u5217\u30c7\u30fc\u30bf\u306e\u307f\u3092\u8fd4\u3055\u306a\u304f\u3066\u826f\u3044\u306e\u304b\uff1f
  }
}

//////////////////////////////
// \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u6700\u5c0f\u5358\u4f4d\u306e\u30af\u30e9\u30b9
//////////////////////////////
class arguments {
  boolean ready;
  String  message;
  String  value;
  String  initialValue;   // ""\u306e\u5834\u5408\u306f\u521d\u671f\u5024\u306e\u6307\u5b9a\u306a\u3057\u3068\u5224\u65ad
  String [] selectValues; // null\u306e\u5834\u5408\u306f\u9078\u629e\u80a2\u30bf\u30a4\u30d7\u3067\u306f\u306a\u3044\u3068\u5224\u65ad\uff08\u8a2d\u5b9a\u6642\u306f\u7a7a\u767d\u3067\u533a\u5207\u3089\u308c\u305f\u6587\u5b57\u5217\uff09
  char    parameterType;  // 'A': Normal, 'N': \u6570\u5024\u306e\u307f, 'S': \u9078\u629e\u80a2
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  arguments() {
    ready   = false;
    message = value = initialValue = "";
    selectValues  = null;
    parameterType = 'A';
  }
  // \u5024\u3092\u8a2d\u5b9a\uff08\u6a19\u6e96\uff09
  public void set(String str) {
    value = str;
    ready = true;
  }
}

//////////////////////////////////////////////////////////////////////////////
// \u30d7\u30ed\u30bb\u30b9\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u30af\u30e9\u30b9\uff08\u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u306e\u30af\u30e9\u30b9\u3092\u7d99\u627f\uff09
//////////////////////////////////////////////////////////////////////////////
class crowbarClass extends consoleClass {
  int          status = 0;          // \u30d7\u30ed\u30bb\u30b9\u306e\u72b6\u614b\u3092\u7ba1\u7406
  String []    comment;             // \u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30b3\u30e1\u30f3\u30c8\uff0e\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u524d\u306b\u8868\u793a\u3055\u308c\u308b\uff0e
  arguments [] argv;                // \u30d1\u30e9\u30e1\u30fc\u30bf\u7fa4\uff08\u30e6\u30fc\u30b6\u306b\u3088\u308a\u5bfe\u8a71\u7684\u306b\u5165\u529b\u3055\u308c\u308b\uff09
  int          argc;                // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u6570
  private int obtainArgIndex = 0;   // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u30b3\u30e1\u30f3\u30c8\u5ba3\u8a00\u6642\u306e\u81ea\u52d5\u767b\u9332\u7528\u30ab\u30a6\u30f3\u30bf
  private int readArgIndex = 0;     // \u30d1\u30e9\u30e1\u30fc\u30bf\u81ea\u52d5\u8aad\u307f\u51fa\u3057\u7528\u30ab\u30a6\u30f3\u30bf
  boolean noShowParams  = false;    // \u5165\u529b\u6e08\u307f\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u78ba\u8a8d\u306e\u305f\u3081\u306b\u8868\u793a\u3059\u308b\u304b\uff1f
  boolean _noShowParams = false;    // setup()\u4e2d\u3067crowbar.noShowParameters()\u304c\u6307\u5b9a\u3055\u308c\u305f\u5834\u5408\u306e\u5bfe\u7b56\uff0e\u518d\u5b9f\u884c\u6642\u306b\u30af\u30ea\u30a2\u3055\u308c\u3066\u3057\u307e\u3046\u305f\u3081\uff0e
  boolean running       = false;    // Main()\u3042\u308b\u3044\u306fcrowbar.nonStop()\u6307\u5b9a\u6642\u306b\u30e6\u30fc\u30b6\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u4e2d\u306ftrue
  boolean afterRunning  = false;    // Main()\u304c\u7d42\u308f\u3063\u305f\u5f8c\uff0c\u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u3092\u518d\u63cf\u753b\u53ef\u80fd\u306a\u9593\u306e\u307ftrue;\uff08userDraw()\u304c\u52d5\u3044\u3066\u3044\u3066\u3082\u305d\u308c\u306f\u6c17\u306b\u3057\u306a\u3044\uff0e\u4eca\u306e\u3068\u3053\u308d\uff09
  boolean nonstop  = false;         // Main()\u7d42\u4e86\u5f8c\u306fdraw()\u306e\u7d42\u7aef\u306b\u8a18\u8ff0\u3057\u305f\u30b3\u30fc\u30c9\u3092\u7e70\u308a\u8fd4\u3057\u5b9f\u884c\u3059\u308b\uff0enonStop()\u3067true/stop()\u3067false
  boolean _nonstop = false;         // setup()\u4e2d\u3067crowbar.nonStop()\u304c\u6307\u5b9a\u3055\u308c\u305f\u5834\u5408\u306e\u5bfe\u7b56\uff0e\u518d\u5b9f\u884c\u6642\u306b\u30af\u30ea\u30a2\u3055\u308c\u3066\u3057\u307e\u3046\u305f\u3081\uff0e

  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  crowbarClass(int x, int y) {
    // consoleClass\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u547c\u3076
    super(x, y);
    // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u521d\u671f\u5316
    argc = 0;
    argv = (arguments [])new arguments[1]; // \u5e38\u306b\u4e00\u3064\u4f59\u5206\u306b\u4f5c\u6210
    argv[0] = new arguments();
    // \u30b3\u30e1\u30f3\u30c8\u306e\u521d\u671f\u5316
    comment = null;
  }
 // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5024\u306e\u30bb\u30c3\u30c8
  public void setValue(String str) {
    argv[obtainArgIndex].set(str);
  }
  // \u30ad\u30fc\u5165\u529b\u30eb\u30fc\u30eb\uff08\u6570\u5024\u306e\u307f\uff09
  public boolean is_numbersOnly() {
    if (argv[obtainArgIndex].parameterType == 'N') return true;
    return false;
  }
  // \u30ad\u30fc\u5165\u529b\u30eb\u30fc\u30eb\uff08\u9078\u629e\u80a2\uff09
  // \u9078\u629e\u80a2\u578b\u306a\u3089\u3070\u9078\u629e\u80a2\u6570\uff08\u6700\u5927\uff11\uff10\uff09\u3092\u8fd4\u3059
  // \u9078\u629e\u80a2\u578b\u3067\u306f\u306a\u3044\u306a\u3089\u3070\uff10\u3092\u8fd4\u3059
  public int is_selectOnly() {
    arguments arg;
    arg = argv[obtainArgIndex];
    if (arg.parameterType == 'S') {
      // \u30c1\u30a7\u30c3\u30af\uff11
      if (arg.selectValues == null) {
        println("SystemError: \u9078\u629e\u80a2\u578b\u306a\u306e\u306b\u9078\u629e\u80a2\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u307e\u305b\u3093\uff0e");
        exit();
      }
      // \u30c1\u30a7\u30c3\u30af\uff12
      if (arg.selectValues.length > 10) {
        println("SystemError: \u9078\u629e\u80a2\u578b\u306e\u9078\u629e\u80a2\u306e\u6570\u304c\uff11\uff10\u500b\u3088\u308a\u591a\u3044\uff0e");
        exit();
      }
      return arg.selectValues.length;
    }
    return 0;
  }
  // \u9078\u629e\u80a2\u578b\u306e\u9078\u629e\u3055\u308c\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u5024\u3092\u8fd4\u3059
  public String get_selectValue(int index) {
    return argv[obtainArgIndex].selectValues[index];
  }
  // \u521d\u671f\u5024\u3092\u53d6\u5f97
  public String get_initialValue() {
    return argv[obtainArgIndex].initialValue;
  }
  // \u5b9f\u884c\u53ef\u80fd\u304b\uff1f
  public boolean allReady() {
    int i;
    // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044
    if (argv == null) return true;
    // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b
    for (i = 0; i < argc; i++) {
      if (argv[i].ready != true) return false;
    }
    return true;
  }
  // \u5168\u3066\u306e\u5165\u529b\u5b8c\u4e86\u30d5\u30e9\u30b0\u3092\u30ea\u30bb\u30c3\u30c8
  public void allResetArguments() {
    int i;
    for (i = 0; i < argv.length; i++) argv[i].ready = false;
    readArgIndex   = 0;
    obtainArgIndex = 0;
  }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u4e00\u3064\u3082\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306btrue
  public boolean isNoParameter() {
    if (argc == 0) return true;
    return false;
  }
  // \u5165\u529b\u6e08\u307f\u306e\u5168\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b
  public void showAllParameters() {
    int i, _readArgIndex;
    // \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7
    _readArgIndex = readArgIndex;
    if (noShowParams) return; // \u5ff5\u306e\u305f\u3081
    for (i = 0; i < argc; i++) {
      if (!argv[i].ready) break;  // \u5165\u529b\u6e08\u307f\u306e\u5206\u306e\u307f\u8868\u793a\u3059\u308b\u306e\u3067\uff0e
      write(get_paramMessage(i) + "\uff1a[");
      write(getStr(i));
      writeln("]");
    }
    // \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u30ea\u30b9\u30c8\u30a2
    readArgIndex = _readArgIndex;
  }
  // \u5165\u529b\u6e08\u307f\u306e\u5168\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u306e\u307f\u51fa\u529b\u5c02\u7528\u3059\u308b
  public void showAllParameters2Log() {
    boolean _display, _textarea;
    // \u30d5\u30e9\u30b0\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7
    _display  = nodisplay;
    _textarea = noTextArea;
    // \u30c6\u30ad\u30b9\u30c8\u51fa\u529b\u3092\u4e00\u6642\u7684\u306b\u7981\u6b62
    disableDisplay();
    disableTextArea();
    // \u7981\u6b62\u3057\u305f\u4e0a\u3067\u51fa\u529b\u3059\u308c\u3070\u30ed\u30b0\u306b\u306e\u307f\u51fa\u529b\u3055\u308c\u308b
    showAllParameters();
    // \u30d5\u30e9\u30b0\u3092\u623b\u3059
    if (!_display)  enableDisplay();
    if (!_textarea) enableTextArea();
  }
  // ------------------------------
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u8868\u793a\u306e\u78ba\u8a8d\u8868\u793a\u306e\u6291\u5236
  public void noShowParameters() { noShowParams = true;  }
  public void showParameters()   { noShowParams = false; } // \u5fc5\u8981\u6027\u306f\u5fae\u5999
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u8aac\u660e\u306e\u53d6\u5f97
  public String get_paramMessage(int index) {
    String    message;
    arguments arg;

    // \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u7bc4\u56f2\u306e\u30c1\u30a7\u30c3\u30af
    if ((index >= argc) || (index < 0)) {
      println();
      print("[\u8b66\u544a] \u30d1\u30e9\u30e1\u30fc\u30bf\u8aad\u307f\u51fa\u3057\u306eIndex\u304c\u7bc4\u56f2\u3092\u8d85\u3048\u3066\u3044\u307e\u3059\uff01(Index=");
      println(str(index)+")");
      return "";
    }
    // \u8aac\u660e\u306e\u53d6\u5f97
    arg     = argv[index];
    // \u5168\u3066\u306e\u30bf\u30a4\u30d7\u306b\u5171\u901a
    message = arg.message;
    // \u4ee5\u4e0b\uff0c\u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8ffd\u52a0
    // \u521d\u671f\u5024\u304c\u4e0e\u3048\u3089\u308c\u3066\u3044\u308b\u5834\u5408
    if (arg.initialValue.length() > 0) message += "\uff08\u521d\u671f\u5024\uff1a" + arg.initialValue + "\uff09";
    // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u7a2e\u985e\u306b\u3088\u3063\u3066
    if (arg.parameterType == 'N') {
      // \u6570\u5b57\u306e\u307f
      message += "\uff0f\u6570\u5b57\u306e\u307f";
    } else if (arg.parameterType == 'S') {
      // \u9078\u629e\u80a2\u578b
      int i;
      message += "\uff0f\uff08";
      for (i = 0; i < arg.selectValues.length; i++) {
        if (i > 0) message += ",";
        message += str(i) + ":" + arg.selectValues[i];
      }
      message += "\uff09";
    }
    return message;
  }
  // --------------------------------------------
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u753b\u9762\u306b\u8868\u793a\u3059\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\uff09
  // --------------------------------------------
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u6a19\u6e96\uff1a\u6570\u5b57\u306e\u307f\uff09
  public void define(String str) {
    defineStr(str);
    argv[argc - 1].parameterType = 'N';
  }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u6a19\u6e96\uff1a\u6570\u5b57\u306e\u307f\uff1a\u521d\u671f\u5024\u3042\u308a\uff09
  public void define(String str1, String str2) {
    defineStr(str1, str2);
    argv[argc - 1].parameterType = 'N';
  }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u6570\u5b57\u306e\u307f\uff1a\u521d\u671f\u5024\u3042\u308a\uff0cfloat\u6e21\u3057\uff09
  public void define(String str, float f) { define(str, str(f)); }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u6570\u5b57\u306e\u307f\uff1a\u521d\u671f\u5024\u3042\u308a\uff0cint\u6e21\u3057\uff09
  public void define(String str, int i)   { define(str, str(i)); }

  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u5165\u529b\u5236\u9650\u898f\u5247\u306a\u3057\uff09
  public void defineStr(String str) {
    argc = argv.length;
    argv = (arguments [])expand(argv, argc + 1);
    argv[argc] = new arguments();
    // \u73fe\u5728\u306e\u5024\u3092\u30bb\u30c3\u30c8
    argv[argc - 1].message = str;
  }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u5165\u529b\u5236\u9650\u898f\u5247\u306a\u3057\uff1a\u521d\u671f\u5024\u3042\u308a\uff09
  public void defineStr(String str1, String str2) {
    defineStr(str1);
    argv[argc - 1].initialValue = str2;
  }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u5165\u529b\u5236\u9650\u898f\u5247\u306a\u3057\uff1a\u521d\u671f\u5024\u3042\u308a\uff0cfloat\u6e21\u3057\uff09
  public void defineStr(String str, float f) { define(str, str(f)); }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u5165\u529b\u5236\u9650\u898f\u5247\u306a\u3057\uff1a\u521d\u671f\u5024\u3042\u308a\uff0cint\u6e21\u3057\uff09
  public void defineStr(String str, int i)   { define(str, str(i)); }

  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u9078\u629e\u80a2\u578b\uff1a\u5165\u529b\u5236\u9650\u898f\u5247\u306f0-9\u306e\u307f\uff09
  public void defineSel(String str1, String str2) {
    String list[];
    if (str2.length() <= 0) {
      println("Error: \u9078\u629e\u80a2\u578b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u5ba3\u8a00\u306e\u7b2c\uff12\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u7a7a\u6587\u5b57\u5217\u3067\u3059\uff0e");
      exit();
    }
    list = split(str2, ' ');
    if (list.length > 10) {
      println("Error: \u9078\u629e\u80a2\u578b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u5ba3\u8a00\u306e\u9078\u629e\u80a2\u306e\u6570\u306f\uff11\uff10\u500b\u4ee5\u4e0b\u3067\u3059\uff0e");
      exit();
    }
    defineStr(str1);
    argv[argc - 1].parameterType = 'S';
    argv[argc - 1].selectValues = list;
  }
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5ba3\u8a00\uff08\u9078\u629e\u578b\uff1a\u521d\u671f\u5024\u3042\u308a\uff09
  public void defineSel(String str1, String str2, int num) {
    defineSel(str1, str2);
    if (num < 0) {
      println("Error: \u9078\u629e\u80a2\u578b\u306e\u521d\u671f\u5024\u306f0\u304b\u30899\u306e\u6574\u6570\u3067\u3059\uff0e");
      exit();
    }
    if (num >= argv[argc - 1].selectValues.length) {
      println("Error: \u9078\u629e\u80a2\u578b\u306e\u521d\u671f\u5024\u306f0\u304b\u3089\u9078\u629e\u80a2\u306e\u6570-1\u307e\u3067\u3067\u3059\uff0e");
      exit();
    }
    argv[argc - 1].initialValue = str(num);
  } 

  //-------------------------
  // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5024\u3092\u53d7\u3051\u53d6\u308b
  //-------------------------
  // 1) index\u3092\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b
  // 1-a) \u30d1\u30e9\u30e1\u30fc\u30bf\u540d\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059
  public String getStr(int index) {
    if ((index >= argc) || (index < 0)) {
      println();
      print("[\u8b66\u544a] \u30d1\u30e9\u30e1\u30fc\u30bf\u8aad\u307f\u51fa\u3057\u306eIndex\u304c\u7bc4\u56f2\u3092\u8d85\u3048\u3066\u3044\u307e\u3059\uff01(Index=");
      println(str(index)+")");
      return "";
    }
    // \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u81ea\u52d5\u66f4\u65b0
    readArgIndex = index + 1;
    return argv[index].value;
  }
  // 1-b) \u30d1\u30e9\u30e1\u30fc\u30bf\u3092float\u3067\u8fd4\u3059
  public float getFloat(int index) { return PApplet.parseFloat(getStr(index)); }
  // 1-c) \u30d1\u30e9\u30e1\u30fc\u30bf\u3092int\u3067\u8fd4\u3059
  public int getInt(int index) { return PApplet.parseInt(getStr(index)); }

  // 2) index\u3092\u660e\u793a\u7684\u306b\u6307\u5b9a\u3057\u306a\u3044\u3067\u9806\u756a\u306b\u81ea\u52d5\u7684\u306b\u8aad\u307f\u51fa\u3059
  // 2-a) \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6587\u5b57\u5217\u3067\u6e21\u3059\uff08\u81ea\u52d5\uff09
  public String getStr() { return getStr(readArgIndex); }
  // 2-b) \u30d1\u30e9\u30e1\u30fc\u30bf\u3092float\u3067\u8fd4\u3059\uff08\u81ea\u52d5\uff09
  public float getFloat() { return getFloat(readArgIndex); }
  // 2-c) \u30d1\u30e9\u30e1\u30fc\u30bf\u3092int\u3067\u8fd4\u3059\uff08\u81ea\u52d5\uff09
  public int getInt() { return getInt(readArgIndex); }

  // ----------------------------------------------------------------------------
  // Main()\u7d42\u4e86\u5f8c\u306bdraw()\u7d42\u7aef\u306b\u8a18\u8ff0\u3057\u305f\u30b3\u30fc\u30c9\u3092\u7e70\u308a\u8fd4\u3057\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb
  // ----------------------------------------------------------------------------
  public void nonStop() { nonstop = true; }   // userDraw()\u95a2\u6570\u304c\u6709\u52b9
  public void stop()    { nonstop = false; }  // userDraw()\u95a2\u6570\u304c\u7d42\u4e86\u3057\u305f\u3089\u30d7\u30ed\u30b0\u30e9\u30e0\u7d42\u4e86
  
  // ----------------------------------------------
  // \u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8aac\u660e\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u524d\u306b\u8868\u793a\u3055\u308c\u308b
  // ----------------------------------------------
  // \u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30e1\u30f3\u30c8\u3092\u8868\u793a\u3059\u308b
  public void outputProgramComments() {
    int i, commNum;
    commNum = comment.length;
    for (i = 0; i < commNum; i++) writeln(comment[i]);
  }
  // \u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30e1\u30f3\u30c8\u3092\u5ba3\u8a00\uff08\u8907\u6570\u5ba3\u8a00\u53ef\u80fd\uff09\uff0esetup()\u5185\u3067\u30e6\u30fc\u30b6\u304c\u5ba3\u8a00\u3059\u308b\uff0e
  public void programComment(String str) {
    String addStr[];
    addStr    = new String[1];
    addStr[0] = str;
    if (comment == null) {
      // \u4e00\u500b\u76ee\u306e\u30b3\u30e1\u30f3\u30c8\u306e\u5834\u5408
      comment = (String [])new String[1];
      comment = addStr;
    } else {
      // \u4e8c\u500b\u76ee\u4ee5\u964d\u306e\u30b3\u30e1\u30f3\u30c8\u306e\u5834\u5408
      comment = concat(comment, addStr);
    }
  }
}

///////////////
// \u30ad\u30fc\u5165\u529b\u5224\u5b9a
///////////////
// \u6570\u5b57\u5165\u529b\u7528\u30ad\u30fc\u304b\uff1f
public boolean isKeyNumbers(char c) {
  if (isNumberChar(c)) return true;
  switch (c) {
    case '.' :
//  case ',' :  // \u304a\u7bc0\u4ecb\u904e\u304e\u308b
    case '+' :
    case '-' :
      return true;
  }
  return false;
}

public void keyPressed() {
  if (crowbar.running == false) {
    // \u30e6\u30fc\u30b6\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u52d5\u4f5c\u3057\u3066\u3044\u306a\u3044\u6642\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u4e2d\u306a\u3069\uff09
    if ((key == 'Q') || (key == 'q')) exit();
    if (crowbar.inputNow) {
      // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u4e2d
      if (key == ENTER) {
        crowbar.inputFinish();
        crowbar.newline();
      } else if (key == BACKSPACE) {
        if (crowbar.keyBufferLength() > 0) {
          crowbar.backSpace();
        }
      } else {
        // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5165\u529b
        boolean flag = true;
        int     num;
        // \u30ad\u30fc\u5165\u529b\u30eb\u30fc\u30eb
        // \u6570\u5024\u306e\u307f\u306e\u5834\u5408
        if (crowbar.is_numbersOnly()) {
          if (!isKeyNumbers(key)) flag = false;
            else                  flag = crowbar.keyCheck.checkFloat(key);
        }
        // \u9078\u629e\u80a2\u306e\u5834\u5408
        if ((num = crowbar.is_selectOnly()) > 0) {
          // \u65e2\u306b\uff11\u6587\u5b57\u5165\u529b\u6e08\u307f\uff08\u534a\u89d2\u7a7a\u767d\u3082\u542b\u3080\uff09
          if (crowbar.keyBufferLength() >= 1) flag = false;
          // \u6570\u5b57\u30ad\u30fc\uff080-9\uff09\u3067\u306f\u306a\u3044
          if (!isNumberChar(key))             flag = false;
          // \u9078\u629e\u80a2\u306e\u6570\u3088\u308a\u3082\u5927\u304d\u306a\u6570\u5b57
          if (PApplet.parseInt(str(key)) >= num)           flag = false;
        }
        if (flag) {
          crowbar.strcat(str(key));
          crowbar.write(str(key));
        }
      }
    }
    // \u30b9\u30af\u30ed\u30fc\u30eb\u53ef\u80fd\u306a\u72b6\u614b\uff08\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u4e00\u65e6\u7d42\u4e86\u3057\u3066\u30ad\u30fc\u5165\u529b\u3092\u5f85\u3063\u3066\u3044\u308b\u9593\u306e\u307f\uff09
    if (crowbar.afterRunning) {
      if (key == '-') {
        crowbar.pageScroll(-0.5f);
      } else if (key == '+') {
        crowbar.pageScroll(0.5f);
      } else if (key == CODED) {
        if (keyCode == UP) {
          crowbar.pageLineScroll(-1);
        } else if (keyCode == DOWN) {
          crowbar.pageLineScroll(1);
        } else if (keyCode == LEFT) {
          crowbar.pageScroll(-0.5f);
        } else if (keyCode == RIGHT) {
          crowbar.pageScroll(0.5f);
        }
      }
    }
    redraw();
  } else {
    // crowbar.nonStop()\u6307\u5b9a\u6642\u306e\u30e6\u30fc\u30b6\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u4e2d\u306e\u30ad\u30fc\u5165\u529b\u5224\u5b9a
    // \u30b3\u30fc\u30c9\u306fuserKeyPressed()\u306b\u8a18\u8ff0\u3059\u308b\u3068\u826f\u3044\uff0e
    userKeyPressed();
  }
}

///////////////
// \u30d7\u30ed\u30bb\u30b9\u7ba1\u7406
///////////////
public void draw() {
  switch (crowbar.status) {
    case 0: // \u521d\u671f\u72b6\u614b
      // setup()\u4e2d\u3067crowbar.nonStop()/noShowParams()\u304c\u5b9f\u884c\u3055\u308c\u305f\u5834\u5408\u306e\u5bfe\u7b56
      if (crowbar.nonstop)      crowbar._nonstop      = true;
      if (crowbar.noShowParams) crowbar._noShowParams = true;
      // \u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30e1\u30f3\u30c8\u306e\u8868\u793a
      if (crowbar.comment != null) {
        crowbar.writeln("\u3010\u30d7\u30ed\u30b0\u30e9\u30e0\u8aac\u660e\u3011");
        crowbar.outputProgramComments();
      }
      crowbar.status++;
      break;
    case 1: // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u958b\u59cb
      crowbar.allResetArguments();
      // setup()\u4e2d\u3067crowbar.nonStop()/noShowParams()\u304c\u5b9f\u884c\u3055\u308c\u305f\u5834\u5408\u306e\u5bfe\u7b56
      if (crowbar._nonstop)      crowbar.nonstop = true;
      if (crowbar._noShowParams) crowbar.noShowParams = true;
      if (!crowbar.isNoParameter()) {
        crowbar.newline();
        crowbar.writeln("\u3010\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5165\u529b\u3011");
      }
      crowbar.status++;
      break;
    case 2: // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u4e2d
      if (!crowbar.isNoParameter()) {
        crowbar.keyCheck.reset();  // \u30ad\u30fc\u5165\u529b\u898f\u5247\u306e\u30ea\u30bb\u30c3\u30c8
        crowbar.write(crowbar.get_paramMessage(crowbar.obtainArgIndex) + ":");
        crowbar.flushKeyBuffer();
        crowbar.startInput();
        // \u30eb\u30fc\u30d7\u505c\u6b62
        noLoop();
      }
      crowbar.status++;
      break;
    case 3: // \u5165\u529b\u78ba\u5b9a
      if (!crowbar.isNoParameter()) {
        String inputs;
        if (crowbar.inputFixed) {
          boolean flag = true;
          inputs = crowbar.getKeyBuffer();
          // \u7a7a\u304b\u3064\u521d\u671f\u5024\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u5834\u5408
          if (inputs.length() == 0) {
            inputs = crowbar.get_initialValue();
          }
          // \u9078\u629e\u80a2\u578b\u306e\u5834\u5408
          if (crowbar.is_selectOnly() > 0) {
            int  num;
            // \u5ff5\u306e\u305f\u3081\u306b\u30c1\u30a7\u30c3\u30af
            if (((num = PApplet.parseInt(inputs)) < 0) || (num > 9)) {
              flag = false;            
            } else if (num > crowbar.is_selectOnly()) {
              flag = false;
            }
            if (!flag) {
              // \u3042\u308a\u5f97\u306a\u3044\u306f\u305a\uff08\u5165\u529b\u6642\u306b\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u308b\u306e\u3067\uff09
              println("SystemError: \u9078\u629e\u80a2\u578b\u306e\u5165\u529b\u5024\u304c\u7570\u5e38\u3067\u3059\uff08" + str(num) + "\uff09\uff0e");
              exit();
            }
            inputs = crowbar.get_selectValue(num);
          }
          crowbar.setValue(inputs);
          crowbar.obtainArgIndex++;
          // \u30eb\u30fc\u30d7\u518d\u958b
          loop();
          crowbar.status++;
        }
      } else crowbar.status++;
      break;
    case 4: // \u30d1\u30e9\u30e1\u30fc\u30bf\u5165\u529b\u5b8c\u4e86\u304b\u306e\u5224\u5b9a
      if (!crowbar.isNoParameter()) {
        if (crowbar.allReady()) {
          crowbar.status++;
        } else {
          crowbar.status -= 2;
        }
      } else crowbar.status++;
      break;
    case 5: // \u5b9f\u884c\u304b\uff1f \u518d\u5165\u529b\u304b\uff1f
      if (!crowbar.isNoParameter()) {
        crowbar.newline();
        crowbar.writeln("\u3010\u5168\u3066\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5165\u529b\u304c\u5b8c\u4e86\u3011");
        if (!crowbar.noShowParams) crowbar.showAllParameters();
        crowbar.write("\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b(Yes) /\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5165\u529b\u3057\u76f4\u3059(Retry) : ");
      }
      crowbar.status++;
      break;
    case 6: // \u30ad\u30fc\u5224\u5b9a\u7d50\u679c
      if (!crowbar.isNoParameter()) {
        if (keyPressed) {
          if ((key == 'y') || (key == 'Y')) {
            crowbar.writeln(str(key));
            crowbar.newline();
            crowbar.status++;
          } else if ((key == 'r') || (key == 'R')) {
            crowbar.writeln(str(key));
            crowbar.newline();
            crowbar.status -= 5;
          }
        }
      } else crowbar.status++;
      break;
    case 7: // \u30e1\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u524d\u51e6\u7406\uff08\u3042\u308b\u306a\u3089\u3070\uff09
      preMain(); // optionCode\u30bf\u30d6\u53c2\u7167
      crowbar.running = true;
      crowbar.status++;
      break;
    case 8: // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f
      if (crowbar.isEnableLogging()) {
        crowbar.textLog.startLogging();
        crowbar.textLog.newline2Log();
        crowbar.showAllParameters2Log();
        crowbar.textLog.newline2Log();
      }
      crowbar.status++;
      break;
    case 9: // \u30e1\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c
      Main();
      // \u30eb\u30fc\u30d7\u518d\u958b
      loop();
      crowbar.status++;
      break;
    case 10: // \u7e70\u308a\u8fd4\u3057\u5b9f\u884c\u30b3\u30fc\u30c9\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\uff09
      if (crowbar.nonstop) break;
      crowbar.status++;
      break;
    case 11: // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b
      crowbar.running = false;
      if (crowbar.isEnableLogging()) {
        // \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b
        crowbar.textLog.newline2Log();
        crowbar.textLog.stopLogging();
      }
      crowbar.status++;
      break;
    case 12: // \u30e1\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u5f8c\u51e6\u7406\uff08\u3042\u308b\u306a\u3089\u3070\uff09
      postMain(); // optionCode\u30bf\u30d6\u53c2\u7167
      crowbar.status++;
      break;
    case 13: // \u30ea\u30c8\u30e9\u30a4\u78ba\u8a8d\u30e1\u30c3\u30bb\u30fc\u30b8
      crowbar.newline();
      crowbar.writeln("\u3010\u30d7\u30ed\u30b0\u30e9\u30e0\u7d42\u4e86\u3011");
      crowbar.write("\u3082\u3046\u4e00\u5ea6\uff0c\u5b9f\u884c\u3057\u307e\u3059\u304b\uff1f(Yes/No)\uff1a");
      // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u95a2\u9023
      crowbar.afterRunning = true;
      crowbar.textbuffer.flushBuffer(!crowbar.noOverlap);
      crowbar.stopRecordTextBuffer();
      crowbar.status++;
      break;
    case 14: // \u30ad\u30fc\u5224\u5b9a\u7d50\u679c
      if (keyPressed) {
        if ((key == 'y') || (key == 'Y')) {
          crowbar.writeln(str(key));
          crowbar.newline();
          // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u2015\u95a2\u9023
          crowbar.redrawNewestPage();
          crowbar.afterRunning = false;
          crowbar.startRecordTextBuffer();
          crowbar.status = 1;
        } else if ((key == 'n') || (key == 'N')) {
          crowbar.writeln(str(key));
          // \u30c6\u30ad\u30b9\u30c8\u30d0\u30c3\u30d5\u30a1\u2015\u95a2\u9023
          crowbar.redrawNewestPage();
          crowbar.afterRunning = false;
          crowbar.startRecordTextBuffer();
          crowbar.status++;
        }
      }
      break;
    case 15: // \u7d42\u4e86
      exit();
      break;
  }
  if (crowbar.running) {
    // crowbar.nonStop()\u6307\u5b9a\u6642\u306e\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u306fuserDraw()\u306b\u8a18\u8ff0
    userDraw();
  }
}

public void mouseDragged() {
  if (crowbar.running) userMouseDragged();
}
public void mouseMoved() {
  if (crowbar.running) userMouseMoved();
}
public void mousePressed() {
  if (crowbar.running) userMousePressed();
}
public void mouseReleased() {
  if (crowbar.running) userMouseReleased();
}
public void mouseClicked() {
  if (crowbar.running) userMouseClicked();
}
public void keyReleased() {
  if (crowbar.running) userKeyReleased();
}
public void keyTyped() {
  if (crowbar.running) userKyeTyped();
}

// \u30b7\u30b9\u30c6\u30e0\u521d\u671f\u8a2d\u5b9a
public void setup()
{
  initializeMain();
//frameRate(10);
  Setup();
  Options();
}

/////////////////////////////////////////////////////
// Processing\u306b\u306f\u7528\u610f\u3055\u308c\u3066\u3044\u306a\u3044\u6570\u5b66\u7cfb\u306e\u6c4e\u7528\u7684\u306a\u95a2\u6570
/////////////////////////////////////////////////////

// 1. int sgn(float), int sgn(int) : \u8ca0\u306a\u3089\u3070-1\uff0c\u6b63\u306a\u3089\u3070 1\uff0c\u30bc\u30ed\u306a\u3089\u3070 0 \u3092\u8fd4\u3059
// 2. nowDateTime(void)   : \u65e5\u6642\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059\uff08yyyy/mm/dd hh:mm:ss\uff09
// 3. getKEY(void)        : \u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u3092\u5927\u6587\u5b57\u306b\u5909\u63db\u3057\u3066\u8fd4\u3059(a-z\u306e\u5834\u5408\u306e\u307f)
// 4. isNumberChar(char)  : char\u304c'0'\u304b\u3089'9'\u306a\u3089\u3070\u771f

// 1. int sgn(float), int sgn(int) : \u8ca0\u306a\u3089\u3070-1\uff0c\u6b63\u306a\u3089\u3070 1\uff0c\u30bc\u30ed\u306a\u3089\u3070 0 \u3092\u8fd4\u3059
public int sgn(int i) {
  return sgn(PApplet.parseFloat(i));
}
public int sgn(float f) {
  if (f < 0.0f) return -1;
  if (f > 0.0f) return  1;
  return 0;
}

// 2. nowDateTime() : \u65e5\u6642\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059\uff08yyyy/mm/dd hh:mm:ss\uff09
public String nowDateTime() {
  return str(year()) + '/' + str(month()) + '/' + str(day()) + ' ' + str(hour()) + ':' + str(minute()) + ':' + str(second());
}

// 3. getKEY() : \u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u3092\u5927\u6587\u5b57\u306b\u5909\u63db\u3057\u3066\u8fd4\u3059(a-z\u306e\u5834\u5408\u306e\u307f)
public char getKEY() {
  if ((key < 'a') || (key > 'z')) return key;
  return str(key).toUpperCase().charAt(0);
}

// 4. isNumberChar(char)    : char\u304c'0'\u304b\u3089'9'\u306a\u3089\u3070\u771f
public boolean isNumberChar(char c) {
  if ((c >= '0') && (c <= '9')) return true;
  return false;
}


// \u4e8c\u6b21\u5143\u30d9\u30af\u30c8\u30eb
class D2T {
  float  x, y;
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  D2T() {
    x = y = 0.0f;
  }
  // \u6e1b\u7b97
  public D2T Sub(D2T A) {
    D2T C;
    C = new D2T();
    C.x = x - A.x;
    C.y = y - A.y;
    return C;
  }
// \u52a0\u7b97
  public D2T Add(D2T A) {
    D2T C;
    C = new D2T();
    C.x = x + A.x;
    C.y = y + A.y;
    return C;
  }
  // \u30ce\u30eb\u30e0
  public float Norm() {
    return sqrt(x * x + y * y);
  }
  // \u5358\u4f4d\u30d9\u30af\u30c8\u30eb
  public D2T Unit() {
    D2T C;
    C = new D2T();
    C.x = x;
    C.y = y;
    C.x /= Norm();
    C.y /= Norm();
    return C;
  }
  // \u30b9\u30ab\u30e9\u500d
  public D2T Scale(float A) {
    D2T C;
    C = new D2T();
    C.x = x * A;
    C.y = y * A;
    return C;
  }
  // \u56de\u8ee2\u884c\u5217
  public D2T Rot(float a) {
    D2T C;
    C = new D2T();
    C.x = cos(a) * x - sin(a) * y;
    C.y = sin(a) * x + cos(a) * y;
    return C;
  }
}

// \u884c\u5217\uff08\uff12\u00d7\uff12\uff09
class Tm22 {
  boolean InvError;
  float m[][] = new float[2][2];
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  Tm22() { InvError = false; }
  // \u8ee2\u7f6e
  public Tm22 trans() {
    Tm22 C;
    C = new Tm22();
    C.m[0][1] = m[1][0];
    C.m[1][0] = m[0][1];
    return C;
  }
  // \u9006\u884c\u5217
  public Tm22 Inv() {
    Tm22  C;
    float e;
    C = new Tm22();
    InvError = false;
    C.m[0][0] =  m[1][1];
    C.m[0][1] = -m[0][1];
    C.m[1][0] = -m[1][0];
    C.m[1][1] =  m[0][0];
    e = C.m[0][0] * C.m[1][1] - C.m[0][1] * C.m[1][0];
    if (abs(e) < 0.001f) {
      C.m[0][0] = C.m[0][1] = C.m[1][0] = C.m[1][1] = 0.0f;
      InvError = true;
      return C;
    }
    C.m[0][0] /= e;
    C.m[0][1] /= e;
    C.m[1][0] /= e;
    C.m[1][1] /= e;
    return C;
  }
}

class Tm23 {
  float m[][] = new float[2][3];
}
class Tm32 {
  boolean    InvError;	// \u9006\u884c\u5217\u4e0d\u53ef\uff08\u6b63\u5247\u3067\u306f\u306a\u3044\uff09
  float m[][] = new float [3][2];
  Tm32() {
    InvError = false;
  }
}

// \uff12\u00d7\uff13\u3068\uff13\u00d7\uff12\u884c\u5217
class Tm33 {
  Tm32 m32 = new Tm32();
  Tm23 m23 = new Tm23();
  // \u8ee2\u7f6e(1) m23 -> m32
  public Tm32 transHV(Tm23 m23) {
    Tm32 m32 = new Tm32();
    int  i, j;
    for (i = 0; i < 2; i++) {
      for (j = 0; j < 3; j++) {
        m32.m[j][i] = m23.m[i][j];
        }
      }
    return m32;
  }
  // \u8ee2\u7f6e(2) m32 -> m23
  public Tm23 transVH(Tm32 m32) {
    Tm23  m23 = new Tm23();
    int	i, j;
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 2; j++) {
        m23.m[j][i] = m32.m[i][j];
      }
    }
    return m23;
  }
  // \u639b\u3051\u7b97(\uff12\uff13\u00d7\uff13\uff12\u884c\u5217\uff1d\uff12\u00d7\uff12\u884c\u5217\uff09
  public Tm22 mult2332(Tm23 m23, Tm32 m32) {
    int  i, j, k;
    Tm22 m22 = new Tm22();
    for (i = 0; i < 2; i++) {
      for (j = 0; j < 2; j++) {
        for (m22.m[i][j] = 0.0f, k = 0; k < 3; k++) {
          m22.m[i][j] += m23.m[i][k] * m32.m[k][j];
        }
      }
    }
    return m22;
  }
  // \u639b\u3051\u7b97(\uff13\uff12\u00d7\uff12\uff12\u884c\u5217\uff1d\uff13\u00d7\uff12\u884c\u5217\uff09
  public Tm32 Mult3222(Tm32 am32, Tm22 m22) {
    Tm32 m32 = new Tm32();
    int  i, j, k;
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 2; j++) {
        for (m32.m[i][j] = 0.0f, k = 0; k < 2; k++) {
          m32.m[i][j] += am32.m[i][k] * m22.m[k][j];
        }
      }
    }
    return m32;
  }
  // \uff12\u00d7\uff13\u306e\u64ec\u4f3c\u9006\u884c\u5217\u3092\uff13\u00d7\uff12\u3078
  public Tm32 Inv() { return Inv(m23); }
  public Tm32 Inv(Tm23 A) {
    Tm32 m32 = new Tm32();
    Tm32 At  = new Tm32();
    Tm22 AAt = new Tm22();
    Tm22 AAti= new Tm22();

    m32.InvError = false;
    At  = transHV(A);	      // At
    AAt = mult2332(A, At);    // AAt
    AAti= AAt.Inv();          // (AAt)^(-1)
    m32 = Mult3222(At, AAti); // At (AAt)^(-1)
    if (AAt.InvError == true) m32.InvError = true;
    return m32;
  }
}

//-----------\u3000\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u5fc5\u8981\u306e\u3042\u308b\u30e6\u30fc\u30b6\u306e\u307f\u8a18\u8ff0\u3059\u308b --------------

// \u3082\u3057Main()\u306e\u958b\u59cb\u524d\u306b\u5b9f\u884c\u3057\u3066\u304a\u304d\u305f\u3044\u30b3\u30fc\u30c9\u304c\u5225\u306b\u3042\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306b\u8a18\u8ff0\uff0e
// \u3053\u306e\u30eb\u30fc\u30c1\u30f3\u306e\u51fa\u529b\u306f\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332\u3055\u308c\u307e\u305b\u3093\uff0e
public void preMain() {
  ELROS.World.ReCalc();
}

// \u3082\u3057Main()\u7d42\u4e86\u5f8c\u306b\u5b9f\u884c\u3057\u3066\u304a\u304d\u305f\u3044\u30b3\u30fc\u30c9\u304c\u5225\u306b\u3042\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306b\u8a18\u8ff0\uff0e
// \u3053\u306e\u30eb\u30fc\u30c1\u30f3\u306e\u51fa\u529b\u306f\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332\u3055\u308c\u307e\u305b\u3093\uff0e
public void postMain() {
// \u4f8b) crowbar.clrscr();
  crowbar.clrscr();
  ELROS.World.ReCalc();
  ELROS.Robot.ReCalc();
  mainPaintBoxRefresh();
}

// \u30e6\u30fc\u30b6\u72ec\u81ea\u306emousePressed()
public void userMousePressed() {
  mainPaintBoxMouseDown(mouseX, mouseY);
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306emouseRelased()
public void userMouseReleased() {
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306emouseDragged()
public void userMouseDragged() {
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306emouseMoved()
public void userMouseMoved() {
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306emouseClicked()
public void userMouseClicked() {
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306ekeyPressed()
public void userKeyPressed() {
// \u4f8b\uff09 if ((key == 'h') || (key == 'H')) crowbar.stop();
  if ((key == 'h') || (key == 'H')) crowbar.stop();
  FormKeyDown();
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306ekeyRleased()
public void userKeyReleased() {
}
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306ekeyTyped()
public void userKyeTyped() {
}

// \u3082\u3057Main()\u7d42\u4e86\u5f8c\u306b\u901a\u5e38\u306eProcessing\u306e\u3088\u3046\u306b\u30a8\u30f3\u30c9\u30ec\u30b9\u306b\u51e6\u7406\u3092\u7d9a\u3051\u308b\u5834\u5408\u306f
// setup()\u306bcrowbar.nonStop()\u3092\u8a18\u8ff0\u3059\u308b\u3068\u5171\u306b\uff0c\u4ee5\u4e0b\u306b\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\uff0e
// \u30e6\u30fc\u30b6\u72ec\u81ea\u306edraw()
public void userDraw() {
// \u4f8b\uff09  crowbar.writeln("\u5b9f\u884c\u4e2d");
  if (ELROS != null) {
    if (ELROS.Sim.SimulationRunning) {
      ELROS.Sim.SetRedrawTiming();
      ELROS.PositionControl_NonCP(false);
    }
    if (ELROS.PGover != null) {
        mainPaintBoxRefresh();
    }
  }
}

public void pD2T(D2T p) {
  print(p.x);
  print(":");
  println(p.y);
}
// ELROS\u672c\u4f53\uff1aC++(Windows)\u304b\u3089\u306e\u79fb\u690d
// \u30af\u30e9\u30b9\u540d\u306a\u3069\u306e\u547d\u540d\u898f\u5247\u304c\u6ec5\u8336\u82e6\u8336\u3067\u3059\u306e\u3067\u53c2\u8003\u306b\u3057\u306a\u3044\u3067\u4e0b\u3055\u3044

class TRobotConfig {
  int    LinkNumber;             // \u30ea\u30f3\u30af\u6570 (1,2,3)
  float  L1_Length, L2_Length, L3_Length;    // [m]
  float  L1_Width,  L2_Width,  L3_Width;     // [m]
  float  J1_Radius, J2_Radius, J3_Radius;    // [m]
  TRobotConfig() {
    LinkNumber = 3;
    L1_Length = L2_Length = L3_Length = 1.0f;
    J1_Radius = J2_Radius = J3_Radius = 0.1f;
    L1_Width = J1_Radius;
    L2_Width = J2_Radius;
    L3_Width = J3_Radius;
  }
}

class TWorld {
  float  PixelRatio;         // [Pixel/m]
  float  OrgX, OrgY;         // [%], 0[%]\uff5e100[%]
  int    WindowX, WindowY;   // WindowSize [Pixel]
  int    OriginX, OriginY;   // Origin [Pixel]
  int    Layer;              // \u63cf\u753b\u3059\u308b\u30ec\u30a4\u30e4\u30fc\uff080, 1, 2,...)
  protected int _Depth = 1;  // \u30ec\u30a4\u30e4\u30fc\u306e\u6df1\u3055

  TWorld() {
    PixelRatio  = 200.0f;
    OrgX        = 50.0f;
    OrgY        = 90.0f;
    Layer       = 0;
    WindowX = width;
    WindowY = height;
  }
  public void ReCalc() {
    OriginX = (int)((OrgX / 100) * WindowX);
    OriginY = (int)((OrgY / 100) * WindowY);
  }
  public int RealToWinX(float x0) {
    float x;
    x = x0 * PixelRatio + OriginX;
    return (int)x;
  }
  public int RealToWinY(float y0) {
    float y;
    y = -y0 * PixelRatio + OriginY;
    return (int)y;
  }
  public float WinToRealX(int x0) {
    float x;
    x = (x0 - OriginX) / PixelRatio;
    return x;
  }
  public float WinToRealY(int y0) {
    float y;
    y = -(y0 - OriginY) / PixelRatio;
    return y;
  }
}

class TRobotController {
  D2T   Ptarget = new D2T();         // \u76ee\u6a19\u306e\u30ed\u30dc\u30c3\u30c8\u306e\u624b\u5148\u5ea7\u6a19 [m]
  float theta11, theta21, theta31;   // \u76ee\u6a19\u306e\u30ed\u30dc\u30c3\u30c8\u306e\u76f8\u5bfe\u95a2\u7bc0\u89d2\u5ea6 [rad]
  D2T   TipVt = new D2T();           // \u624b\u5148\u306e\u76ee\u6a19\u901f\u5ea6\u30d9\u30af\u30c8\u30eb [m/s]
  // \u4f4d\u7f6e\u5236\u5fa1\u7528\u30d1\u30e9\u30e1\u30fc\u30bf
  float	omega1,  omega2,  omega3;    // \u73fe\u5728\u306e\u5404\u95a2\u7bc0\u306e\u89d2\u901f\u5ea6 [rad/s]
  float	omegad1, omegad2, omegad3;   // \u73fe\u5728\u306e\u5404\u95a2\u7bc0\u306e\u89d2\u52a0\u901f\u5ea6 [rad/s^2]
  D2T   TipV = new D2T();            // \u73fe\u5728\u306e\u624b\u5148\u306e\u901f\u5ea6\u3068\u52a0\u901f\u5ea6 [m/s], [m/s^2]
  D2T   TipA = new D2T();
  float Vmax, Amax;                  // \u624b\u5148\u4f4d\u7f6e\u306e\u901f\u5ea6\u5236\u9650\u3068\u52a0\u901f\u5ea6\u5236\u9650 [m/s], [m/s^2]
  float  allowableError;             // [m]

  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  TRobotController() {
    Vmax = 1.0f;  // 1[m/s]
    Amax = 5.0f;  // 5[m/s^2]
    allowableError = 0.001f;  // 1[mm]
    ResetRC();
  }
  // \u30ed\u30dc\u30c3\u30c8\u306e\u5236\u5fa1\u72b6\u614b\u3092\u30ea\u30bb\u30c3\u30c8
  public void ResetRC() {
    omega1  = omega2  = omega3  = 0.0f;  // \u73fe\u5728\u306e\u89d2\u901f\u5ea6
    omegad1 = omegad2 = omegad3 = 0.0f;  // \u73fe\u5728\u306e\u89d2\u52a0\u901f\u5ea6
    TipV.x  = TipV.y  = 0.0f;            // \u73fe\u5728\u306e\u624b\u5148\u306e\u901f\u5ea6
    TipA.x  = TipA.y  = 0.0f;            // \u73fe\u5728\u306e\u624b\u5148\u306e\u52a0\u901f\u5ea6
    TipVt.x = TipVt.y = 0.0f;            // \u624b\u5148\u306e\u76ee\u6a19\u901f\u5ea6\u30d9\u30af\u30c8\u30eb
  }
}

// \u30ed\u30dc\u30c3\u30c8\u5168\u4f53\u306e\u30af\u30e9\u30b9
class TRobot {
  TRobotController	RC;
  TRobotConfig    	RobotConfig;
  D2T 	Pj1, Pj2, Pj3, Pj4;         	// \u73fe\u5728\u306e\u30ed\u30dc\u30c3\u30c8\u306e\u95a2\u7bc0\u4f4d\u7f6e [m]
  float theta1, theta2, theta3;         // \u73fe\u5728\u306e\u30ed\u30dc\u30c3\u30c8\u306e\u76f8\u5bfe\u95a2\u7bc0\u89d2\u5ea6 [rad]
  D2T 	Pj10, Pj20, Pj30, Pj40;     	// \u8ecc\u9053\u8868\u793a\u958b\u59cb\u6642\u306e\u30ed\u30dc\u30c3\u30c8\u306e\u95a2\u7bc0\u4f4d\u7f6e [m]
  float theta10, theta20, theta30;      // \u8ecc\u9053\u8868\u793a\u958b\u59cb\u6642\u306e\u30ed\u30dc\u30c3\u30c8\u306e\u76f8\u5bfe\u95a2\u7bc0\u89d2\u5ea6 [rad]
  float theta1r, theta2r, theta3r;      // \u8a18\u61b6\u3057\u305f\u30ed\u30dc\u30c3\u30c8\u306e\u76f8\u5bfe\u95a2\u7bc0\u89d2\u5ea6 [rad]
  // \u30e4\u30b3\u30d3\u884c\u5217
  Tm22  J22;
  Tm33  J23;

  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  TRobot() {
    RC           = new TRobotController();
    RobotConfig  = new TRobotConfig();
    Pj1  = new D2T();
    Pj2  = new D2T();
    Pj3  = new D2T();
    Pj4  = new D2T();
    Pj10 = new D2T();
    Pj20 = new D2T();
    Pj30 = new D2T();
    Pj40 = new D2T();
    J22  = new Tm22();
    J23  = new Tm33();
    theta1  = radians(60.0f);
    theta2  = radians(30.0f);
    theta3  = radians(30.0f);
    theta10 = theta1;
    theta20 = theta2;
    theta30 = theta3;
    ReCalc();
  }
  public void CalcJ22() {
    J22.m[0][0] = - RobotConfig.L1_Length * sin(theta1) - RobotConfig.L2_Length * sin(theta1 + theta2);
    J22.m[0][1] = - RobotConfig.L2_Length * sin(theta1 + theta2);
    J22.m[1][0] =   RobotConfig.L1_Length * cos(theta1) + RobotConfig.L2_Length * cos(theta1 + theta2);
    J22.m[1][1] =   RobotConfig.L2_Length * cos(theta1 + theta2);
  }
  public void CalcJ23() {
    float  s1, s12, s123;
    float  c1, c12, c123;
    float  l1, l2, l3;
    s1 = sin(theta1);	s12 = sin(theta1 + theta2);	s123 = sin(theta1 + theta2 + theta3);
    c1 = cos(theta1);	c12 = cos(theta1 + theta2);	c123 = cos(theta1 + theta2 + theta3);
    l1 = RobotConfig.L1_Length;	l2 = RobotConfig.L2_Length;	l3 = RobotConfig.L3_Length;
    J23.m23.m[0][0] = -l1 * s1 - l2 * s12 - l3 * s123;
    J23.m23.m[0][1] = -l2 * s12 -l3 * s123;
    J23.m23.m[0][2] = -l3 * s123;
    J23.m23.m[1][0] =  l1 * c1 + l2 * c12 + l3 * c123;
    J23.m23.m[1][1] =  l2 * c12 + l3 * c123;
    J23.m23.m[1][2] =  l3 * c123;
  }
  // \u9806\u904b\u52d5\u5b66\u306e\u518d\u8a08\u7b97
  public void ReCalc() {
    Pj1.x = Pj1.y = 0.0f;
    Pj2.x = Pj1.x + RobotConfig.L1_Length * cos(theta1);
    Pj2.y = Pj1.y + RobotConfig.L1_Length * sin(theta1);
    Pj3.x = Pj2.x + RobotConfig.L2_Length * cos(theta1 + theta2);
    Pj3.y = Pj2.y + RobotConfig.L2_Length * sin(theta1 + theta2);
    Pj4.x = Pj3.x + RobotConfig.L3_Length * cos(theta1 + theta2 + theta3);
    Pj4.y = Pj3.y + RobotConfig.L3_Length * sin(theta1 + theta2 + theta3);
    Pj10.x = Pj10.y = 0.0f;
    Pj20.x = Pj10.x + RobotConfig.L1_Length * cos(theta10);
    Pj20.y = Pj10.y + RobotConfig.L1_Length * sin(theta10);
    Pj30.x = Pj20.x + RobotConfig.L2_Length * cos(theta10 + theta20);
    Pj30.y = Pj20.y + RobotConfig.L2_Length * sin(theta10 + theta20);
    Pj40.x = Pj30.x + RobotConfig.L3_Length * cos(theta10 + theta20 + theta30);
    Pj40.y = Pj30.y + RobotConfig.L3_Length * sin(theta10 + theta20 + theta30);
    CalcJ22();
    CalcJ23();
  }
  // \u73fe\u5728\u4f4d\u7f6e\u306e\u8a18\u61b6
  public void SetOriginalPosture() {
    theta10 = theta1;
    theta20 = theta2;
    theta30 = theta3; 
  }
  public void RestoreOriginalPosture() {
    theta1 = theta10;
    theta2 = theta20;
    theta3 = theta30;
    ReCalc();
  }
  // \u73fe\u5728\u306e\u30ea\u30f3\u30af\u5148\u7aef\u5ea7\u6a19
  public D2T TipPosition() {
    switch (RobotConfig.LinkNumber) {
      case 1 : return Pj2;
      case 2 : return Pj3;
    }
    return (Pj4);
  }
  // \u521d\u671f\u306e\u30ea\u30f3\u30af\u5148\u7aef\u5ea7\u6a19
  public D2T TipPosition0() {
    switch (RobotConfig.LinkNumber) {
      case 1 : return Pj20;
      case 2 : return Pj30;
    }
    return (Pj40);
  }
  // \u4f4d\u7f6e\u5236\u5fa1\u95a2\u9023
  // \u4f4d\u7f6e\u8aa4\u5dee
  public float PositionError() {
    float dx, dy;
    D2T   Ptip = new D2T();

    Ptip = TipPosition();
    dx = Ptip.x - RC.Ptarget.x;
    dy = Ptip.y - RC.Ptarget.y;
    return (sqrt(dx*dx + dy*dy));
  }
}

class TDisplay {
  boolean Trajectory;
  boolean Strobo;
  D2T     LP;      // \u6700\u5f8c\u306b\u7dda\u3092\u5f15\u3044\u305f\u5ea7\u6a19\uff08\u7d42\u70b9\uff09\uff0c\u3042\u308b\u3044\u306fMoveto\u3057\u305f\u70b9
  D2T     LPo;     // \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u30ec\u30a4\u30e4\u30fc\u7528
  D2T     Trj;     // \u8ecc\u8de1\u306e\u7d42\u70b9
  TDisplay() {
    Trajectory  = false;
    Strobo      = false;
    LP          = new D2T();
    LPo         = new D2T();
    Trj         = new D2T();
  }
  public void setTrj(D2T Tip) { Trj.x = Tip.x; Trj.y = Tip.y; }
  public void setLP(float x, float y)  { LP.x  = x; LP.y  = y; }
  public void setLPo(float x, float y) { LPo.x = x; LPo.y = y; }
}

class textInfoClass {
  String J1_Label,  J2_Label,  J3_Label;   // \u73fe\u5728\u306e\u4f4d\u7f6e\uff08\u95a2\u7bc0\u89d2\u5ea6\uff09
  String J10_Label, J20_Label, J30_Label;  // \u521d\u671f\u4f4d\u7f6e\uff08\u95a2\u7bc0\u89d2\u5ea6\uff09
  String J11_Label, J21_Label, J31_Label;  // \u76ee\u6a19\u4f4d\u7f6e\uff08\u95a2\u7bc0\u89d2\u5ea6\uff09
  String Tx_Label,  Ty_Label;              // \u73fe\u5728\u4f4d\u7f6e\uff08\u624b\u5148\uff09
  String Tx0_Label, Ty0_Label;             // \u521d\u671f\u4f4d\u7f6e\uff08\u624b\u5148\uff09
  String Tx1_Label, Ty1_Label;             // \u76ee\u6a19\u4f4d\u7f6e\uff08\u624b\u5148\uff09
  String PositionError_Label;              // \u76ee\u6a19\u4f4d\u7f6e\u3068\u73fe\u5728\u4f4d\u7f6e\u306e\u5dee
  String TV_Label;                         // \u624b\u5148\u5ea7\u6a19\u306e\u901f\u5ea6
  String SimulationTime_Label;             // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u7d4c\u904e\u6642\u9593
  String ErrorMessage;                     // \u7279\u7570\u59ff\u52e2\u767a\u751f\uff0c\u306a\u3069
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  textInfoClass() {
    J1_Label  = J2_Label  = J3_Label  = "";
    J10_Label = J20_Label = J30_Label = "none";
    J11_Label = J21_Label = J31_Label = "none";
    Tx_Label  = Ty_Label  = "";
    Tx0_Label = Ty0_Label = "none";
    Tx1_Label = Ty1_Label = "none";
    PositionError_Label   = "none";
    TV_Label              = "none";
    SimulationTime_Label  = "0.0 [s]";
    ErrorMessage = "";
  }
  public void setErrorMessage(String str) { ErrorMessage = str; }
  public void resetErrorMessage()         { ErrorMessage = ""; }
  // \u5e38\u306b\u8868\u793a\u66f4\u65b0
  public void displayTextInfo() {
    int  x = 45, y = 0;
    // \u73fe\u5728\u5024
    crowbar._write(x, y++, "\u3010\u73fe\u5728\u5024\u3011");
    crowbar._write(x, y++, "\u7b2c\u4e00\u95a2\u7bc0\uff1a" + J1_Label);
    crowbar._write(x, y++, "\u7b2c\u4e8c\u95a2\u7bc0\uff1a" + J2_Label);
    if (ELROS.LinkNumber() == 3) {
      crowbar._write(x, y++, "\u7b2c\u4e09\u95a2\u7bc0\uff1a" + J3_Label);
    }
    crowbar._write(x, y++, "\u624b\u5148\u4f4d\u7f6e\uff1a(" + Tx_Label + "," + Ty_Label + ")");
    y++;
    // \u521d\u671f\u4f4d\u7f6e
    crowbar._write(x, y++, "\u3010\u521d\u671f\u4f4d\u7f6e\u3011");
    crowbar._write(x, y++, "\u7b2c\u4e00\u95a2\u7bc0\uff1a" + J10_Label);
    crowbar._write(x, y++, "\u7b2c\u4e8c\u95a2\u7bc0\uff1a" + J20_Label);
    if (ELROS.LinkNumber() == 3) {
      crowbar._write(x, y++, "\u7b2c\u4e09\u95a2\u7bc0\uff1a" + J30_Label);
    }
    crowbar._write(x, y++, "\u624b\u5148\u4f4d\u7f6e\uff1a(" + Tx0_Label + "," + Ty0_Label + ")");
    y++;
    // \u76ee\u6a19\u4f4d\u7f6e
    crowbar._write(x, y++, "\u3010\u76ee\u6a19\u4f4d\u7f6e\u3011");
    crowbar._write(x, y++, "\u7b2c\u4e00\u95a2\u7bc0\uff1a" + J11_Label);
    crowbar._write(x, y++, "\u7b2c\u4e8c\u95a2\u7bc0\uff1a" + J21_Label);
    if (ELROS.LinkNumber() == 3) {
      crowbar._write(x, y++, "\u7b2c\u4e09\u95a2\u7bc0\uff1a" + J31_Label);
    }
    crowbar._write(x, y++, "\u624b\u5148\u4f4d\u7f6e\uff1a(" + Tx1_Label + "," + Ty1_Label + ")");
//  if (ELROS.Sim.SimulationRunning) {
      y++;
      crowbar._write(x, y++, "\uff08\u5236\u5fa1\u60c5\u5831\uff09");
      crowbar._write(x, y++, "\u624b\u5148\u901f\u5ea6\uff1a" + TV_Label);
      crowbar._write(x, y++, "\u4f4d\u7f6e\u8aa4\u5dee\uff1a" + PositionError_Label);
      crowbar._write(x, y++, "\u7d4c\u904e\u6642\u9593\uff1a" + SimulationTime_Label);
//  }
    if (ErrorMessage.length() > 0) crowbar._write(x, y++, ErrorMessage);
    
    // \u30d5\u30e9\u30b0\u8868\u793a
    x = 0; y = 0;
    crowbar._write(x, y++, "\u3010\u753b\u9762\u8868\u793a\u8a2d\u5b9a\u3011");
    crowbar._write(x, y++, "[T] \u8ecc\u8de1\u8868\u793a\u3000\u3000\uff1a" + (ELROS.Display.Trajectory ? "\u3059\u308b" : "\u3057\u306a\u3044"));
    crowbar._write(x, y++, "[S] \u30b9\u30c8\u30ed\u30dc\u8868\u793a\uff1a" + (ELROS.Display.Strobo     ? "\u3059\u308b" : "\u3057\u306a\u3044"));
    crowbar._write(x, y++, "[H] \u4e2d\u65ad");
    crowbar._write(x, y++, "[ESC] \u7d42\u4e86");

    // \u64cd\u4f5c\u8aac\u660e
    x = 0; y = 38;
    crowbar._write(x, y++, "\uff08\u624b\u52d5\u64cd\u4f5c\uff09\uff1a\u95a2\u7bc0\uff11 [Z][X]\uff0c\u95a2\u7bc0\uff12 [C][V]\uff0c\u95a2\u7bc0\uff13 [B][N]");
    crowbar._write(x, y++, "\uff08\u81ea\u52d5\u52d5\u4f5c\uff09\uff1a\u30de\u30a6\u30b9\u5de6\u30af\u30ea\u30c3\u30af \u76ee\u6a19\u5024\u8a2d\u5b9a\uff0c[SPACE] \u4f4d\u7f6e\u5236\u5fa1");

   // \u30b3\u30d4\u30fc\u30e9\u30a4\u30c8
   x = 43; y = 38;
   crowbar._write(x, y++, "ELROS(Easy Link RObot Simulator)");
   crowbar._write(x, y++, "by T.Shirai(@tatsuva) 2012/04/25");
  }
}

class TSim {
  boolean  SimulationRunning;
  boolean  RedrawTiming;
  float    RunningTime;			// \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u958b\u59cb\u5f8c\u306e\u7a4d\u7b97\u6642\u9593
  float    RunningCycleTime;		// \u753b\u9762\u518d\u63cf\u753b\u307e\u3067\u306b\u884c\u3046\u6642\u9593\uff08\u3053\u306e\u7a4d\u7b97\u6642\u9593\u304cRedrawInterval\u3092\u8d85\u3048\u305f\u3089\u4e00\u6642\u505c\u6b62)
  float    KeyStep;        		// \u30ad\u30fc\u5165\u529b\u6642\u306e\u95a2\u7bc0\u89d2\u5ea6\u5909\u5316\u306e\u523b\u307f [deg]
  char     J1P, J1M, J2P, J2M, J3P, J3M;      // \u30ad\u30fc\u5272\u5f53
  boolean  TargetTeached;       // \u76ee\u6a19\u4f4d\u7f6e\u8a2d\u5b9a\u6e08\u307f\uff08\u624b\u52d5\u64cd\u4f5c\u3067\u30ea\u30bb\u30c3\u30c8\uff09
  float    SamplingTime;	// [s]
  float    RedrawInterval;	// [s]

  int      status = 0;          // 0: Initialize, 1: Running 2: Finishing
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  TSim() {
    KeyStep = 1.0f;          // [deg]
    J1P = 'Z';  J1M = 'X';
    J2P = 'C';  J2M = 'V';
    J3P = 'B';  J3M = 'N';
    TargetTeached = false;
    SamplingTime = 0.001f;	// 1[ms]
    // \u753b\u9762\u518d\u63cf\u753b\u9593\u9694\u306e\u8a2d\u5b9a
    RedrawInterval = 1.0f / frameRate;
    SimulationRunning = RedrawTiming = false;
  }
  // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u958b\u59cb
  public void SimulationStart() {
    // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u7d4c\u904e\u6642\u9593\u306e\u30af\u30ea\u30a2
    RunningTime = RunningCycleTime = 0.0f;
    // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u4e2d\u30d5\u30e9\u30b0\u306e\u30bb\u30c3\u30c8
    SimulationRunning = true;
    // \u72b6\u614b\u7ba1\u7406\u306e\u30ea\u30bb\u30c3\u30c8
    status = 0;
  }
  // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u7d42\u4e86\uff08\u304a\u3088\u3073\u5f37\u5236\u7d42\u4e86\uff09
  public void SimulationStop() {
    // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u4e2d\u30d5\u30e9\u30b0\u306e\u30ea\u30bb\u30c3\u30c8
    SimulationRunning = false;
    // \u72b6\u614b\u7ba1\u7406
    status = 0;
  }
  public void ResetRedrawTiming() {
    RedrawTiming = false;
    RunningCycleTime = 0.0f;
  }
  public void SetRedrawTiming() {
    RedrawTiming = true;
  }
}

// \u30b7\u30b9\u30c6\u30e0\u7d71\u62ec
class TELROS {
  TWorld          World;
  TRobot          Robot;
  TDisplay        Display;
  TSim            Sim;
  textInfoClass   TextInfo;
  PGraphics       targetLayer;
  PGraphics       PGover;
  // \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf
  TELROS() {
    World    = new TWorld();
    Robot    = new TRobot();
    Display  = new TDisplay();
    Sim      = new TSim();
    TextInfo = new textInfoClass();
    targetLayer = null;
    PGover   = createGraphics(World.WindowX, World.WindowY, P2D);  // Overlay
  }
  public int LinkNumber() { return (Robot.RobotConfig.LinkNumber); }
  public boolean IsOneLink() {
    if (Robot.RobotConfig.LinkNumber == 1) return true;
    return false;
  }
  public boolean IsTwoLink() {
    if (Robot.RobotConfig.LinkNumber == 2) return true;
    return false;
  }
  public boolean IsThreeLink() {
    if (Robot.RobotConfig.LinkNumber == 3) return true;
    return false;
  }
  // \u30ec\u30a4\u30e4\u30fc
  public void overlayLayer(boolean layer) {
    if (layer) targetLayer = PGover;
      else     targetLayer = null;
  }
  public void BeginDraw(boolean layer) {
    overlayLayer(layer);
    if (targetLayer != null) targetLayer.beginDraw();
  }
  public void EndDraw() {
    if (targetLayer != null) targetLayer.endDraw();
  }

  // Canvas\u3078\u306e\u63cf\u753b\u547d\u4ee4
  public void Line(float x1, float y1, float x2, float y2) {
    _line(World.RealToWinX(x1), World.RealToWinY(y1), World.RealToWinX(x2), World.RealToWinY(y2));
  }
  public void LineTo(float x1, float y1) {
    _lineTo(World.RealToWinX(x1), World.RealToWinY(y1));
  }
  public void MoveTo(float x1, float y1) {
    _moveTo(World.RealToWinX(x1), World.RealToWinY(y1));
  }
  public void Circle(float x, float y, float r) {
    int xc, yc, rc;
    xc = World.RealToWinX(x);
    yc = World.RealToWinY(y);
    rc = PApplet.parseInt(r * World.PixelRatio);
    _circle(xc, yc, rc);
  }
  public void PenColor(int c) {
    if (targetLayer != null) targetLayer.stroke(c);
      else                   stroke(c);
  }
  public void PenWidth(int w) {
    if (targetLayer != null) targetLayer.strokeWeight(w);
      else                   strokeWeight(w);
  }
  public void _noFill() {
    if (targetLayer != null) targetLayer.noFill();
      else                   noFill();
  }
  public void clrscr() {
    if (targetLayer != null) {
      targetLayer.background(0xff000000, 0);     // \u80cc\u666f\u8272
      targetLayer.fill(crowbar.textColor);    // \u5857\u308a\u3064\u3076\u3057\u8272
    } else {
      background(crowbar.backgroundColor);    // \u80cc\u666f\u8272
      fill(crowbar.textColor);                // \u5857\u308a\u3064\u3076\u3057\u8272
    }
  }
  public void _line(float x1, float y1, float x2, float y2) {
    if (targetLayer != null) {
      targetLayer.line(x1, y1, x2, y2);
      Display.setLPo(x2, y2);
    } else {
      line(x1, y1, x2, y2);
      Display.setLP(x2, y2);
    }
  }
  public void _lineTo(float x1, float y1) {
    if (targetLayer != null) {
      targetLayer.line(Display.LPo.x, Display.LPo.y, x1, y1);
      Display.setLPo(x1, y1);
    } else {
      line(Display.LP.x, Display.LP.y, x1, y1);
      Display.setLP(x1, y1);
    }
  }
  public void _moveTo(float x1, float y1) {
    if (targetLayer != null) Display.setLPo(x1, y1);
      else                   Display.setLP(x1, y1);
  }
  public void _circle(float x, float y, float r) {
    if (targetLayer != null) {
      targetLayer.ellipse(x, y, r * 2, r * 2);
      Display.setLPo(x, y);
    } else {
      ellipse(x, y, r * 2, r * 2);
      Display.setLP(x, y);
    }
  }
  // \u30ea\u30f3\u30af\u306e\u56db\u89d2\u3092\u63cf\u304f
  public void LinkBox(float x1, float y1, float x2, float y2, float LW) {
    D2T  P1, P2, P3, P4;
    float angle;   // [rad]

    P1 = new D2T();
    P2 = new D2T();
    P3 = new D2T();
    P4 = new D2T();
    angle = atan2(y2 - y1, x2 - x1) + (HALF_PI);
    P1.x = P3.x = LW * cos(angle);
    P2.x = P4.x = - P1.x;
    P1.y = P3.y = LW * sin(angle);
    P2.y = P4.y =- P1.y;
    P1.x += x1; P1.y += y1;
    P2.x += x1; P2.y += y1;
    P3.x += x2; P3.y += y2;
    P4.x += x2; P4.y += y2;
    Line(P1.x, P1.y, P2.x, P2.y);
    LineTo(P4.x, P4.y);
    LineTo(P3.x, P3.y);
    LineTo(P1.x, P1.y);
  }
  // \u30ed\u30dc\u30c3\u30c8\u306e\u63cf\u753b
  public void DrawRobotStrobo() {
    DrawRobot(true);
  }
  // \u80cc\u666f\u753b\u9762\uff1a false, \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u753b\u9762\uff08\u30b9\u30c8\u30ed\u30dc\uff09\uff1a true
  public void DrawRobot(boolean layer) {
    overlayLayer(false);
    Robot.ReCalc();
    DrawAxis();
    BeginDraw(layer);
    // \u95a2\u7bc0
    PenColor(0xff000000);
    _noFill();
    Circle(Robot.Pj1.x, Robot.Pj1.y, Robot.RobotConfig.J1_Radius);
    if (LinkNumber() >= 2) {
      Circle(Robot.Pj2.x, Robot.Pj2.y, Robot.RobotConfig.J2_Radius);
      if (LinkNumber() >= 3) {
        Circle(Robot.Pj3.x, Robot.Pj3.y, Robot.RobotConfig.J3_Radius);
      }
    }
    // \u30ea\u30f3\u30af
    PenColor(0xffff0000);
    Line(Robot.Pj1.x, Robot.Pj1.y, Robot.Pj2.x, Robot.Pj2.y);
    LinkBox(Robot.Pj1.x, Robot.Pj1.y, Robot.Pj2.x, Robot.Pj2.y, Robot.RobotConfig.L1_Width);
    if (LinkNumber() >= 2) {
      Line(Robot.Pj2.x, Robot.Pj2.y, Robot.Pj3.x, Robot.Pj3.y);
      LinkBox(Robot.Pj2.x, Robot.Pj2.y, Robot.Pj3.x, Robot.Pj3.y, Robot.RobotConfig.L2_Width);
      if (LinkNumber() >= 3) {
        Line(Robot.Pj3.x, Robot.Pj3.y, Robot.Pj4.x, Robot.Pj4.y);
        LinkBox(Robot.Pj3.x, Robot.Pj3.y, Robot.Pj4.x, Robot.Pj4.y, Robot.RobotConfig.L3_Width);
      }
    }
    EndDraw();
  }
  // xy\u8ef8\u3092\u63cf\u753b
  public void DrawAxis() {
    BeginDraw(false);
    PenColor(0xff000000);
    line(0, World.OriginY, World.WindowX, World.OriginY);
    line(World.OriginX, 0, World.OriginX, World.WindowY);
    EndDraw();
  }
  public void DrawTrajectory() {
    D2T	Ptip;

    Ptip = Robot.TipPosition();
    if (Ptip.Sub(ELROS.Display.Trj).Norm() > 0.0f) {
      BeginDraw(true);
      PenColor(0xff0000ff);
      Line(ELROS.Display.Trj.x, ELROS.Display.Trj.y, Ptip.x, Ptip.y);
      EndDraw();
      ELROS.Display.setTrj(Ptip);
    }
  }
  // \u76ee\u6a19\u4f4d\u7f6e\u306e\u5341\u6587\u5b57\u63cf\u753b\uff0b\u76f4\u7dda\u8ecc\u9053\u63cf\u753b
  public void TargetBullet() {
    int X, Y;
    D2T	Ptip;

    BeginDraw(true);
    // \u5341\u6587\u5b57\u63cf\u753b
    X = World.RealToWinX(Robot.RC.Ptarget.x);
    Y = World.RealToWinY(Robot.RC.Ptarget.y);
    PenColor(0xff00ff00);
    _line(X - 20, Y, X + 20, Y);
    _line(X, Y - 20, X, Y + 20);
    _noFill();
    _circle(X, Y, 10);
    // \u76f4\u7dda\u8ecc\u9053\u63cf\u753b
    Ptip = Robot.TipPosition();
    Line(Robot.RC.Ptarget.x, Robot.RC.Ptarget.y, Ptip.x, Ptip.y);
    EndDraw();
  }

  // \u4f4d\u7f6e\u5236\u5fa1\u95a2\u9023
  // \u4f4d\u7f6e\u5236\u5fa1\u672c\u4f53(\u8ecc\u9053\u5236\u5fa1\u306a\u3057, Vmax\u3067\u79fb\u52d5)
  public void PositionControl_NonCP(boolean JointConstraint) {
    Tm33    InvJ32 = new Tm33();
    Tm22    InvJ22 = new Tm22();
    String  str;

    if (LinkNumber() == 1) return;
    if (Sim.status == 0) {
      // \u30ed\u30dc\u30c3\u30c8\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\uff08\u73fe\u5728\u306e\u72b6\u614b\uff09\u306e\u30ea\u30bb\u30c3\u30c8
      Robot.RC.ResetRC();
      Sim.SimulationStart();
      Sim.status++;
      return;
    } else if (Sim.status == 1) {
//    println(Robot.PositionError());
      while (Sim.RunningCycleTime <= Sim.RedrawInterval) {
        if (Sim.SimulationRunning == false) return;
        if (Robot.PositionError() < Robot.RC.allowableError) {
          Sim.status++;
          break;
        }
        // \u76ee\u6a19\u901f\u5ea6\u30d9\u30af\u30c8\u30eb\u306e\u30bb\u30c3\u30c8
        Robot.RC.TipVt = Robot.RC.Ptarget.Sub(Robot.TipPosition()).Unit().Scale(Robot.RC.Vmax);
        if (LinkNumber() == 2) {
          return;
        } else if (LinkNumber() == 3) {
          Robot.ReCalc();
          Robot.CalcJ23();
          InvJ32.m32 = Robot.J23.Inv();
          if (InvJ32.m32.InvError == true) {
            // \u7279\u7570\u59ff\u52e2\u767a\u751f
            ELROS.TextInfo.setErrorMessage("\u7279\u7570\u59ff\u52e2\u304c\u767a\u751f\u3057\u307e\u3057\u305f\uff0e");
            Robot.theta2 += 0.01f;
            Robot.ReCalc();
            Sim.status++;
            break;
          }
          Robot.theta1 += (InvJ32.m32.m[0][0] * Robot.RC.TipVt.x + InvJ32.m32.m[0][1] * Robot.RC.TipVt.y) * Sim.SamplingTime;
          Robot.theta2 += (InvJ32.m32.m[1][0] * Robot.RC.TipVt.x + InvJ32.m32.m[1][1] * Robot.RC.TipVt.y) * Sim.SamplingTime;
          Robot.theta3 += (InvJ32.m32.m[2][0] * Robot.RC.TipVt.x + InvJ32.m32.m[2][1] * Robot.RC.TipVt.y) * Sim.SamplingTime;
        } else {
          return;
        }
        Sim.RunningTime      += Sim.SamplingTime;
        Sim.RunningCycleTime += Sim.SamplingTime;
      }
      Sim.ResetRedrawTiming();
      // \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u4e2d\u306e\u60c5\u5831\u66f4\u65b0
      refreshSimulationInfo();
    } else if (Sim.status == 2) {
//    DrawRobot();
      Sim.SimulationStop();
    }
  }
  // \u76ee\u6a19\u59ff\u52e2\u3067\u306e\u95a2\u7bc0\u89d2\u5ea6\u3092\u4e8b\u524d\u306b\u8abf\u3079\u308b
  public void CalculateTargetPosture() {
    Tm33    InvJ32 = new Tm33();
//    Tm22    InvJ22 = new Tm22();
    D2T	    TipVt;
    String  str;
    boolean InvError = false;

    // \u73fe\u5728\u306e\u59ff\u52e2\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7
    Robot.SetOriginalPosture();

    if (LinkNumber() == 1) return;
    while (Robot.PositionError() > Robot.RC.allowableError) {
      // \u76ee\u6a19\u901f\u5ea6\u30d9\u30af\u30c8\u30eb\u306e\u30bb\u30c3\u30c8
      TipVt = Robot.RC.Ptarget.Sub(Robot.TipPosition()).Unit().Scale(Robot.RC.Vmax);
      if (LinkNumber() == 2) {
/*
        Robot.ReCalc();
        Robot.CalcJ22();
        InvJ22.m22 = Robot.J22.Inv();
        if (InvJ22.m22.InvError == true) {
          TextInfo.setErrorMessage("\u8b66\u544a\uff1a\u7279\u7570\u59ff\u52e2\u304c\u767a\u751f\u3057\u307e\u3059\uff0e");
          break;
        } else {
          Robot.theta1 += (InvJ22.m22.m[0][0] * TipVt.x + InvJ22.m22.m[0][1] * TipVt.y) * Sim.SamplingTime;
          Robot.theta2 += (InvJ22.m22.m[1][0] * TipVt.x + InvJ22.m22.m[1][1] * TipVt.y) * Sim.SamplingTime;
        }
        break;
*/
      } else if (LinkNumber() == 3) {
        Robot.ReCalc();
        Robot.CalcJ23();
        InvJ32.m32 = Robot.J23.Inv();
        if (InvJ32.m32.InvError == true) {
          TextInfo.setErrorMessage("\u8b66\u544a\uff1a\u7279\u7570\u59ff\u52e2\u304c\u767a\u751f\u3057\u307e\u3059\uff0e");
          break;
        } else {
          Robot.theta1 += (InvJ32.m32.m[0][0] * TipVt.x + InvJ32.m32.m[0][1] * TipVt.y) * Sim.SamplingTime;
          Robot.theta2 += (InvJ32.m32.m[1][0] * TipVt.x + InvJ32.m32.m[1][1] * TipVt.y) * Sim.SamplingTime;
          Robot.theta3 += (InvJ32.m32.m[2][0] * TipVt.x + InvJ32.m32.m[2][1] * TipVt.y) * Sim.SamplingTime;
        }
      } else {
        break;
      }
    }
    // \u76ee\u6a19\u89d2\u5ea6\u306e\u4fdd\u5b58
    Robot.RC.theta11 = Robot.theta1;
    Robot.RC.theta21 = Robot.theta2;
    Robot.RC.theta31 = Robot.theta3;
    if (!InvError) {
      // \u30c6\u30ad\u30b9\u30c8\u60c5\u5831\u306e\u66f4\u65b0
      setTargetInfo();
    } else {
      TextInfo.setErrorMessage("\u8b66\u544a\uff1a\u7279\u7570\u59ff\u52e2\u304c\u767a\u751f\u3057\u307e\u3059\uff0e");
    }
    // \u73fe\u5728\u306e\u59ff\u52e2\u3092\u5fa9\u5143
    Robot.RestoreOriginalPosture();
  }
  // \u30c6\u30ad\u30b9\u30c8\u60c5\u5831\u95a2\u4fc2
  // \u73fe\u5728\u306e\u60c5\u5831\uff08\u5e38\u306b\u66f4\u65b0\uff09
  public void refreshTextInfo() {
    D2T      Ptip;
    // \u73fe\u5728\u4f4d\u7f6e
    TextInfo.J1_Label = nf(degrees(Robot.theta1), 0, 1) + " [deg]";
    TextInfo.J2_Label = nf(degrees(Robot.theta2), 0, 1) + " [deg]";
    TextInfo.J3_Label = nf(degrees(Robot.theta3), 0, 1) + " [deg]";
    Ptip = Robot.TipPosition();
    TextInfo.Tx_Label = nf(Ptip.x, 0 , 3) + " [m]";
    TextInfo.Ty_Label = nf(Ptip.y, 0 , 3) + " [m]";
  }
  // \u76ee\u6a19\u89d2\u5ea6\u3068\u4f4d\u7f6e\uff08\u30c6\u30a3\u30fc\u30c1\u76f4\u5f8c\u306e\u307f\uff09
  public void setTargetInfo() {
    D2T  Tp;
    // \u76ee\u6a19\u4f4d\u7f6e
    TextInfo.J11_Label = nf(degrees(Robot.RC.theta11), 0, 1) + " [deg]";
    TextInfo.J21_Label = nf(degrees(Robot.RC.theta21), 0, 1) + " [deg]";
    TextInfo.J31_Label = nf(degrees(Robot.RC.theta31), 0, 1) + " [deg]";
    TextInfo.Tx1_Label = nf(Robot.RC.Ptarget.x, 0, 3) + " [m]";
    TextInfo.Ty1_Label = nf(Robot.RC.Ptarget.y, 0, 3) + " [m]";
    // \u521d\u671f\u4f4d\u7f6e
    TextInfo.J10_Label = nf(degrees(Robot.theta10), 0, 1) + " [deg]";
    TextInfo.J20_Label = nf(degrees(Robot.theta20), 0, 1) + " [deg]";
    TextInfo.J30_Label = nf(degrees(Robot.theta30), 0, 1) + " [deg]";
    Tp = Robot.TipPosition0();
    TextInfo.Tx0_Label = nf(Tp.x, 0 , 3) + " [m]";
    TextInfo.Ty0_Label = nf(Tp.y, 0 , 3) + " [m]";
  }
  // \u30ed\u30dc\u30c3\u30c8\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u66f4\u65b0\u60c5\u5831\uff08\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u4e2d\u306e\u307f\uff09
  public void refreshSimulationInfo() {
    TextInfo.TV_Label             = nf(Robot.RC.TipVt.Norm(), 0, 3) + " [m/s]";
    TextInfo.PositionError_Label  = nf(Robot.PositionError(), 0, 3) + "[m]";
    TextInfo.SimulationTime_Label = nf(Sim.RunningTime, 0, 2) + "[s]";
  }
}

public void FormKeyDown()
{
  float theta10, theta20, theta30;
  char Key;

  Key = str(key).toUpperCase().charAt(0);
  theta10 = ELROS.Robot.theta1;
  theta20 = ELROS.Robot.theta2;
  theta30 = ELROS.Robot.theta3;
  if (Key == ELROS.Sim.J1P) ELROS.Robot.theta1 += radians(ELROS.Sim.KeyStep);
  if (Key == ELROS.Sim.J1M) ELROS.Robot.theta1 -= radians(ELROS.Sim.KeyStep);
  if (Key == ELROS.Sim.J2P) ELROS.Robot.theta2 += radians(ELROS.Sim.KeyStep);
  if (Key == ELROS.Sim.J2M) ELROS.Robot.theta2 -= radians(ELROS.Sim.KeyStep);
  if (Key == ELROS.Sim.J3P) ELROS.Robot.theta3 += radians(ELROS.Sim.KeyStep);
  if (Key == ELROS.Sim.J3M) ELROS.Robot.theta3 -= radians(ELROS.Sim.KeyStep);
  if (Key == ' ') ELROS.PositionControl_NonCP(false);
  if (Key == 'T') {
    // \u8ecc\u8de1\u8868\u793a\u306eOn/Off
    ELROS.Display.Trajectory = !ELROS.Display.Trajectory;
    // \u73fe\u5728\u5024\u3092\u8a18\u9332
    if (ELROS.Display.Trajectory) ELROS.Display.setTrj(ELROS.Robot.TipPosition());
    // \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u753b\u9762\u306e\u6d88\u53bb
    overlayClear();
  }
  if (Key == 'S') {
    // \u30b9\u30c8\u30ed\u30dc\u8868\u793a\u306eOn/Off
    ELROS.Display.Strobo     = !ELROS.Display.Strobo;
    // \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u753b\u9762\u306e\u6d88\u53bb
    overlayClear();
  }
  if ((theta10 != ELROS.Robot.theta1) || (theta20 != ELROS.Robot.theta2) || (theta30 != ELROS.Robot.theta3)) {
      ELROS.Sim.TargetTeached = false;
  }
}

public void TrajectoryClear_SubMeuClick()
{
  D2T  Ptip = new D2T();

  // \u521d\u671f\u59ff\u52e2\u60c5\u5831\u306e\u53ef\u8996\u5316
//  ELROS.VisibleOriginalPosture(true);
  // \u521d\u671f\u59ff\u52e2\u306e\u63cf\u753b
  Ptip = ELROS.Robot.TipPosition();
  ELROS.MoveTo(Ptip.x, Ptip.y);
}

// \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u753b\u9762\u306e\u6d88\u53bb
public void overlayClear()
{
  ELROS.BeginDraw(true);
  ELROS.clrscr();
  ELROS.EndDraw();
}

public void mainPaintBoxMouseDown(int X, int Y)
{
  // \u76ee\u6a19\u4f4d\u7f6e\u306e\u8a2d\u5b9a
  if (mouseButton == LEFT) {
    ELROS.TextInfo.resetErrorMessage();
    ELROS.Robot.RC.Ptarget.x = ELROS.World.WinToRealX(X);
    ELROS.Robot.RC.Ptarget.y = ELROS.World.WinToRealY(Y);
    ELROS.Robot.SetOriginalPosture();

    // \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u753b\u9762\u3092\u6d88\u53bb
    overlayClear();
    // \u5341\u6587\u5b57\u3092\u63cf\u304f
    ELROS.TargetBullet();
    // \u73fe\u5728\u306e\u59ff\u52e2\u3092\u63cf\u304f
    ELROS.DrawRobotStrobo();

    // \u30e2\u30fc\u30c9\u89e3\u9664
    ELROS.Sim.TargetTeached = true;
    // \u76ee\u6a19\u59ff\u52e2\u306e\u7b97\u51fa\u3068\u30c6\u30ad\u30b9\u30c8\u60c5\u5831\u306e\u66f4\u65b0
    ELROS.CalculateTargetPosture();
  }
}

// onPaint()\u30cf\u30f3\u30c9\u30e9\u30fc
public void mainPaintBoxRefresh()
{
  // \u80cc\u666f\u753b\u9762
  ELROS.overlayLayer(false);
  ELROS.clrscr();
  ELROS.DrawRobot(false);
  ELROS.refreshTextInfo();
  ELROS.TextInfo.displayTextInfo();

  // \u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u753b\u9762
  // \u8ecc\u8de1\u8868\u793a
  if (ELROS.Display.Trajectory == true) {
      ELROS.DrawTrajectory();
  }
  // \u30b9\u30c8\u30ed\u30dc\u8868\u793a
  if (ELROS.Display.Strobo == true) {
    ELROS.DrawRobotStrobo();
  }
  blend(ELROS.PGover, 0, 0, ELROS.World.WindowX, ELROS.World.WindowY, 0, 0, ELROS.World.WindowX, ELROS.World.WindowY, BLEND);
}

  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#D4D0C8", "ELROS" });
  }
}
