#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include "primlib.h"
/* - Program Definition - */
#define PEG 3
#define BLOCK 11
int drawPeg();
int drawBlock();
/* - Program Body - */
int main(void)
{
drawPeg();
SDL_Delay(1000);
drawBlock();
SDL_Delay(3000);
return 0;
}
/* - Function Drawing Peg's - */
int drawPeg(void)
{
int tempWidth;
int tempHeight;
int loopCount = 1;
if (initGraph()) exit(1);
filledRect(0, 0, screenWidth()-1, screenHeight()-1, BLACK);
do{
tempWidth = screenWidth()/(PEG+1);
tempWidth = tempWidth * loopCount;
tempHeight = screenHeight()/(BLOCK+1);
filledRect(tempWidth-2, tempHeight, tempWidth+2, screenHeight()-30, RED);
loopCount++;
SDL_Delay(50);
}while(loopCount < (PEG+1));
updateScreen();
return 1;
}
/* - Function Drawing Block's - */
int drawBlock(void)
{
/* 0 Stand for no block, 1 biggest, 2 smaller etc */
int pegBlock[PEG][BLOCK];
int setup = 0;
int firstLoop = 1;
int secondLoop = 1;
int blockLocX;
int blockWidth = 0;
int blockLocY;
int blockHeight = screenHeight()/(BLOCK +1);
/* - Fill the first Peg with Blocks - */
for(setup = 0; setup < BLOCK; setup++)
{
pegBlock[0][setup] = BLOCK - setup;
}
if (initGraph()) exit(1);
filledRect(0, 0, screenWidth()-1, screenHeight()-1, BLACK);
do{
do{
blockLocX = screenWidth()/(PEG+1);
blockLocX = blockLocX * firstLoop;
blockLocY = screenHeight()/(BLOCK+1);
blockLocY = blockLocY * secondLoop;
blockHeight = blockHeight / 10;
blockWidth = (pegBlock[firstLoop][secondLoop] * 2) + 2;
if(pegBlock[firstLoop][secondLoop] != 0)
{
filledRect(blockLocX - blockWidth, blockLocY - blockHeight, blockLocX + blockWidth, blockLocY + blockHeight, BLUE);
}
secondLoop++;
}while(secondLoop < (BLOCK+1));
firstLoop++;
}while(firstLoop < (PEG+1));
updateScreen();
return 1;
}