Created
October 29, 2015 22:33
-
-
Save pavelmaca/f48b6ab40bcc3c66b27f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Kresleni { | |
public static int VLEVO = 0; | |
public static int DOLU = 1; | |
public static int VPRAVO = 2; | |
public static int NAHORU = 3; | |
public static void main(String[] arg){ | |
kresleni(10); | |
} | |
public static void kresleni(int velikost) { | |
if (velikost < 2) { | |
System.out.print("Minimální velikost je 2"); | |
return; | |
} | |
int y = velikost; | |
int smer = VPRAVO; | |
int x = 0; | |
int i = 1; | |
while (velikost > 0) { | |
if (smer == VPRAVO) { | |
smer = DOLU; | |
cara(x, y, x + velikost, y); | |
x += velikost; | |
} else if (smer == DOLU) { | |
smer = VLEVO; | |
cara(x, y, x, y - velikost); | |
y -= velikost; | |
} else if (smer == VLEVO) { | |
smer = NAHORU; | |
cara(x, y, x - velikost, y); | |
x -= velikost; | |
} else if (smer == NAHORU) { | |
smer = VPRAVO; | |
cara(x, y, x, y + velikost); | |
y += velikost; | |
} | |
if (i % 2 == 0) { | |
velikost -= 1; | |
} | |
i += 1; | |
} | |
} | |
/** | |
* Robot kreslí čáru od souřadni [x, y] do [x2, y2] | |
*/ | |
public static void cara(int x, int y, int x2, int y2) { | |
System.out.println("Robot kreslí čáru: počátek[x:"+x+", y:"+y+"] konec[x:"+x2+", y:"+y2+"]"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment