Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to creat a mesh bar image in c++

This thread is locked; no one can reply to it. rss feed Print
How to creat a mesh bar image in c++
helwa_1
Member #8,008
November 2006

I created a 2D array called it image_1; then did two loops for height & width that incremented by 10 & assigned them to 1. But the image doesn't show as bar image just a black image.. Any advice how to create a bare mesh image...

Johan Peitz
Member #9
April 2000
avatar

Please show code.

--
johan peitz :: things I made

James Stanley
Member #7,275
May 2006
avatar

You should do clear_to_color(your background colour), before the for loop, and, unless you use 8 bit graphics you should assign them to makecol(red, green, blue). If you are using 8 bit graphics you should check what is in palette position 1.

EDIT:
You did put a spot or draw a line at the specified position, I assume. And yeah, code would help.

Also, make sure that the loops aren't nested inside each other else it will slow it down and might cause your problem.

1//Nested:
2 
3for(loop 1) {
4 vertical;
5 for(loop 2) {
6 horizontal;
7 }
8}
9 
10//Un-nested:
11 
12for(loop 1) {
13 vertical;
14}
15for(loop 2) {
16 horizontal;
17}

helwa_1
Member #8,008
November 2006

thanks for your reply guys & here is my code thanks inadvance for ur helps...

Johan Peitz
Member #9
April 2000
avatar

Here is the code you posted: (you can use code tags to show itin your post (check out the mockup link))

// after I created 2D array
// just intialize the image to zero
for (i=0; i< width; i++){
    for (j=0; j<height; j++){
        out_image[j]<i>=0;
    }
}

for (i=0; i< width; i=i+50){
    for (j=0; j<height; j=j+50){
        out_image[j]<i>=1;
    }
}

In all honesty, I don't really know what you're trying to achieve. The code above does nothing except setting every 50 pixel in an array to 1.

If you want to place dots on a bitmap, you'd have to do something like this:

BITMAP *bmp;
bmp = create_bitmap(640, 480); // or whatever size
clear_to_color(bmp, makecol(0, 0, 0)); // makes it all black
for (i=0; i< width; i=i+50){
    for (j=0; j<height; j=j+50){
        putpixel(bmp, j, i, makecol(255, 255, 255)); // makes the pixel white
    }
}
blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp-h);  // show image on screen

Or are you trying to do something else?

--
johan peitz :: things I made

helwa_1
Member #8,008
November 2006

Thanks for ur tips but I am not quite sure if this is the answer of my qs cause I am trying to draw a mesh bar image so, all I was trying to make the background =0 & the bars in horizontal & vertical =1( as a white color or verse versa). I did similar thing in matlab & worked out greatly but in C++ didn't work( I am just a new programmer in C++). & all I am getting just verticals lines with the dark dots in the crossing lines .In ur code, when u made background =0 why u used 3 parameters (0, 0, 0)??? & does of each command u used should I create a function for it.. excuse me, my qs might seem dump but as I mentioned just beginner person in using C++ ::)..

HardTranceFan
Member #7,317
June 2006
avatar

From reading this thread, it appears the helwa_1 wants to have a mesh with lines every 50 pixels. James Stanely's pseudo code is a start to what helwa_1 is attempting to achieve.

Here's some untested hybrid code based on James's pseudo code and John's code :

BITMAP *bmp;
bmp = create_bitmap(640, 480); // or whatever size
clear_to_color(bmp, makecol(0, 0, 0)); // makes it all black

// Vertical lines
for (i=0; i< width; i=i+50)
  vline(bmp, i, 0, bmp->h, makecol(255, 255, 255));

// Horizontal lines
for (j=0; j<height; j=j+50)
  hline(bmp, 0, j, bmp->w, makecol(255, 255, 255));    }

blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp-h);  // show image on screen

[edit]
The 3 parameters are the red, green and blue values of the colour. See the manual for details.
[/edit]

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

LennyLen
Member #5,313
December 2004
avatar

Quote:

From reading this thread, it appears the helwa_1 wants to have a mesh with lines every 50 pixels.

Actually, I think he wants them every 10 pixels, based on this line:

Quote:

then did two loops for height & width that incremented by 10 & assigned them to 1

HardTranceFan
Member #7,317
June 2006
avatar

Heh, well spotted. So OP can't write and work from his own specs?

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

helwa_1
Member #8,008
November 2006

Thanks a lot :O.. now I got it & it is working excellent....
appreciate all ur help;D...

HardTranceFan
Member #7,317
June 2006
avatar

No worries.

[edit]
took out greedy part of comment
[/edit

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

James Stanley
Member #7,275
May 2006
avatar

An 'optimisation' to make it cleaner:
Instead of i=i+10, use i += 10

Go to: