Разное о выращивании табака на Алтае
Вы не вошли.
Код.
#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; }
}
}
}
Не в сети
Не в сети