ΠΡ ΡΠΎΠ·Π΄Π°Π΄ΠΈΠΌ ΡΠΈΡΡΠ΅ΠΌΡ, ΠΊΠΎΡΠΎΡΠ°Ρ ΠΏΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈ ΠΌΠ΅Π½ΡΡΡ Π·Π°ΠΊΠΎΠ½Ρ ΡΠΈΠ·ΠΈΠΊΠΈ Π² ΡΠΈΠΌΡΠ»ΠΈΡΠΎΠ²Π°Π½Π½ΠΎΠΉ Π²ΡΠ΅Π»Π΅Π½Π½ΠΎΠΉ!
Π Π΅Π΄Π°ΠΊΡΠΎΡ Π·Π°ΠΊΠΎΠ½ΠΎΠ² ΡΠΈΠ·ΠΈΠΊΠΈ:
cpp
#define UNIVERSE_SIZE 32
// ΠΠ°ΠΊΠΎΠ½Ρ ΡΠΈΠ·ΠΈΠΊΠΈ (ΠΈΠ·ΠΌΠ΅Π½ΡΠ΅ΠΌΡΠ΅ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ)
struct PhysicsLaws {
uint8_t gravity; // 0-255
uint8_t entropy; // 0-255
uint8_t quantumNoise; // 0-255
uint8_t timeFlow; // 0-255
uint8_t consciousness; // 0-255
uint8_t causality; // 0-255 (ΠΏΡΠΈΡΠΈΠ½Π½ΠΎΡΡΡ)
};
PhysicsLaws physics;
uint8_t universe[UNIVERSE_SIZE][UNIVERSE_SIZE];
uint8_t backupUniverse[UNIVERSE_SIZE][UNIVERSE_SIZE];
// ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Ρ Π½Π°ΡΠΈΠΌΠΈ Π·Π°ΠΊΠΎΠ½Π°ΠΌΠΈ ΡΠΈΠ·ΠΈΠΊΠΈ
void initPhysics() {
physics.gravity = 128;
physics.entropy = 100;
physics.quantumNoise = 30;
physics.timeFlow = 255;
physics.consciousness = 0;
physics.causality = 255;
}
// ΠΡΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π·Π°ΠΊΠΎΠ½ΠΎΠ² ΠΊ ΡΠ°ΡΡΠΈΡΠ΅
void applyPhysics(uint8_t x, uint8_t y) {
uint8_t* cell = &universe[x][y];
// ΠΡΠ°Π²ΠΈΡΠ°ΡΠΈΡ (ΠΏΡΠΈΡΡΠΆΠ΅Π½ΠΈΠ΅)
if (physics.gravity > 100) {
// Π§Π°ΡΡΠΈΡΡ ΠΏΡΠΈΡΡΠ³ΠΈΠ²Π°ΡΡΡΡ ΠΊ ΡΠ΅Π½ΡΡΡ
int16_t dx = x - UNIVERSE_SIZE / 2;
int16_t dy = y - UNIVERSE_SIZE / 2;
if (dx * dx + dy * dy > 5) {
uint8_t moveProb = physics.gravity / 50;
if (random(100) < moveProb) {
// ΠΠ΅ΡΠ΅ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅
int8_t mx = (dx > 0) ? 1 : -1;
int8_t my = (dy > 0) ? 1 : -1;
if (x + mx < UNIVERSE_SIZE && y + my < UNIVERSE_SIZE) {
universe[x + mx][y + my] = *cell;
*cell = 0;
}
}
}
}
// ΠΠ½ΡΡΠΎΠΏΠΈΡ (ΡΠ°ΡΠΏΠ°Π΄)
if (physics.entropy > 50 && *cell > 0) {
if (random(100) < physics.entropy / 10) {
*cell = max(0, *cell - 1);
}
}
// ΠΠ²Π°Π½ΡΠΎΠ²ΡΠΉ ΡΡΠΌ (ΡΠ»ΡΠΊΡΡΠ°ΡΠΈΠΈ)
if (physics.quantumNoise > 0) {
if (random(100) < physics.quantumNoise / 10) {
*cell = min(255, *cell + random(-10, 11));
}
}
// ΠΡΠ΅ΠΌΡ (ΡΠΊΠΎΡΠΎΡΡΡ ΡΠ²ΠΎΠ»ΡΡΠΈΠΈ)
if (physics.timeFlow < 255) {
if (random(100) > physics.timeFlow) {
// ΠΡΠ΅ΠΌΡ Π·Π°ΠΌΠ΅Π΄Π»ΡΠ΅ΡΡΡ
*cell = *cell; // ΠΠ°ΠΌΠΎΡΠΎΠ·ΠΊΠ°
}
}
// Π‘ΠΎΠ·Π½Π°Π½ΠΈΠ΅ (Π½Π°Π±Π»ΡΠ΄Π°ΡΠ΅Π»Ρ Π²Π»ΠΈΡΠ΅Ρ Π½Π° ΡΠ΅Π°Π»ΡΠ½ΠΎΡΡΡ)
if (physics.consciousness > 100) {
if (random(100) < physics.consciousness / 10) {
// ΠΡΡΠ΅ΠΊΡ Π½Π°Π±Π»ΡΠ΄Π°ΡΠ΅Π»Ρ
*cell = *cell ^ (1 << (physics.consciousness % 8));
}
}
// ΠΡΠΈΡΠΈΠ½Π½ΠΎΡΡΡ (ΡΠ²ΡΠ·Ρ ΠΌΠ΅ΠΆΠ΄Ρ ΡΠΎΠ±ΡΡΠΈΡΠΌΠΈ)
if (physics.causality < 200) {
if (random(100) < (255 - physics.causality) / 10) {
// ΠΠ°ΡΡΡΠ΅Π½ΠΈΠ΅ ΠΏΡΠΈΡΠΈΠ½Π½ΠΎΡΡΠΈ (ΡΠΎΠ±ΡΡΠΈΡ Π±Π΅Π· ΠΏΡΠΈΡΠΈΠ½Ρ)
*cell = random(256);
}
}
}
// ΠΠ²ΠΎΠ»ΡΡΠΈΡ Π²ΡΠ΅Π»Π΅Π½Π½ΠΎΠΉ
void evolveUniverse() {
// Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΊΠΎΠΏΠΈΡ
memcpy(backupUniverse, universe, sizeof(universe));
// ΠΡΠΈΠΌΠ΅Π½ΡΠ΅ΠΌ Π·Π°ΠΊΠΎΠ½Ρ ΠΊΠΎ Π²ΡΠ΅ΠΌ ΡΠ°ΡΡΠΈΡΠ°ΠΌ
for (uint8_t x = 0; x < UNIVERSE_SIZE; x++) {
for (uint8_t y = 0; y < UNIVERSE_SIZE; y++) {
applyPhysics(x, y);
}
}
}
// ΠΠΈΠ·ΡΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Π²ΡΠ΅Π»Π΅Π½Π½ΠΎΠΉ
void renderUniverse() {
clearScreen();
for (uint8_t x = 0; x < UNIVERSE_SIZE; x++) {
for (uint8_t y = 0; y < UNIVERSE_SIZE; y++) {
uint8_t val = universe[x][y];
if (val > 0) {
uint8_t screenX = x * 2;
uint8_t screenY = y * 2;
if (screenX < 64 && screenY < 64) {
drawPixel(screenX, screenY, val > 100);
}
}
}
}
updateDisplay();
}
// ΠΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π·Π°ΠΊΠΎΠ½ΠΎΠ² ΡΠΈΠ·ΠΈΠΊΠΈ (Π±ΠΎΠΆΠ΅ΡΡΠ²Π΅Π½Π½Π°Ρ ΡΠΈΠ»Π°)
void tweakPhysics() {
// ΠΠ΅Π½ΡΠ΅ΠΌ ΡΠ»ΡΡΠ°ΠΉΠ½ΡΠΉ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡ
uint8_t param = random(6);
int8_t delta = random(-20, 21);
switch (param) {
case 0:
physics.gravity = constrain(physics.gravity + delta, 0, 255);
Serial.print("β‘ ΠΡΠ°Π²ΠΈΡΠ°ΡΠΈΡ: ");
Serial.println(physics.gravity);
break;
case 1:
physics.entropy = constrain(physics.entropy + delta, 0, 255);
Serial.print("β‘ ΠΠ½ΡΡΠΎΠΏΠΈΡ: ");
Serial.println(physics.entropy);
break;
case 2:
physics.quantumNoise = constrain(physics.quantumNoise + delta, 0, 255);
Serial.print("β‘ ΠΠ²Π°Π½ΡΠΎΠ²ΡΠΉ ΡΡΠΌ: ");
Serial.println(physics.quantumNoise);
break;
case 3:
physics.timeFlow = constrain(physics.timeFlow + delta, 0, 255);
Serial.print("β‘ ΠΡΠ΅ΠΌΡ: ");
Serial.println(physics.timeFlow);
break;
case 4:
physics.consciousness = constrain(physics.consciousness + delta, 0, 255);
Serial.print("β‘ Π‘ΠΎΠ·Π½Π°Π½ΠΈΠ΅: ");
Serial.println(physics.consciousness);
break;
case 5:
physics.causality = constrain(physics.causality + delta, 0, 255);
Serial.print("β‘ ΠΡΠΈΡΠΈΠ½Π½ΠΎΡΡΡ: ");
Serial.println(physics.causality);
break;
}
}
void setup() {
initOLED();
Serial.begin(115200);
randomSeed(analogRead(A0));
initPhysics();
// ΠΠ°ΠΏΠΎΠ»Π½ΡΠ΅ΠΌ Π²ΡΠ΅Π»Π΅Π½Π½ΡΡ ΡΠ»ΡΡΠ°ΠΉΠ½ΡΠΌΠΈ ΡΠ°ΡΡΠΈΡΠ°ΠΌΠΈ
for (uint8_t x = 0; x < UNIVERSE_SIZE; x++) {
for (uint8_t y = 0; y < UNIVERSE_SIZE; y++) {
universe[x][y] = random(100) < 30 ? random(256) : 0;
}
}
Serial.println("π ΠΠΠΠΠ‘Π’ΠΠΠΠΠ«Π Π ΠΠΠΠ ΠΠΠ’ΠΠΠΠ ΠΠΠΠ");
Serial.println("ΠΡ ΡΠΏΡΠ°Π²Π»ΡΠ΅ΡΠ΅ Π·Π°ΠΊΠΎΠ½Π°ΠΌΠΈ ΡΠΈΠ·ΠΈΠΊΠΈ!");
}
void loop() {
// ΠΠ²ΠΎΠ»ΡΡΠΈΡ Π²ΡΠ΅Π»Π΅Π½Π½ΠΎΠΉ (10 ΡΠ°Π³ΠΎΠ²)
for (uint8_t step = 0; step < 10; step++) {
evolveUniverse();
}
// ΠΠ½ΠΎΠ³Π΄Π° ΠΌΠ΅Π½ΡΠ΅ΠΌ Π·Π°ΠΊΠΎΠ½Ρ
if (random(100) < 20) {
tweakPhysics();
}
// ΠΠΈΠ·ΡΠ°Π»ΠΈΠ·Π°ΡΠΈΡ
renderUniverse();
delay(100);
}