001package bitmap;
002
003import javafx.application.Application;
004import javafx.scene.Scene;
005import javafx.scene.canvas.Canvas;
006import javafx.scene.canvas.GraphicsContext;
007import javafx.scene.image.PixelWriter;
008import javafx.scene.layout.Pane;
009import javafx.scene.paint.Color;
010import javafx.stage.Stage;
011
012/**
013 * This is an experiment with bit-mapped graphics.
014 * 
015 * You may include HTML in your Javadoc comments.
016 * 
017 * <h1>Section Title</h1>
018 * 
019 * Here is an enumerated list.
020 * <ol>
021 * <li> int </li>
022 * <li> double </li>
023 * <li> boolean </li>
024 * </ol>
025 * 
026 * <h2>Subsection Title</h2>
027 * 
028 * Here is an itemized list.
029 * <ul>
030 * <li> for loop </li>
031 * <li> enhanced for loop (for-each loop) </li>
032 * <li> while loop </li>
033 * <li> if statement </li>
034 * <li> switch statement </li>
035 * </ul>
036 * 
037 * <p>
038 * To learn more about the man who led the
039 * team that created the Java programming language,
040 * take a look at 
041 * <a href="https://en.wikipedia.org/wiki/James_Gosling">
042 * this article on Wikipedia.
043 * </a>
044 * </p>
045 * 
046 * <p>
047 * The University of Minnesota is the home
048 * of an archive that holds documents related to the
049 * history of computing.
050 * It is the Charles Babbage Institute.
051 * </p>
052 * 
053 * <img src="https://upload.wikimedia.org/wikipedia/commons/d/d1/Elmer_Andersen_Library_Minnesota_5.jpg"
054 * alt="Charles Babbage Institute"
055 * width=384>
056 * 
057 * <p>
058 * This photograph is
059 * by AlexiusHoratius (Own work) [CC BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0) or GFDL (http://www.gnu.org/copyleft/fdl.html)], via Wikimedia Commons
060 * </p>
061 * 
062 * @author Your Name
063 * @version 21 March 2018
064 */
065public class Bitmap extends Application {
066
067    private static final int WIDTH = 512;
068    private static final int HEIGHT = 512;
069
070    @Override
071    public void start(Stage stage) {
072        stage.setTitle("Bitmap");
073
074        Canvas canvas = new Canvas(WIDTH, HEIGHT);
075        GraphicsContext gc = canvas.getGraphicsContext2D();
076
077        Pane root = new Pane();
078
079        root.getChildren().add(canvas);
080
081        PixelWriter pw = gc.getPixelWriter();
082
083        for (int i = 0; i < HEIGHT; i++) {
084            for (int j = 0; j < WIDTH; j++) {
085
086                Color c = computeColor( i, j );
087                pw.setColor( j, i, c);
088            } // for
089        } // for
090
091        Scene scene = new Scene(root);
092        stage.setScene(scene);
093
094        stage.show();
095    } // start( Stage )
096
097    private Color computeColor(int row, int column) {
098        Point p = new Point(row, column, HEIGHT, WIDTH);
099
100        double x = p.getX();
101        double y = p.getY();
102
103        if (x < y) {
104            return Color.WHITE;
105        } // if
106        else {
107            return Color.PURPLE;
108        } // else
109    } // computeColor( int , int )
110
111    public static void main(String[] args) {
112        launch(args);
113    } // main( String[] )
114
115} // Bitmap