drawing a stick man

This is a discussion on drawing a stick man within the C Programming forums, part of the General Programming Boards category; Hi, This is a part of my project where i have drawn a stick man. As you can see in ...

  1. #1
    Registered User
    Join Date
    Dec 2005

    drawing a stick man

    This is a part of my project where i have drawn a stick man. As you can see in the code that i have used constants like (radius *2) etc to draw hand ,leg, head etc to draw the stick man. I am just wondering if it is considered a good programming practice or is there any other way around to accomplish the same task-just more eloquently.

    Please keep in mind that i am quite a newbie and only familiar with functions and arrays and some other basic stuff. Have not reached to the "pointers" yet.


    circle((int)x_position, (int)y_position, (int)radius);		//head
    			line((int)x_position,(int)(y_position + radius),(int)x_position,(int)(y_position + (radius*4)));	//body
    			line((int)(x_position-(radius*2)),(int)(y_position+(radius*2)),(int)(x_position+(radius*2)),(int)(y_position+(radius*2)));	//hand
    			line((int)x_position,(int)(y_position+(radius*4)),(int)(x_position+radius),(int)(y_position+(radius*5)));		//right leg
    			line((int)x_position,(int)(y_position+(radius*4)),(int)(x_position-radius),(int)(y_position+(radius*5)));		//left leg
    			line((int)0,(int)(y_position+(radius*5)),(int)640,(int)(y_position+(radius*5)));	// ground

  2. #2
    Join Date
    Aug 2002
    Tucson, Arizona
    Well I am confused why you are doing all those casts other than that it looks ok.
    Last edited by prog-bman; 12-25-2005 at 03:07 PM.

  3. #3
    Registered User
    Join Date
    Dec 2005
    do not worry about casting. As i said it is part of a project where stick man throws a projectile and if i use int then it will be funny path- not exactly like a parabola. Since those functions can only take int values.

    Yes this code is working but i just wanna know if there is any efficient way to do it. I am thinking of skipping those constants somehow...

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    First of all, let me guess, your screen is 640x480. Second, 640 is already an int, you don't need to cast it.
    See above.
    ((int)x_position,(int)(y_position + radius),
    You only need those casts if the variables concernced aren't ints.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 06:09 PM
  2. casting - pointer to pointer
    By terminator in forum C Programming
    Replies: 56
    Last Post: 04-23-2008, 01:54 AM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  4. we of the cage
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 08-21-2002, 11:14 AM
  5. Gender Humour Thread
    By stevey in forum A Brief History of Cprogramming.com
    Replies: 39
    Last Post: 06-01-2002, 02:12 PM

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