The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Help coding a bitmap coordinates counter
Discuss Help coding a bitmap coordinates counter in the C Programming forum on Dev Shed. Help coding a bitmap coordinates counter C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 23rd, 2012, 11:45 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 1 h 13 m
Reputation Power: 0
|
|
|
Help coding a bitmap coordinates counter
hello. My name is Thomas. Happy to stumble onto this forum. I need some help! I am using imagemagick to draw pictures and perform iterative operations on images. my latest idea requires some technical know-how that i just don't possess.
To explain, I need a sort of complex(for me) counting program.
Imagine an image of 1111x1111 pixels. I want to draw from the center outward spirally. pixel by pixel. I dont want to type in every X,Y coordinate. so i'm looking for a ?nested for loop? in C that can count the way i want. like this (sticking with X axis numbers first)
555,556,556,555,554,554,554,555,556,557,557,557,557,556,555,554,553,553,553,553,553,554,555,556,557, 558,558,558,558,558,558,557,556,555,554,553,552,552,552,552,552,552,552 etc. (hope that's enough contextual information.)
once i see how to code it in C. I can take care of the Y axis myself. and i think i should be off and running, using actionaz for help to move numbers around. Really hope someone can spare some moments to help me with this.
Best wishes to you all.
Thomas
|

December 24th, 2012, 02:01 AM
|
 |
Contributed User
|
|
|
|
Consider the following image
The things I notice are
1. Up and left always have the same count
2. Down and right always have the same count
3. The count is 1,2,3
So I imagine some pseudocode looking like this
Code:
int direction = -1 // -1 for up/left, +1 for down/right
int x = 555, y = 555
for ( count = 1 ; count < n ; count++ )
draw(&x,&y,0,direction,count); // up/down
draw(&x,&y,direction,0,count); // left/right
direction = direction * -1;
Where draw() is like
draw ( int *xpos, int *ypos, int xdir, int ydir, int count );
|

December 24th, 2012, 03:25 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 1 h 13 m
Reputation Power: 0
|
|
Salem, thanks for your observation and code ideas!
the math program loop that i imagined happening, is beneath. and I need each calculation result printed.
555(starting number)
LOOP START
add 1
multiply by 1
subtract 1
subtract 1
multiply by 1
multiply by 1
LOOP END
!!each new run through the loop must perform 2 more of each step!!
example:
second run
add 1(3x) multiply by 1(3x) subtract 1(4x) multiply by 1(4x)
third run
add 1(5x) multiply by 1(5x) subtract 1(6x) multiply by 1(6x)
fourth run
add 1(7x) multiply by 1(7x) subtract 1(8x) multiply by 1(8x)
of course multiply by 1 could be simply add 0 just thought using all ones was pretty.
Quote: | Originally Posted by salem Consider the following image
The things I notice are
1. Up and left always have the same count
2. Down and right always have the same count
3. The count is 1,2,3
So I imagine some pseudocode looking like this
Code:
int direction = -1 // -1 for up/left, +1 for down/right
int x = 555, y = 555
for ( count = 1 ; count < n ; count++ )
draw(&x,&y,0,direction,count); // up/down
draw(&x,&y,direction,0,count); // left/right
direction = direction * -1;
Where draw() is like
draw ( int *xpos, int *ypos, int xdir, int ydir, int count );
|
|

December 24th, 2012, 04:29 AM
|
 |
Contributed User
|
|
|
|
So in terms of my pretty picture, the following actions would apply on the following colours?
add 1 => yellow
multiply by 1 => green
subtract 1 => cyan
subtract 1 => cyan
multiply by 1 => blue
multiply by 1 => blue
Perhaps you could do
Code:
for ( count = 1 ; count < n ; count += 2 ) {
draw(&x,&y,0,-1,count,OP1); // up
draw(&x,&y,-1,0,count,OP2); // left
draw(&x,&y,0,+1,count+1,OP3); // down
draw(&x,&y,+1,0,count+1,OP4); // right
}
OPx could be anything to help you decide what to do within the draw function.
Last edited by salem : December 24th, 2012 at 07:59 AM.
|

December 24th, 2012, 12:42 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 1 h 13 m
Reputation Power: 0
|
|
|
I'm really struggling finding any information about the draw function in C. I'm performing the actual drawing in a program called imagemagick. And had just thought of using C to make a counter for coordinates.
|

December 24th, 2012, 12:54 PM
|
 |
Contributed User
|
|
|
|
|

December 24th, 2012, 01:45 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 1 h 13 m
Reputation Power: 0
|
|
|
Salem thanks for sharing these. this is a great looking tool! I've lost so much time as it is struggling with making a seemingly simple math loop in C that I don't feel ready to tackle this. I've got a comfortable, easy way for me, using a bash script to draw my stuff with imagemagick. The real help i could use is just how to make that math LOOP posted about earlier in this thread. Thanks for so much help thus far.
Thomas
|

December 25th, 2012, 01:38 AM
|
 |
Contributed User
|
|
|
|
Consider this as a simple 'draw' function.
Code:
void draw(int *x, int *y, int dx, int dy, int count) {
int i;
for ( i = 0 ; i < count ; i++ ) {
*x += dx;
*y += dy;
printf("X=%d, Y=%d\n", *x, *y );
}
}
This will print out your coordinates.
Now you can change the printf to automatically create your bash command line, say
Code:
printf("imagemagick image.bmp add %d %d 1\n", *x, *y );
|

December 25th, 2012, 02:03 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 1 h 13 m
Reputation Power: 0
|
|
ok i need this in my life! how do i get this functionality in C? i'm not finding any way to get magickwand API which is what i'm assuming i need. please advise. this solution is very compelling.
Quote: | Originally Posted by salem Consider this as a simple 'draw' function.
Code:
void draw(int *x, int *y, int dx, int dy, int count) {
int i;
for ( i = 0 ; i < count ; i++ ) {
*x += dx;
*y += dy;
printf("X=%d, Y=%d\n", *x, *y );
}
}
This will print out your coordinates.
Now you can change the printf to automatically create your bash command line, say
Code:
printf("imagemagick image.bmp add %d %d 1\n", *x, *y );
|
|

December 25th, 2012, 03:09 AM
|
 |
Contributed User
|
|
|
|
Since you mentioned bash script, I assume you're on a Linux system with gcc as the compiler.
Regarding MagickWand, have you tried to download the example wand.c program, compile it, and run it?
If not, you should try it - if you want to progress beyond bash scripting. Just follow the instructions on the web page I posted earlier.
If you get stuck with an error message, then post it here.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|