This site requires JavaScript, please enable it in your browser!
Greenfoot back
larry020
larry020 wrote ...

2017/3/21

drawing a rectangular spiral with crosses (for-loop)

larry020 larry020

2017/3/21

#
G'day, I wanna draw a rectangular spiral with a/several for-loop(s) with my Rover. On each field, there shall be a cross which illustrate that. So already have
1
2
3
4
5
6
for(int i=0; i<5;++i) {
for(int j=0;j<1;++j) {
drive();
}
turn("right);
}
Actually, the first time it should drive and turn right, the second time it should drive twice and then turn right and so on. I already had the idea with incrementing after each run, but I don't know how to implement it. Can you help me?
Super_Hippo Super_Hippo

2017/3/21

#
If I get you right, it should be this:
1
2
3
4
5
6
7
int distance = 5;
for (int i=0; i<10; i++)
{
    move(distance);
    distance *= 2;
    turn(90);
}
However, if you actually want to have it visually moving this track, it shouldn't be done in a for loop.
You need to login to post a reply.