plotting a 2D tire using functions.

This is a discussion on plotting a 2D tire using functions. within the C Programming forums, part of the General Programming Boards category; ok so heres the code i have so far but the code doesnt really do anything and I cant figure ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    33

    plotting a 2D tire using functions.

    ok so heres the code i have so far but the code doesnt really do anything and I cant figure out
    how to write the function to print the picture out on a rectangle space. help please.

    Code:
    int smlrad,bigrad;
    int line,col;
    int main (){
        
        printf("please enter your small radius.\n");
        scanf("%d",&smlrad);
        printf("please enter your big radius.\n");
        scanf("%d",&bigrad);
        
        
        for(line=-bigrad; line<=+bigrad; line++);{
    for(col=-bigrad; col<=bigrad; col++);{
    if (col^2+line^2<=1)
    printf("+");
    else if (col^2+line^2<=smlrad^2)
    printf("$");
    else if(col^2+line^2<=bigrad^2)
    printf("+");
    }
        
    }   
        
    system("pause");
    return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are using ^ as if it's a "raised to" operator. It is not. C uses ^ to indicate logical exclusive or, which is a bitwise operation.

    For "square" operations, I'd say "x * x" is the right approach. For higher powers, you may want to use a function of some sort.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    33
    The output should look like this. but alligned properly

    *************
    *****************
    *********************
    ***********************
    ***************************
    *********$$$$$$$$$$$*********
    ********$$$$$$$$$$$$$$$********
    *******$$$$$$$$$$$$$$$$$*******
    ******$$$$$$$$$$$$$$$$$$$$$******
    ******$$$$$$$$$$$$$$$$$$$$$$$******
    ******$$$$$$$$$$$$$$$$$$$$$$$******
    ******$$$$$$$$$$$$$$$$$$$$$$$$$******
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    ******$$$$$$$$$$$$$$$$$$$$$$$$$$$******
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$+$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$+++$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$+$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    ******$$$$$$$$$$$$$$$$$$$$$$$$$$$******
    *****$$$$$$$$$$$$$$$$$$$$$$$$$$$*****
    ******$$$$$$$$$$$$$$$$$$$$$$$$$******
    ******$$$$$$$$$$$$$$$$$$$$$$$******
    ******$$$$$$$$$$$$$$$$$$$$$$$******
    ******$$$$$$$$$$$$$$$$$$$$$******
    *******$$$$$$$$$$$$$$$$$*******
    ********$$$$$$$$$$$$$$$********
    *********$$$$$$$$$$$*********
    ***************************
    ***********************
    *********************
    *****************
    *************

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And what does your code produce?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    This can be done via the distance formula which is essentially what has been mentioned.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D in directX
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 01-25-2009, 10:23 AM
  2. Replies: 16
    Last Post: 09-22-2006, 03:39 PM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. 2D arrays with functions made easy
    By goran in forum C Programming
    Replies: 1
    Last Post: 09-17-2001, 12:08 PM

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