Thread: Printing Shapes

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    18

    Printing Shapes

    Hello, I'm working on this project that takes an input file with 3 shapes, and then prints out the shapes in an x,y list with their RGB values. For some reason, my program is doing something where it checks the x and y values, then reads a shape and sets its RGB values. Then it checks the other shapes and because they aren't in the same place, it just turns it back to black. I need to change this so that it prints all the shapes on the same image. Here is the section of my code. Any help is appreciated; thanks!
    for (y = 0; y < imgHeight; y++){
    for (x = 0; x < imgWidth; x++){
    for (i = 0; i < numShapes; i++) {

    newX = x - xOff[i];
    newY = y - yOff[i];

    if (InObject(shapeLetter[i], newX, newY, arg1[i], arg2[i], arg3[i])){
    PixelPrint(color[i], &r, &g, &b);
    }
    else {
    PixelPrint(0, &r, &g, &b);
    }
    }
    printf("%d %d %d # %d, %d\n", r, g, b, x, y);
    }
    }

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    OK well you're logic is just incorrect.
    You can't just fill a pixel black if it isn't within the first shape. You must only turn it black if it is not within any of the shapes. This implies that you should have a boolean variable that is false initially, and is set to true when you've coloured a pixel. Then once you've looped through all shapes then if that boolean is not true then and only then do you set it to black.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    18
    Thanks for the tip. Although, I'm still a little unclear about exactly which part of the code I would need to change. Should I take out the whole if-else statement, and replace it with something else?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Every shape has it's own x and y, so I don't see why the numShapes for loop, isn't the outermost for loop.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It did take a while to understand initially, but no that much he has right Adak. It's plotting shapes pixel by pixel. It's all very inefficient, but will work with the loops as-is.

    Just forget the outer two for-loops for a moment. Think about what you need to do for just one particular pixel (if say I picked any given pixel at random).
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    18
    So, what it needs to do is cycle through each x and y, testing for InObject for EVERY shape. I'm guessing I need to tweak my if(InObject) statement to check each shape, but I'm not sure how to actually implement this.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    fI I kool ta eht mhtirogla ni a rorrim, ti skool enif.

  8. #8
    Registered User
    Join Date
    Feb 2011
    Posts
    18
    That's not very helpful

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  3. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  4. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM
  5. Program with Shapes using Virtual Functions
    By goron350 in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2005, 01:42 PM