[chbot] Draw algorithm

Simon Chester simonches at gmail.com
Mon May 16 23:11:33 BST 2011


Finite loops are a bit hard to flowchart-out, but here's some c code:

void DrillHoles(startx, starty){
>
> int xoffset = startx;
> int yoffset = starty;
>
> for (a = 0; a < 2; a++)
> {
> if(a != 0)
> yoffset += 200;
> for (b = 0; b < 3; b++)
> {
> if(b != 0)
> xoffset -= 100;
> for (c = 0; c < 3; c++)
> {
> if(c != 0)
> yoffset += 5;
> for (d = 0; d < 6; d++)
> {
> if(d != 0)
> xoffset -= 5;
> HoleDriller_DrillHole(xoffset, yoffset);
> }
> }
> }
> }
> }


If you want to see what that would look like, go to
http://raphaeljs.com/playground.html and paste this in the box:

var xoffset = 900;
var yoffset = 200;

for (a = 0; a < 2; a++)
{
if(a != 0)
yoffset += 200;
for (b = 0; b < 3; b++)
{
if(b != 0)
xoffset -= 100;
for (c = 0; c < 3; c++)
{
if(c != 0)
yoffset += 5;
for (d = 0; d < 6; d++)
{
if(d != 0)
xoffset -= 5;
console.log("crcl");
paper.circle(xoffset/1.5, yoffset/1.5, 1)
}
}
}
}


--

Simon


On Tue, May 17, 2011 at 8:37 AM, Marshland Engineering <
marshland at marshland.co.nz> wrote:

>  Hi all
>
> I'm a bit stumped with this one. I can't seem to work out the algorithm I
> need.
>
> I need to draw a picture of a bit of computer code.
>
> The verbal description is
>
> 1 Drill a hole
> 2 Repeat step1  5 times, each time adding 5 mm going the left
> 3 Repeat 1 and 2   2 times, each time add 5 mm going up.
>         Now you should have 18 holes.
> 4 Repeat 1 to 3  2 times, each time adding 100 mm to the left
> 5 Repeat  1 to 4  1 times, each time adding 200 mm to the top.
>
> If I have my sums correct, that is 6 sets of 18 holes.
>
> Any suggestions ?
>
> Thanking you
> Wallace Weideman
> Marshland Engineering
> 704 Marshland Road
> Christchurch
> New Zealand
>
> Ph 03 3237449 Fax 03 3235449
> http://www.marshland.co.nz/
>
>
>
>
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Web site: http://kiwibots.org
> Meeting Time and Location uncertain while Science Alive is out of action.
>
> When replying, please edit your Subject line to reflect new content.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ourshack.com/pipermail/chchrobotics/attachments/20110517/e6cafd9d/attachment.htm 


More information about the Chchrobotics mailing list