Created
November 3, 2010 20:19
-
-
Save H4kor/661644 to your computer and use it in GitHub Desktop.
Herz.java
This file contains 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 Herz{ | |
public static boolean inRaute(double px, double py, double cx, double cy, double b) { | |
double x_abstand = Math.abs(cx - px); | |
double y_abstand = Math.abs(cy - py); | |
if((x_abstand + y_abstand) <= b) | |
return(true); | |
else | |
return(false); | |
} | |
public static boolean inKreis(double px, double py, double cx, double cy, double r) { | |
double dif_x = (cx - px)*(cx - px); | |
double dif_y = (cy - py)*(cy - py); | |
double wurzel = Math.sqrt(dif_x + dif_y); | |
return (wurzel <= r); | |
} | |
public static boolean inHerz(double px, double py, double cx, double cy, double b) { | |
double d = b*0.4; | |
double kreis_links_x = cx - d/2; | |
double kreis_links_y = cy - d/2; | |
double kreis_rechts_x = cx + d/2; | |
double kreis_rechts_y = cy - d/2; | |
if(inRaute(px,py,cx,cy,d) || | |
inKreis(px,py,kreis_links_x,kreis_links_y,d/Math.sqrt(2)) || | |
inKreis(px,py,kreis_rechts_x,kreis_rechts_y,d/Math.sqrt(2)) ) { | |
return true; | |
}else return false; | |
} | |
public static void main(String[] params){ | |
System.out.print("Breite eingeben: "); | |
double durchmesser = IO.readInt(); | |
double cx = durchmesser/2; | |
double cy = durchmesser/2; | |
for(int y = 0; y <= durchmesser; y++) { | |
for(int x = 0; x <= durchmesser; x++) { | |
if(inHerz(x,y*2,cx,cy*2,durchmesser)) { | |
System.out.print("#"); | |
}else{ | |
System.out.print("_"); | |
} | |
} | |
System.out.println(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment