スポンサーリンク

Processing

Processingでオブジェクト指向プログラミング

投稿日:

Processingでオブジェクト指向プログラミング、classをうまく使える様になりたいので何度も初歩的なことを繰り返す。

Processingベース側

Circle c1,c2,c3,c6;

void setup(){
  size(400,400);
  smooth();
  noStroke();
  fill(0);
  
  
  //オブジェクトの生成
  c1 = new Circle(100,10,1.0);
  c2 = new Circle(300,40,4.5);
  c3 = new Circle(50,80,2.5);
  c6 = new Circle(380,90,2.5);
}

void draw(){
  background(255); //背景色
  
  c1.update();
  c1.display();
  
  c2.update();
  c2.display();

  c3.update();
  c3.display();

  c6.update();
  c6.display();
}

Processingcircleクラス側

下記、class構文

//circleクラスの宣言
class Circle{
  float xPos,yPos,eSize,speed;  
  Circle(float _y, int _eSize, float _speed){
     xPos = 0.0; //x座標の初期値
     yPos = _y;  //y座標の初期値はオブジェクトを宣言した際の引数
     eSize = _eSize;
     speed = _speed;
  }

  void update(){
  xPos += speed;
  if(xPos>width){
    xPos = 0;
    }  
  }
  void display(){
     ellipse(xPos,yPos,eSize,eSize); //円を描く
  }
}

cn.を増やしていけばどんどんcircleを書いていくことができる。
Class構文の基本かな?

Originally posted 2015-12-09 01:11:57.

スポンサーリンク

-Processing
-, ,

Copyright© office606 , 2023 All Rights Reserved Powered by STINGER.