Skip to content

Instantly share code, notes, and snippets.

@menixator
Last active June 20, 2019 16:24
Show Gist options
  • Save menixator/74075b6c170faa78021f15ea52a1b3ca to your computer and use it in GitHub Desktop.
Save menixator/74075b6c170faa78021f15ea52a1b3ca to your computer and use it in GitHub Desktop.
#include "MicroBit.h"
#include <vector>
using namespace std;
#define MAX_X 5
#define MAX_Y 2
#define MAX_HEIGHT 3
#define MAX_COUNT 5
// Initialize the wrapper
MicroBit mbit;
MicroBitImage
image;
int main() {
mbit.init();
vector<int> *stacks[MAX_X];
for (int i = 0; i < MAX_X; i++) {
stacks[i] = new vector<int>();
}
while (1) {
for (int i = 0; i < MAX_X; i++) {
stacks[i]->clear();
stacks[i]->push_back(1);
}
for (int i = 0; i < MAX_COUNT; i++) {
int column;
do {
column = mbit.random(MAX_X);
} while (stacks[column]->size() >= MAX_HEIGHT);
stacks[column]->push_back(1);
}
for (int i = 0; i < MAX_X; i++) {
vector<int> *ptr = stacks[i];
for (int j = 0; j < (int)ptr->size(); j++) {
image.setPixelValue(i, j, 1);
}
}
mbit.display.image.paste(image);
mbit.sleep(3000);
image.clear();
}
release_fiber();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment