Skip to content

Instantly share code, notes, and snippets.

@pavelmaca
Created October 29, 2015 22:33
Show Gist options
  • Save pavelmaca/f48b6ab40bcc3c66b27f to your computer and use it in GitHub Desktop.
Save pavelmaca/f48b6ab40bcc3c66b27f to your computer and use it in GitHub Desktop.
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