#include <iostream>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <stdio.h>
//-------------------------
using namespace std;
//**********************//
int main(int argc, char *argv[])
{
screen(screenW, screenH, 0, "Flood Fill");
clearScreenBuffer(RGB_White);
int mouseX, mouseY;
int oldMouseX, oldMouseY;
bool LMB, RMB;
while(!done())
{
oldMouseX = mouseX;
oldMouseY = mouseY;
getMouseState(mouseX, mouseY, LMB, RMB);
//3 different mouse input actions
if(LMB) paint_drawLine(oldMouseX, oldMouseY, mouseX, mouseY, RGB_Black);
if(RMB)
{
int color = RGBtoINT(ColorRGB((mouseX % 3 + 1) * 64, (mouseY % 8) * 32, (mouseX + mouseY) % 256));
floodFillScanlineStack(mouseX, mouseY, color, screenBuffer[mouseX][mouseY]);
}
if(RMB && LMB) clearScreenBuffer(RGB_White);
//benchmark
readKeys();
if(inkeys[SDLK_SPACE])
{
float startTime = getTime();
for(int i = 1; i < 50; i++) floodFill4Stack(mouseX, mouseY, RGBtoINT(ColorRGB(i,255,i)), screenBuffer[mouseX][mouseY]);
float endTime = getTime();
float startTime2 = getTime();
for(int i = 1; i < 50; i++) floodFillScanlineStack(mouseX, mouseY, RGBtoINT(ColorRGB(i,255,i)), screenBuffer[mouseX][mouseY]);
float endTime2 = getTime();
drawBuffer(screenBuffer[0]);
print(endTime - startTime, 0, 0, 0, RGB_Black, 1, RGB_White);
print(endTime2 - startTime2, 0, 0, 8, RGB_Black, 1, RGB_White);
redraw();
sleep();
}
//redraw the screen each frame
drawBuffer(screenBuffer[0]);
redraw();
}
return 0;
}