I multiplied the fractional things by 16 to make them integers.
And I got rid of the color zero circle by adding 1 to the circle index.
#include "pokitto.h"
Pokitto::Core game;
int width=110;
int height=88;
int PX_SIZE = 3;
int PY_SIZE = PX_SIZE;
int SUM_THRESHOLD = 10;
const int NUM_CIRCLES = 8;
struct circle{
int x;
int y;
int r;
int vx;
int vy;
};
static circle c[NUM_CIRCLES];
int RandMinMax(int min, int max){
return rand() % max + min;
}
void draw_circles(){
for (int i = 0; i < NUM_CIRCLES; i++) {
c[i].x += c[i].vx;
c[i].y += c[i].vy;
if (c[i].x - c[i].r < 0) {
c[i].vx = +abs(c[i].vx);
}
if (c[i].x + c[i].r > width) {
c[i].vx = -abs(c[i].vx);
}
if (c[i].y - c[i].r < 0) {
c[i].vy = +abs(c[i].vy);
}
if (c[i].y + c[i].r > height) {
c[i].vy = -abs(c[i].vy);
}
game.display.color = i+1;
game.display.drawCircle(c[i].x,c[i].y,c[i].r);
}
// was commented out
for (int x = 0; x < width; x += PX_SIZE) {
for (int y = 0; y < height; y += PY_SIZE) {
int sum = 0;
int closestD2 = 32767;
int closestColor = 0;
for (int i = 0; i < NUM_CIRCLES; i++) {
int dx = x - c[i].x;
int dy = y - c[i].y;
int d2 = dx * dx + dy * dy;
if (d2 != 0) sum += ((c[i].r * c[i].r) * 16) / d2;
if (d2 < closestD2) {
closestD2 = d2;
closestColor = i+1;//[c.red, c.green, c.blue];
}
}
if (sum > SUM_THRESHOLD) {
game.display.color = closestColor;
game.display.fillRectangle(x, y, PX_SIZE, PY_SIZE);
}
}
}
// end commented out
}
int main(){
srand(game.getTime());
for (int i = 0; i < NUM_CIRCLES; i++) {
c[i].x = RandMinMax(0,width);
c[i].y = RandMinMax(0,height);
c[i].r = RandMinMax(5, 10);
c[i].vx = RandMinMax(-2,2);
c[i].vy = RandMinMax(-2,2);
}
game.begin();
game.display.width = width; // full size
game.display.height = height;
game.setFrameRate(60);
game.display.load565Palette(def565palette);
while (game.isRunning()) {
if (game.update()) {
//game.display.drawPixel(x,y,pixel/16);
draw_circles();
}
}
return 1;
}
#include "pokitto.h"
Pokitto::Core game;
int width=110;
int height=88;
int PX_SIZE = 1;
int PY_SIZE = PX_SIZE;
int SUM_THRESHOLD = 64;
const int NUM_CIRCLES = 6;
struct circle{
int x;
int y;
int r;
int vx;
int vy;
};
static circle c[NUM_CIRCLES];
int RandMinMax(int min, int max){
return rand() % max + min;
}
void draw_circles(){
for (int i = 0; i < NUM_CIRCLES; i++) {
c[i].x += c[i].vx;
c[i].y += c[i].vy;
if (c[i].x - c[i].r < 0) {
c[i].vx = +abs(c[i].vx);
}
if (c[i].x + c[i].r > width) {
c[i].vx = -abs(c[i].vx);
}
if (c[i].y - c[i].r < 0) {
c[i].vy = +abs(c[i].vy);
}
if (c[i].y + c[i].r > height) {
c[i].vy = -abs(c[i].vy);
}
game.display.color = i+1;
game.display.drawCircle(c[i].x,c[i].y,c[i].r);
}
// was commented out
for (int x = 0; x < width; x += PX_SIZE) {
for (int y = 0; y < height; y += PY_SIZE) {
int sum = 0;
int closestD2 = 32767;
int closestColor = 0;
for (int i = 0; i < NUM_CIRCLES; i++) {
int dx = x - c[i].x;
int dy = y - c[i].y;
int d2 = dx * dx + dy * dy;
if (d2 != 0) sum += ((c[i].r * c[i].r) * 64) / d2;
if (d2 < closestD2) {
closestD2 = d2;
closestColor = i+1;//[c.red, c.green, c.blue];
}
}
if (sum > SUM_THRESHOLD) {
game.display.color = closestColor;
game.display.fillRectangle(x, y, PX_SIZE, PY_SIZE);
}
}
}
// end commented out
}
int main(){
srand(game.getTime());
for (int i = 0; i < NUM_CIRCLES; i++) {
c[i].x = RandMinMax(0,width);
c[i].y = RandMinMax(0,height);
c[i].r = RandMinMax(5, 15);
c[i].vx = RandMinMax(-2,2);
c[i].vy = RandMinMax(-2,2);
}
game.begin();
game.display.width = width; // full size
game.display.height = height;
game.setFrameRate(60);
game.display.load565Palette(def565palette);
while (game.isRunning()) {
if (game.update()) {
//game.display.drawPixel(x,y,pixel/16);
draw_circles();
}
}
return 1;
}
Thatās definitely need it . I thought out out using floats without thinking about performance or optimization. Thereās a lot of room for it. Thanks for test it!
message me if you want me to test that on the real hardware. lots of particle stuff, would be interesting to know the performance. also, if its code you do not want to be seen in public yet, I will delete it after testing