initial commit
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / basic / GlowingPoint.java
1 /*
2  * Sixth - System for data storage, computation, exploration and interaction.
3  * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
15
16 public class GlowingPoint extends ForwardOrientedTexture {
17
18     private static final int TEXTURE_SIZE = 50;
19     private final Color color;
20
21     public GlowingPoint(final Point3D point, final double pointSize,
22                         final Color color) {
23         super(point, pointSize, getTexture(color));
24         this.color = color;
25
26         getTexture(color);
27
28     }
29
30     public static Texture getTexture(final Color color) {
31         final Texture texture = new Texture(TEXTURE_SIZE, TEXTURE_SIZE, 1);
32         for (int x = 0; x < TEXTURE_SIZE; x++)
33             for (int y = 0; y < TEXTURE_SIZE; y++) {
34                 int address = texture.primaryBitmap.getAddress(x, y);
35
36                 final int distance = (int) Math
37                         .sqrt((((TEXTURE_SIZE / 2) - x) * ((TEXTURE_SIZE / 2) - x))
38                                 + (((TEXTURE_SIZE / 2) - y) * ((TEXTURE_SIZE / 2) - y)));
39
40                 int alpha = 255 - ((270 * distance) / (TEXTURE_SIZE / 2));
41                 if (alpha < 0)
42                     alpha = 0;
43
44                 texture.primaryBitmap.bytes[address] = (byte) alpha;
45                 address++;
46                 texture.primaryBitmap.bytes[address] = (byte) color.b;
47                 address++;
48                 texture.primaryBitmap.bytes[address] = (byte) color.g;
49                 address++;
50                 texture.primaryBitmap.bytes[address] = (byte) color.r;
51             }
52
53         return texture;
54     }
55
56 }