The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Desperate for help! Creation of image in C
Discuss Desperate for help! Creation of image in C in the C Programming forum on Dev Shed. Desperate for help! Creation of image in C 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:
|
|
|

October 16th, 2012, 11:44 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 2
Time spent in forums: 20 m 9 sec
Reputation Power: 0
|
|
|
Desperate for help! Creation of image in C
I'm having to write a program for homework using the C language that will create a ppm file. The ppm file must have a diagonal line going from the top left corner to the bottom right corner. On the top of the line, the image must be blue, and under the line, the image must be green. The user of the program will specify the width and height of the ppm image.
I've written a program that will create a ppm image before, except they consisted of horizontal/vertical stripes of color. I am completely stuck on this with the line being diagonal.
Can someone help point me in the right direction? I've got the program to make the top half (top rectangle of the image) one color, and the bottom half (bottom rectangle of the image) another color. I just don't know how to make this line separating the two colors diagonal.
Thank you so much in advance!
|

October 17th, 2012, 12:21 AM
|
 |
Contributed User
|
|
|
|
Code:
for ( green = 0 ; green < midpoint ; green++ ) { }
for ( blue = midpoint+1 ; blue < width ; blue++ ) { }
midpoint++; // for a square
|

October 17th, 2012, 05:38 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 2
Time spent in forums: 20 m 9 sec
Reputation Power: 0
|
|
|
Thank you for your quick reply!
I understand how to divide the image up into rectangular sections. What I'm having trouble with is dividing it into two halves diagonally. The final image needs to be rectangular (dimensions based on user input which I already have the code for) with a diagonal line going from the top left corner to the bottom right corner.
Thank you!
|

October 17th, 2012, 08:59 AM
|
 |
Contributing User
|
|
|
|
You could make a less than table
Code:
i. 8 NB. input lines are indented as a 3 space prompt
0 1 2 3 4 5 6 7
< table i. 8
┌─┬───────────────┐
│<│0 1 2 3 4 5 6 7│
├─┼───────────────┤
│0│0 1 1 1 1 1 1 1│
│1│0 0 1 1 1 1 1 1│
│2│0 0 0 1 1 1 1 1│
│3│0 0 0 0 1 1 1 1│
│4│0 0 0 0 0 1 1 1│
│5│0 0 0 0 0 0 1 1│
│6│0 0 0 0 0 0 0 1│
│7│0 0 0 0 0 0 0 0│
└─┴───────────────┘
|. 'barg'
grab
|. </~ i. 8
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
0 0 0 0 0 1 1 1
0 0 0 0 1 1 1 1
0 0 0 1 1 1 1 1
0 0 1 1 1 1 1 1
0 1 1 1 1 1 1 1
((+:@:=) + |.@:(</~)) i. 8
2 0 0 0 0 0 0 0
0 2 0 0 0 0 0 1
0 0 2 0 0 0 1 1
0 0 0 2 0 1 1 1
0 0 0 0 3 1 1 1
0 0 0 1 1 3 1 1
0 0 1 1 1 1 3 1
0 1 1 1 1 1 1 3
__________________
[code] Code tags[/code] are essential for python code!
Last edited by b49P23TIvg : October 17th, 2012 at 09:02 AM.
|

October 17th, 2012, 10:59 AM
|
 |
Contributed User
|
|
|
|
Quote: | The final image needs to be rectangular (dimensions based on user input which I already have the code for) with a diagonal line going from the top left corner to the bottom right corner. |
So if the rectangle was 20 wide, and 10 high, can you work out how much to increment midpoint by on each iteration of the loop?
This is maths, not programming.
|
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
|
|
|
|
|