I have a layout that is covered entirely by a tint overlay (it's the last element in my RelativeLayout).
I have TextView1 and TextView2 with textColor set to red (#FF0000).
My tint overlay is grey with transparency set - #88676767.
I want my TextView1 tinted but TextView2 appear red (#FF0000).
Is there a way for me to calculate color value X for TextView2 so when it is overlayed with a tint layer it appears to the user as red (#FF0000)? If so, how do I go about calculating this value?
No, there is no way to achieve this. The color is calculated as
(color1.R*color1.A + color2.R*color2.A)/(color1.A+color2.A)
This equation does not have solution for color1.R in (0, 255) and color1.A in (0, 1) when color2 is your overlay and result color is 255.
Find more info in this answer.
Related
I use Paint.Net in Windows to make mask png image from source png.
def mask (im):
newimdata = []
transparent = (255, 255, 255, 0)
black = (0,0,0)
white = (255,255,255)
for color in im.getdata():
if color == transparent:
newimdata.append(white)
else:
newimdata.append(black)
newim = Image.new(im.mode,im.size)
newim.putdata(newimdata)
return newim
img = Image.open(thumb)
img = img.convert("RGBA")
mask(img).show()
The result is little weird.
Source png.
Mask png.
Left transparent rectangle I made in PaintNet: I clicked mouse, made transparent area.
Right transparent rectangle I made: I clicked mouse, made transparent area. After I clicked mouse once again and made transparent vertical figures on transparent rectangle.
I don't understand: Is it two transparent layers (right rectangle and vertical figures)?
How can I merge this to make mask as in left clean rectangle?
I don't understand what you are trying to do, but want to show you how the 4 channels (RGBA) of your image look. R is on the left, then G, then B with A (alpha/transparency) on the right.
I guess you just want the rightmost (A) channel, so with PIL, that is:
from PIL import Image
im = Image.open('....')
alpha = im.getchannel('A')
If you want all the channels, use:
R, G, B, A = im.split()
I have been planning to change my sprite to a bit darker color through changing saturation and hue values. But it seems very tricky to do so as the Godot modules only talk about changing the color of a sprite though the modulate option like this:
node.modulate= Color(0, 50, 2,0.5)
Doing so is changing the entire sprite to a new color whereas I just want to make the existing colors to a bit darker color the way we do in Photoshop using "Curves" or "Levels" - but not as refined. Any rudimentary method would also help.
Currently, I can only do "Color Overlay" without changing the opacity. Any method of adding a color overlay with opacity change would be helpful as long as it doesn't change the opacity of the entire sprite but just the overlay color.
I am working on a 2D game with imported PNG Sprites. If any more information is required, I'll be happy to provide it.
Additional Information -
What my sprite looks like
I want to make it darker through code twice like this -
By doing node.modulate= Color(0.0, 0.0, 0.0,1) it becomes like this -
The reason why I'm avoiding to do this manually because I have too many sprites and doing this for all of them will be tedious.
Here's two examples of how you can darken a sprite via code.
The first method is by using self_modulate. Modulation is calculated by multiplying the modulation value by texture color value. This shows that modulation of (1, 1, 1, 1) is the same as the original texture. A modulation of (0.5, 0.5, 0.5, 1) halves the texture color making it darker like it has a half opacity black overlay.
# On a node that extends CanvasItem
self_modulate = Color(0.5, 0.5, 0.5, 1.0)
The second method is to subtract the texture value by a constant. This creates a texture that's more saturated but darker.
The shader code:
shader_type canvas_item;
uniform float difference: hint_range(0.0, 1.0) = 0.0;
void fragment() {
vec4 tex = texture(TEXTURE, UV);
COLOR.rgb = tex.rgb - vec3(difference);
COLOR.a = tex.a;
}
The other code:
# On a node that extends CanvasItem
material.set_shader_param('difference', 0.3)
These effects can be combined to produce the desired result. Play around with the shader to produce a better result.
Hope this helps.
Each pixel is composed by two bits, allowing up to 4 shades of gray. From the LCD Monochrome Palettes section of the pandocs we can develop the algorithm for getting the color (in the case I've understood it correctly):
COLOR_NUMBER_PALETTE_BITS = {
0: (1, 0),
1: (3, 2),
2: (5, 4),
3: (7, 6)
}
COLORS = {0: WHITE, 1: LIGHT_GRAY, 2: DARK_GRAY, 3: BLACK}
def get_pixel_color(palette_address, color_number):
palette = read_memory(palette_address)
high_bit, low_bit = COLOR_NUMBER_PALETTE_BITS[color_number]
color_high_bit = get_bit(palette, high_bit)
color_low_bit = get_bit(palette, low_bit)
color = (color_high_bit << 1) | color_low_bit
return COLORS[color]
But just looking at the function signature we can deduce that same color numbers may result in different colors; it depends on the palette we're using.
My question is, why do we need multiple color palettes when two of them are identical, and the only difference with the third one is that 0 is transparent instead of white? Why do the palette definition change, instead of the color number used to get the color from the palette?
What do you mean "two of them are identical"? You have three different color palettes. One for background and window. Two for sprites which you can select for each sprite individually using special bit in sprite attributes. Why changing palette instead of color numbers? It's much cheaper to change color palette or sprite attributes than to rewrite each tile of a sprite or window to achieve some effect on the screen. You can even change palettes in realtime as the Gameboy draws the image on the screen.
For example, let's say I wanted to implement flashing effect where whole background flashes between normal colors and white or black. Instead of rewriting every background tile on every frame I could just change the palette and time it exactly to only affect parts of the screen I need. There's even an article describing similar technique.
I want a lighter version of the "cyan" color, using the function colormap('cyan'). How do you do this?
Check out the function BRIGHTEN:
X = spiral(8);
image(X)
colormap(winter), colorbar
brighten(0.6)
Another trick is to right click on the colorbar and select Interactive Colormap Shift, this allows to shift the color-to-data mapping using mouse dragging.
Pure cyan is represented by the RGB triple [0 1 1]. To make it lighter, just increase the red component (ex: [0.5 1 1]), thus moving it closer to pure white ([1 1 1]). If you want to make a colormap that spans from pure cyan through lighter shades of cyan all the way to pure white, you can do the following:
nValues = 128; %# The number of unique values in the colormap
map = [linspace(0,1,nValues)' ones(nValues,2)]; %'# 128-by-3 colormap
Now you can set the colormap to the one made above using the COLORMAP function:
colormap(map);
For more discussion of colors in MATLAB, check out this link.
For me colormap('cyan') fails because cyan is undefined.
However, you can create your own colors easily. If cyan is equivalent to [0,1,1] a lighter color would be [0,1,1] + [.1,0,0] = [.1,1,1] or rather just increase the R in RGB to increase the luminosity.
My dataset consists of three vectors (x,y and z). I plot these values as dots in a 3d-plot with plot3(x,y,z), which is fine. I also want to show a plane in the same plot. To get the data of this plot I use linear regression on x and y to get a new z.
This is how it looks:
(source: bildr.no)
I want the surf to be filled with only one color (say light blue or gray) and set the opacity, to make it see-through. How can I do this?
The easiest way to create a surface that has just 1 color and a given transparency value is to set the 'FaceColor' and 'FaceAlpha' properties of the surface object:
hSurface = surf(...your arguments to create the surface object...);
set(hSurface,'FaceColor',[1 0 0],'FaceAlpha',0.5);
This example sets the surface color to be red and the transparency to 0.5. You can also set the edge properties too (with 'EdgeColor' and 'EdgeAlpha').
It is not clear to me what you want to do. When you say one color for the surf, do you mean exactly one color, or do you mean you want shades of gray?
Here is some code that will do a variety of things, you can choose which lines to use:
x = rand(1,20);
y = rand(1,20);
z = rand(1,20);
[X,Y] = meshgrid(linspace(0,1,10),linspace(0,1,10));
Z = rand(10)*0.1;
clf
plot3(x,y,z,'.');
hold on
h = surf(X,Y,Z)
hold off
%% This will change the color
colormap(copper)
%% This will remove colordata
set(h, 'cdata',zeros(10))
%% This will make transparent
alpha(0.5)
Completing the answer from gnovice, an extra ingredient in set(hsurface...) may be required (Matlab R2010b 64):
hSurface = surf(...your arguments to create the surface object...);
set(hSurface, 'FaceColor',[1 0 0], 'FaceAlpha',0.5, 'EdgeAlpha', 0);
to make invisible the point-to-point edges of the plotted surface
#matlabDoug has what you need, I think. The property cdata holds color data that gets a color map applied to it. Setting it to an array the same size as your surface data, with each element in that array having the same value, will make your surface one color. With the default color map, setting everything in cdata to zero will make your surface blue, and setting everything to 1 will make the surface red. Then you can play with the alpha to make it transparent.