|
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
|
Please show code. -- |
James Stanley
Member #7,275
May 2006
|
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: Also, make sure that the loops aren't nested inside each other else it will slow it down and might cause your problem.
|
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
|
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? -- |
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
|
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] -- |
LennyLen
Member #5,313
December 2004
|
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
|
Heh, well spotted. So OP can't write and work from his own specs? -- |
helwa_1
Member #8,008
November 2006
|
Thanks a lot :O.. now I got it & it is working excellent.... |
HardTranceFan
Member #7,317
June 2006
|
No worries. [edit] -- |
James Stanley
Member #7,275
May 2006
|
An 'optimisation' to make it cleaner: |
|