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 October 16th, 2012, 11:44 PM
jwatkins jwatkins is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 jwatkins User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #2  
Old October 17th, 2012, 12:21 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,839 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 18 h 45 m 47 sec
Reputation Power: 1774
Code:
for ( green = 0 ; green < midpoint ; green++ ) { }
for ( blue = midpoint+1 ; blue < width ; blue++ ) { }
midpoint++;  // for a square 
__________________
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 October 17th, 2012, 05:38 AM
jwatkins jwatkins is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 jwatkins User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #4  
Old October 17th, 2012, 08:59 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,372 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 11 h 39 m 38 sec
Reputation Power: 383
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.

Reply With Quote
  #5  
Old October 17th, 2012, 10:59 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,839 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 18 h 45 m 47 sec
Reputation Power: 1774
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Desperate for help! Creation of image in C

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