Hallo zusammen, bin neu hier und hoffe, dass ich die Fragen am richtigen Ort stelle...ich bin Anfänger und lerne grade JAVA. Bei einer Aufgabe komme ich leider nicht weiter. Ich hoffe ihr könnt mir helfen.
Ich soll eine Pyramide aus Rechtecken bauen, bei dem die Farbe unten rot ist und von Ebene zu Ebene verblasst, also von dunkel zu hell rot quasi...
Die Aufgabenstellung:
First, write a method that returns the color to be used for a given layer out of a given number of total layers:
public Color layerColor(int layerIndex, int numberOfLayers) {
// Implement this method
Second, write a method that draws a given layer of the pyramid by creating and adding the appropriate rectangles:
public void drawLayer(int layerIndex, int numberOfLayers, Color layerColor) {
// Implement this method
}
Third, use the run() method such that it uses the two new methods to draw the pyramid. In particular, the run() method should not do anything itself to calculate layer colors, and should not instantiate any GRect objects or call the add(...) method.
so soll es aussehen..
Der User soll nach der Anzahl der Rechtecke im Fundament gefragt werden, bevor die Pyramide gebaut wird.
Ich habe versucht das nach meinem Wissen zu lösen, jedoch weiß ich nicht wie die Pyramide ausgeben soll und auch nicht wie ich die ausgegeben Rechtecke einfärbe.
Ich bin mir sicher, dass im Code auch einige Fehler sein sollten, daher würde ich mich über Tipps/Denkanstöße sehr freuen!
Vielen Dank im Voraus!
Ich soll eine Pyramide aus Rechtecken bauen, bei dem die Farbe unten rot ist und von Ebene zu Ebene verblasst, also von dunkel zu hell rot quasi...
Die Aufgabenstellung:
First, write a method that returns the color to be used for a given layer out of a given number of total layers:
public Color layerColor(int layerIndex, int numberOfLayers) {
// Implement this method
Second, write a method that draws a given layer of the pyramid by creating and adding the appropriate rectangles:
public void drawLayer(int layerIndex, int numberOfLayers, Color layerColor) {
// Implement this method
}
Third, use the run() method such that it uses the two new methods to draw the pyramid. In particular, the run() method should not do anything itself to calculate layer colors, and should not instantiate any GRect objects or call the add(...) method.
Der User soll nach der Anzahl der Rechtecke im Fundament gefragt werden, bevor die Pyramide gebaut wird.
Ich habe versucht das nach meinem Wissen zu lösen, jedoch weiß ich nicht wie die Pyramide ausgeben soll und auch nicht wie ich die ausgegeben Rechtecke einfärbe.
Ich bin mir sicher, dass im Code auch einige Fehler sein sollten, daher würde ich mich über Tipps/Denkanstöße sehr freuen!
Vielen Dank im Voraus!
Java:
import java.awt.Color;
import acm.program.GraphicsProgram;
import acm.graphics.GRect;
public class hhh extends GraphicsProgram {
public void layerColor(int layerIndex, int numberOfLayers) {
int Bricks = readInt ("Enter Bricks: ");
Bricks = numberOfLayers;
Color layerColor = new Color (255, 0, 0);
while (numberOfLayers > 0) {
for (layerIndex = 0; layerIndex <= numberOfLayers; layerIndex++) {
Color OtherColor = new Color (220/(numberOfLayers-1));
}}}
public void drawLayer(int layerIndex, int numberOfLayers, Color layerColor) {
for (int i = layerIndex; layerIndex < numberOfLayers; i++) {
for (int j = 0; j<numberOfLayers; j++); {
final int BRICK_WIDTH = 30
final int BRICK_HEIGHT = 12;
double x = (BrickWidth*i);
double y = (BrickHeight*j);
GRect bricks = new GRect (x,y, 10.5, 5);
bricks.setFilled (true);
bricks.setFillColor (layerColor);
add(bricks);
}}}