#1 08-01-2022 17:14:35

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Эмулятор биологической жизни Конвея.

Код.

#include "fabgl.h"
fabgl::VGAController DisplayController;
fabgl::Canvas        canvas(&DisplayController);
long density = 30;
int polltime;
int life=0;
void setup() {
DisplayController.begin();
DisplayController.setResolution( VGA_640x400_70Hz) ;
canvas.setGlyphOptions(GlyphOptions().FillBackground(false).DoubleWidth(1));
canvas.selectFont(&fabgl::FONT_std_24);
canvas.setPenColor(Color::Red);
canvas.clear();
  canvas.setPenColor(Color::Yellow);
 randomSeed(analogRead(0));
 randomscreen();
 }
void loop() {
 for (int y = 1; y < 399; y++) {
    for (int x = 1; x < 639; x++) {
    if (canvas.getPixel( x ,y)== RGB888(0,255,0)){
    if (canvas.getPixel( x+1 ,y)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x-1 ,y)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x+1 ,y+1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x-1 ,y-1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x ,y+1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x ,y-1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x-1 ,y+1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x+1 ,y-1)== RGB888(0,255,0)) life++;
    if (life>=5 or life==0) canvas.setPixel(x,y,RGB888(0,0,0)); 
     life=0;
    }
   }    
    }
 for (int x = 1; x < 20; x++) {
 canvas.setPixel(random(640),random(400),RGB888(0,0,0));
 }
 //////////////////////////////////////
 for (int y = 1; y < 399; y++) {
    for (int x = 1; x < 639; x++) {
    if (canvas.getPixel( x ,y)== RGB888(0,0,0)){
    if (canvas.getPixel( x+1 ,y)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x-1 ,y)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x+1 ,y+1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x-1 ,y-1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x ,y+1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x ,y-1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x-1 ,y+1)== RGB888(0,255,0)) life++;
    if (canvas.getPixel( x+1 ,y-1)== RGB888(0,255,0)) life++;
  ///////////////////////////////////////////////////////////////
    if (life==3) {canvas.setPixel( x ,y,RGB888(0,255,0));}
    }
     life=0;
    }
    }
}
void randomscreen() {
    for (int y = 1; y < 399; y++) {
    for (int x = 1; x < 639; x++) {
      if (random(1150) < density) canvas.setPixel(x,y,RGB888(0,255,0));//{world[x][y][0] = 1; }
    }
  }
 }

Не в сети

#2 08-01-2022 17:16:02

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: Эмулятор биологической жизни Конвея.

16416369333816805239015612328825.jpg
16416369901933734216830295653166.jpg
16416370539989120143048498649086.jpg
16416372590488791044910634691063.jpg

16416376660306227867013770110122.jpg

Не в сети

Подвал раздела

Работает на FluxBB (перевод Laravel.ru)