C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 23rd, 2012, 11:45 PM
thomas.buckler thomas.buckler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 thomas.buckler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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


Reply With Quote
  #2  
Old December 24th, 2012, 02:01 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
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 );
Attached Images
File Type: png untitled2.png (756 Bytes, 63 views)
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 24th, 2012, 03:25 AM
thomas.buckler thomas.buckler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 thomas.buckler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 );

Reply With Quote
  #4  
Old December 24th, 2012, 04:29 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
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.

Reply With Quote
  #5  
Old December 24th, 2012, 12:42 PM
thomas.buckler thomas.buckler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 thomas.buckler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old December 24th, 2012, 12:54 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
Some links
http://www.imagemagick.org/script/magick-wand.php
http://www.imagemagick.org/script/magick-core.php
C doesn't do graphics, or drawing (or networking or ....) without the support of external libraries.

Whilst this may seem a burden at first, it is useful to know that you're not going to be weighed down with the baggage of what someone else thinks is a good graphics API. You're always free to either do it yourself, or make a choice from all the libraries available.

Reply With Quote
  #7  
Old December 24th, 2012, 01:45 PM
thomas.buckler thomas.buckler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 thomas.buckler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old December 25th, 2012, 01:38 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
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 );

Reply With Quote
  #9  
Old December 25th, 2012, 02:03 AM
thomas.buckler thomas.buckler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 thomas.buckler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 );

Reply With Quote
  #10  
Old December 25th, 2012, 03:09 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help coding a bitmap coordinates counter

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap