DRAWING ROBOT NXT-G (need some help)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: DRAWING ROBOT NXT-G (need some help)

Post by muntoo »

Basic structure of program:
  • Read black & white image file
    • Read header
      • Width
      • Height
  • Read a horizontal line in the image file
    • If pixel is black
      • Make the pen touch the paper
      • Make a rectangular/circular motion (depends on the writing tool)
      • Move pen back up
    • Move motor right by a tiny amount (one pixel)
  • If there is another line, move the motor down one pixel, and back to the left by [width] pixels
  • Go back to the instruction Read a horizontal... until all lines have been read
In C, this is something like:

Code: Select all

ReadFileHeader("filename.pic", &width, &height);

for(y = 0; y < height; ++y)
{
    for(x = 0; x < width; ++x)
    {
        if(ReadFileNextByte() == BLACK)
        {
            MovePen(DOWN);
            MoveHand(CIRCLE_MOTION);
            MovePen(UP);
        }
        
        MoveHand(RIGHT, 1);
    }
    
    MoveHand(LEFT, width);
    MoveHand(DOWN, 1);
}
What happens in that program is: you determine the width and height of the image (Line 1); loop through each horizontal line (Line 3); loop through each pixel (Line 5); draw the pixel if it is black (Line 7); and move the hand holding the pen into the proper positions.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests