a74e9208e145db922c1215b0a9b4b44734bc5aa1
Stefan Schuermans implemented fade example, f...

Stefan Schuermans authored 13 years ago

1) /* JFlexiPix - Java implementation of FlexiPix output library
2)  *
3)  * Copyright 2010-2011 Stefan Schuermans <stefan blinkenarea org>
4)  *
5)  * This program is free software: you can redistribute it and/or modify
6)  * it under the terms of the GNU General Public License as published by
7)  * the Free Software Foundation, version 3 of the License.
8)  *
9)  *
10)  * This program is distributed in the hope that it will be useful,
11)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13)  * GNU General Public License for more details.
14)  *
15)  * You should have received a copy of the GNU Lesser General Public License
16)  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17)  */
18) 
19) package org.blinkenarea.JFlexiPix.examples;
20) 
21) import org.blinkenarea.JFlexiPix.*;
22) 
23) public class Fade
24) {
25)   // entry point
26)   public static void main(String [] args)
27)   {
28)     String config;
29)     Display display;
30)     int width, height, i, x, y;
31)     byte [] image;
32) 
33)     // check usage
34)     if (args.length < 1) {
35)       System.out.println("usage: java Fade <config.flp>");
36)       return;
37)     }
38)     config = args[0];
39) 
40)     /* create a display, take configuration from a file,
41)        deliver messages to message method of new Msg object */
42)     try {
43)       display = new Display(config, new Msg());
44)     } catch (Exception e) {
45)       System.out.println("could not create display\n");
46)       e.printStackTrace();
47)       return;
48)     }
49) 
50)     // get size and show it
51)     width  = display.getWidth();
52)     height = display.getHeight();
53)     System.out.println("display size:");
54)     System.out.println(String.format("  width:  %5d", width ));
55)     System.out.println(String.format("  height: %5d", height));
56) 
57)     /* create an image with a nice fade:
58)        black to red from left to right,
59)        black to green from top to bottom */
60)     image = new byte [height * width * 3];
61)     i = 0;
62)     for (y = 0; y < height; ++y) {
63)       for (x = 0; x < width; ++x) {
64)         image[i++] = (byte)(255.0*x/(width -1)+0.5); // red
65)         image[i++] = (byte)(255.0*y/(height-1)+0.5); // green
66)         image[i++] = (byte)0;                        // no blue
67)       }
68)     }
69) 
70)     // output image
71)     display.data(image,
Stefan Schuermans added additional base index...

Stefan Schuermans authored 13 years ago

72)                  3,              // consecutive pixels are 3 bytes apart
73)                  width * 3,      // consecutive lines are width * 3 bytes apart
74)                  0,              // top-left pixel is at array index 0
75)                  0, 0,           // top-left pixel is 0,0
76)                  width, height); // image size is width,height