help me with this c graphics program

This is a discussion on help me with this c graphics program within the C Programming forums, part of the General Programming Boards category; hello i have got a c graphics program of a demonstration of a flying kite.i have to alter this program ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    help me with this c graphics program

    hello
    i have got a c graphics program of a demonstration of a flying kite.i have to alter this program to make a user input of the rope of kite.For example when when the program start it will be asking for a user input length of the rope of the kite.so that we can adjust the height of the kite...please kindly help...

    this is the original program can you please alter this with my requirement
    my requirement is to set a user input for the height of the kite while flying

    Code:
    #include<stdio.h>
    #include<graphics.h>
    #include<alloc.h>
    int main(void)
    {
    void *kite;
    int s,x,y,gd=DETECT,gm,r;
    initgraph(&gd,&gm,"c:\tc");
    setcolor(10);
    moveto(100,100);
    lineto(125,75);
    lineto(150,100);
    lineto(120,130);
    lineto(130,130);
    lineto(125,125);
    lineto(100,100);  //this completes the outline design of kite
    setfillstyle(SOLID_FILL,BLUE);
    floodfill(125,100,10);
    floodfill(125,127,10);
    arc(125,120,40,140,31);
    line(125,125,125,75);
    line(125,110,150,130);
    line(125,94,150,130);
    
    s=imagesize(100,75,150,130);
    kite=(void*)malloc(s);
    
    getimage(100,75,150,130,kite);
    putimage(100,75,kite,XOR_PUT);
    x=100,y=75;
    
    while(!kbhit())
    {
    setcolor(10);
    putimage(x,y,kite,XOR_PUT);
    setcolor(YELLOW);
    line(x+50,y+55,639,479);
    delay(100);
    putimage(x,y,kite,XOR_PUT);
    setcolor(0);
    line(x+50,y+55,639,479);
    
    r=rand();
    
    switch(r%4)
    {
    case 0:x=x+10; break;
    case 1:x=x-10; break;
    case 2:y=y+10; break;
    case 3:y=y-10;break;
    }
    if(x>640) x-=40;
    if(x<40) x+=40;
    if(y>479) y-=40;
    if(y<40) y+=40;
    }
    getch();
    closegraph();
    return 0;
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by arunstar008 View Post
    this is the original program can you please alter this with my requirement
    my requirement is to set a user input for the height of the kite while flying
    Kind of unlikely that someone will do it for you, but we will try and help you do it yourself.

    The most basic way to get user input is with the scanf() or fgets() command. Have you used these before?

    A possible problem here is those commands may not work in conjunction with <graphics.h>. <graphics.h> is an old Borland thing, meaning most people are probably not familiar with it, so if you cannot use scanf(), then you probably need to use some command peculiar to it, but unfortunately finding someone who remembers that stuff may be hard.

    Is the output drawn in the text console, or in a separate window? If it is in a separate window, you can probably use scanf() in a text console where you start the program from.

    Also: PLEASE INDENT YOUR CODE. IT IS MUCH MUCH EASIER TO READ THAT WAY AND SOMETHING WE ASK OF EVERYONE HERE AT CBOARD. For example (and notice, all of this is indended one tabspace already because it is inside main():

    Code:
    	getimage(100,75,150,130,kite);
    	putimage(100,75,kite,XOR_PUT);
    	x=100,y=75;
    
    	while(!kbhit())
    	{
    		setcolor(10);
    		putimage(x,y,kite,XOR_PUT);
    		setcolor(YELLOW);
    		line(x+50,y+55,639,479);
    		delay(100);
    		putimage(x,y,kite,XOR_PUT);
    		setcolor(0);
    		line(x+50,y+55,639,479);
    
    		r=rand();
    
    		switch(r%4)
    		{
    			case 0:x=x+10; break;
    			case 1:x=x-10; break;
    			case 2:y=y+10; break;
    			case 3:y=y-10;break;
    		}
    		if(x>640) x-=40;
    		if(x<40) x+=40;
    		if(y>479) y-=40;
    		if(y<40) y+=40;
    	}
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    actually i am a new one to c program. i am doing this job fro my friend.but for the past few days i started studying C language.can you please help me.can any one written the code for me.i am in a little hurry.note that i am a beginner to the C language ...

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by arunstar008 View Post
    i am in a little hurry.note that i am a beginner to the C language ...
    Okay, well, don't waste any more time then

    Do you know how to use scanf? Here's an example:

    Code:
    #include <stdio.h>
    
    int main(void) {
    	char buffer[64];
    	printf("Enter your name: ");
    	scanf("%63s",buffer);
    	printf("Your name is %s!\n",buffer);
    	return 0;
    }
    Here's some basic documentation for scanf:
    Keyboard Input: scanf()

    See what you can do and feel free to ask more questions.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    i have go through that code....yess ..understanding some thing....so what code i have to input in the original program to adjust the length of the rope of the kite..
    and where i have to input that code

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Edit: removed due to misunderstanding what the OP meant by the height of the kite. I thought he meant dimension, but he meant y axis, on the screen.
    Last edited by Adak; 01-16-2010 at 10:12 AM.

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    i have tried some alteration method in the program but it fails.i am getting mad with that.i have no time also.so can any one rewrite my program to adjust the length of the rope as the given input when running the program

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You might want to try here for that kind of help:
    Rent A Coder: How Software Gets Done -- Home of the worlds' largest number of completed software projects
    Someone there may do that for like $10-20.

    And if this makes you angry and frustrated, I would just give up programming right now. Adak did a great job of trying to show you something...oh well.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    <aside> Is there a lot of homework due tomorrow or something? This is like the third person to just post a demand for homework err help this morning....
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OOOOOHHHH! I mis-understood what you posted.

    You don't have to change the size of the kite, you just have to change the display (y value), height of the kite in the screen, (and of course, the string too).

    That's *much* easier. It's been awhile since i coded in Turbo C graphics, but I can whip something up for you.

    Edit: Change a kite flying program for homework?

    Really? I never got neat homework like that!!

    This is it:

    Code:
    /* press Esc key to quit */
    #include<stdio.h>
    #include<graphics.h>
    #include<alloc.h>
    
    #define UP 0x48
    #define DOWN 0x50
    #define ESC 27
    
    
    int main(void) {
      void *kite;
      int ch, s,x,y,gd=DETECT,gm,r, offy;
      initgraph(&gd,&gm,"c:\tc");
      setcolor(10);
      moveto(100,100);
      lineto(125,75);
      lineto(150,100);
      lineto(120,130);
      lineto(130,130);
      lineto(125,125);
      lineto(100,100);  //this completes the outline design of kite
      setfillstyle(SOLID_FILL,BLUE);
      floodfill(125,100,10);
      floodfill(125,127,10);
      arc(125,120,40,140,31);
      line(125,125,125,75);
      line(125,110,150,130);
      line(125,94,150,130);
     
      s=imagesize(100,75,150,130);
      kite = malloc(s);
      
      getimage(100,75,150,130,kite);
      putimage(100,75,kite,XOR_PUT);
      x=100,y=75;
      offy = 10;
      while(1) {
        setcolor(10);
        putimage(x,y,kite,XOR_PUT);
        setcolor(YELLOW);
        line(x+50,y+55,639,479);
        delay(100);
        putimage(x,y,kite,XOR_PUT);
        setcolor(0);
        line(x+50,y+55,639,479);
    
        r=rand();
      
        switch(r%4) {
          case 0:x=x+10; break;
          case 1:x=x-10; break;
          case 2:y=y+10; break;
          case 3:y=y-10;break;
        }
        
        if(kbhit()) {
          offy=getch();
          if(offy == UP) y -= 30;
          if(offy == DOWN) y+= 30;
          if(offy == ESC) break;
        }
    
        if(x>640) x-=40;
        if(x<40) x+=40;
        if(y>490) y-=40;
        if(y<40) y+=40;
      }
      closegraph();
      return 0;
    }
    Enjoy!
    Last edited by Adak; 01-16-2010 at 10:09 AM.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    thank you adak.i don't know how to thank youuuu....again very very very thanks.....u save me from a big trouble.......god bless you...

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're welcome. Good luck with your kite project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turtle Graphics (debug help)
    By impact201 in forum C Programming
    Replies: 5
    Last Post: 07-14-2006, 01:45 PM
  2. Anybody have a good graphics program and 5 minutes?
    By sean in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-18-2003, 12:26 AM
  3. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  4. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21