Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Question about how-to draw a brick wall with for loops

Author
Message
skeeterz71
11
Years of Service
User Offline
Joined: 13th Jan 2013
Location:
Posted: 28th Feb 2013 04:24 Edited at: 28th Feb 2013 20:23
Figured out my problem with the original post.

This code draws a red brick wall that fills the screen. What I would like to do is stagger the rows. Every other row indented on the right 20 pixels. I can\'t figure it out. Any help would be appreciated.


#include \"DarkGDK.h\"

void DarkGDK ()
{
dbSetDisplayMode(800,600,32);
const int red = dbRGB(255,0,0);
const int black = dbRGB(0,0,0);

for(int x=0; x<=800; x+=40)
{
for(int y=0; y<=600; y+=20)
{
// Draw red bricks with a 1 pixel
// black border around the bricks
dbInk(red,black);
dbBox(x+1,y+1,x+39,y+19);
}
}

// Pause the program until the user presses a key.
dbWaitKey();
}

Over 40 & Back to School
http://www.SkeeterZ71.com
Most Awesome Blog!

Attachments

Login to view attachments
skeeterz71
11
Years of Service
User Offline
Joined: 13th Jan 2013
Location:
Posted: 28th Feb 2013 20:24
Figured out my problem with the original post.

This code draws a red brick wall that fills the screen. What I would like to do is stagger the rows. Every other row indented on the right 20 pixels. I can\'t figure it out. Any help would be appreciated.


#include \"DarkGDK.h\"

void DarkGDK ()
{
dbSetDisplayMode(800,600,32);
const int red = dbRGB(255,0,0);
const int black = dbRGB(0,0,0);

for(int x=0; x<=800; x+=40)
{
for(int y=0; y<=600; y+=20)
{
// Draw red bricks with a 1 pixel
// black border around the bricks
dbInk(red,black);
dbBox(x+1,y+1,x+39,y+19);
}
}

// Pause the program until the user presses a key.
dbWaitKey();
}

Over 40 & Back to School
http://www.SkeeterZ71.com
Most Awesome Blog!

Attachments

Login to view attachments
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 3rd Mar 2013 08:26
First, I would change your for-loops so that the iteration parameter represents what row you're on rather than the pixel position, like this:


This will make it easier to check whether you're on an odd-numbered row, which you can do like this:


You can then add like 20 to the x position of all the bricks on odd rows in the for loop.

Login to post a reply

Server time is: 2024-04-20 14:18:15
Your offset time is: 2024-04-20 14:18:15