當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing . (dot)用法及代碼示例

Processing, . (dot)用法介紹。

用法

  • object.method()
  • object.data

參數

  • object 要訪問的對象
  • method() 封裝在對象中的方法
  • data 封裝在對象中的變量或常量

說明

提供對對象的方法和數據的訪問。對象是類的一個實例,可以包含方法(對象函數)和數據(對象變量和常量),如類定義中所指定。點運算符將程序定向到封裝在對象中的信息。

例子

// Declare and construct two objects (h1 and h2) of the class HLine
HLine h1 = new HLine(20, 1.0);
HLine h2 = new HLine(50, 5.0);

void setup() {
  size(200, 200);
}

void draw() {
  if (h2.speed > 1.0) {  // Dot syntax can be used to get a value
    h2.speed -= 0.01;    // or set a value.
  }
  h1.update();  // Calls the h1 object's update() function
  h2.update();  // Calls the h2 object's update() function
}

class HLine {  // Class definition
  float ypos, speed;  // Data
  HLine (float y, float s) {  // Object constructor
    ypos = y;
    speed = s;
  }
  void update() {  // Update method
    ypos += speed;
    if (ypos > width) {
      ypos = 0;
    }
    line(0, ypos, width, ypos);
  }
}

有關的

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 . (dot)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。