Java loop structure

iDunnoiDunno Dallas, Tejas
edited January 2005 in Internet & Media
Hello, i need help on a loop stucture for a java programming i am doing.
Imagine that you have a 20x20 grid and i need to get "fishes" to appear clockwise starting at the top left corner, then going in circles, in a swirl pattern, clockwise.

01 02 03 04 05 06 07 08 09 10
38 39 40 41 42 43 44 45 46 11
37 ****************47 12
36*****************48 13
35*****************49 14
34*****************50 15
33*****************51 16
32********************17
31 *******************18
30********************19
29 28 27 26 25 24 23 22 21 20

and so on
if i could get a basic loop stucture, taht would be good
thanks

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2005
    I cannot think of an easy way to do this. can you give a little more background about the project, or is this a specific problem posed for the class?

    Also, how is it indexed?

    0,0...n,0
    .
    .
    .
    0,m...n,m

    i assume?
  • iDunnoiDunno Dallas, Tejas
    edited January 2005
    yes, it is indexed starting at 0,0 in the upper left and 19,19 at the bottom
  • iDunnoiDunno Dallas, Tejas
    edited January 2005
    woohoo, i figured it out
    thanks anyways!
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2005
    I'd like to see it, for my own curiosity :)
  • iDunnoiDunno Dallas, Tejas
    edited January 2005
           {
                   int a = 0;
                   int b = 0;
                   int c = 1;
                   int color = 1;
                   int z = 0;
                   FishGfx f = new FishGfx(g,20,20,1000);
                   while (z< 10)
                   {
                   for (a=0+z,b=0+z;b< 20-z;b++,c++)
                   f.drawFish(g,a,b,color,String.valueOf(c));
                   color++;
                   if (color ==10)
                   	color = 1;
                   for (a=0+z+1,b=19-z;a<20-z;a++,c++)
                   f.drawFish(g,a,b,color,String.valueOf(c));
                   color++;
                   if (color ==10)
                   	color = 1;
                   for (a=19-z,b=19-z-1;b>= 0+z;b--,c++)
                   f.drawFish(g,a,b,color,String.valueOf(c));
                   color++;
                   if (color ==10)
                   	color = 1;
                   for (a=19-z-1,b=0+z;a> 0+z;a--,c++)
                   f.drawFish(g,a,b,color,String.valueOf(c));
                   color++;
                   if (color ==10)
                   	color = 1;
                   z++;
                   }
                   z=0;
    


    attached are all the files if you want to execute it and see the output
Sign In or Register to comment.