0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VisibleSimで3D Catomの色を変更してみた

Last updated at Posted at 2025-09-20

概要

VisibleSimにはロボットの色を変更するとしてsetColorメソッドが用意されている。
今回は隣接しているロボットの数に応じて色を変えて遊んでみた。

image.png

コード

rキーを押下時に呼び出されるstartup()に処理を追加。
getLocalNeighborhoodStateメソッドを利用して隣接するロボットの数を取得し、隣接数に応じてsetColor()で色を変更する。

void LightWalkCatoms3DBlockCode::startup() {
    stringstream info;
    info << "Starting ";
    int neighborCount = getNeighborsCount();
    if(neighborCount == 0){
        setColor(WHITE);
    }else if(neighborCount == 1){
        setColor(YELLOW);
    }else if(neighborCount == 2){
        setColor(GREEN);
    }else if (neighborCount == 3){
        setColor(BLUE);
    }else if(neighborCount == 4){
        setColor(RED);
    }else if (neighborCount == 5){   
        setColor(PINK);
    }else if (neighborCount == 6){   
        setColor(ORANGE);
    }else if (neighborCount == 7){   
        setColor(MAGENTA);
    }else if (neighborCount == 8){   
        setColor(GOLD);
    }
}
int LightWalkCatoms3DBlockCode::getNeighborsCount() const {
    return catom->getLocalNeighborhoodState().count();
}

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?