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...
Please show code.
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 | |
3 | for(loop 1) { |
4 | vertical; |
5 | for(loop 2) { |
6 | horizontal; |
7 | } |
8 | } |
9 | |
10 | //Un-nested: |
11 | |
12 | for(loop 1) { |
13 | vertical; |
14 | } |
15 | for(loop 2) { |
16 | horizontal; |
17 | } |
thanks for your reply guys & here is my code thanks inadvance for ur helps...
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?
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++ ..
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]
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:
then did two loops for height & width that incremented by 10 & assigned them to 1
Heh, well spotted. So OP can't write and work from his own specs?
Thanks a lot :O.. now I got it & it is working excellent....
appreciate all ur help;D...
No worries.
[edit]
took out greedy part of comment
[/edit
An 'optimisation' to make it cleaner:
Instead of i=i+10, use i += 10