I would like some help figuring out a routine for creating from a base colour the exact contrasting colour.
Is this possible?
Sass has a variety of color functions which may be what you're looking for.
Complement: 180° around the color wheel.
div { color: complement($color); }
Invert: Reverses the RGB values, but doesn't adjust the opacity.
div { color: invert($color); }
For more color functions, see http://sass-lang.com/documentation/Sass/Script/Functions.html or examples on Codepen.
Related
I want to the corners to be rounded and hover for a QPushButton in Qt designer. Changing the style sheet has no effect. What am doing wrong?
QPushButton#pushButton_3{
background: rgb(170, 170, 255);
border: 2px solid rgb(0, 170, 255);
border-style: outset;
border-width: 2px;
border-radius: 20px;
color: white;
}
QPushButton:hover#pushButton_3{
background-color: rgb(0, 255, 255);
border: 2px solid (0, 255, 255);
}
This is what I get when the above style sheet is set:
TL;DR
Use smaller values for border-radius, usually half of a standard font size (2 <= radius <= 10).
Further explanation
The QSS border radius must have a reasonable value.
The private QStyleSheetStyle normalizes the border radius (or, better, all four border radii) based on the bounding rect of the widget, which includes the border size(s).
Whenever any border radius exceeds the size related to its corner, all radius are ignored.
For instance, if the rectangle of a widget has height 10, the sum of its top-left and bottom-left radii must be equal or less than 10, otherwise the left corner will be squared.
Note that widgets normally consider the border only for their size hint, not their minimum size hint, and that behavior also can change depending on the current style.
A button is normally created using the current style's pixelMetric() and fontMetrics(), and since a pretty standard height of a button is ~30 pixels, considering the above, the border-radius specified is excessive: the sum of any corner component is always greater than the widget height, so the radii are ignored, and the border will be squared.
So, how to set a proper border radius?
The easy answer is: use "small" values, normally no more than twice or four times the border width.
The actual answer is more complex, as we need to consider that widgets often have some displayed text, and any modern OS supports both font scaling and high DPI screens.
QSS support various types of lengths other than the standard px:
px: pixels (normally, physical pixels, AFAIK, the actual value depends on the OS and their implementation of High DPI);
pt: the size of one point (based on the screen DPI, AFAIK, only used for text properties and ignored for widget/border sizes);
em: the em width of the font (based on the displayed font);
ex: the x-height of the font (as above);
If you want to properly support any modern OS, you probably need to use any of the last two values, and that's another reason for which is important to set a global style sheet for the application: as long as the app is created, you can know the default (or imported) fonts, and eventually set a main style sheet with formatted widths or sizes based on the current device pixel ratios and font metrics.
I would like to animate an SVG stroke color change from say, red to green.
Is this possible?
I have managed to do so with the "fill" property, but for some reason i cannot do it with stroke.
One solution would be something along the lines of:
.velocity({
strokeRed: 0,
strokeGreen: 255,
strokeBlue: 0
});
My understanding is that linear 1s should the default timing, perhaps adding a named easing will enable that,
.velocity({
strokeRed: 0,
strokeGreen: 255,
strokeBlue: 0
}, "easeInSine");
Also, you can simply use "stroke", but note that stroke requires a hex value, unlike those listed above which can either be unitless or a percent.
Sass language has function called darken that takes two arguments: a color and percentage you want to darken the color by. I only know the original color and the resulting color. How can I determine the percentage value that was passed to the darken function along with the original color?
darken(#e8e8e8, ???) // returns #c1c1c1
For darken (and probably lighten too), you would want to calculate the difference between the lightness values of both colors:
#function color-difference($c1, $c2) {
$c1: lightness($c1);
$c2: lightness($c2);
#return max($c1, $c2) - min($c1, $c2);
}
$color1: #e8e8e8;
$color2: #c1c1c1;
.foo {
// guessed the percentage manually
test: darken($color1, 15.25%);
// check our percentage
test: color-difference($color1, $color2);
// do we get the same result?
test: darken($color1, color-difference($color1, $color2));
}
Output:
.foo {
test: #c1c1c1;
test: 15.2941176471%;
test: #c1c1c1;
}
You can use rgba() where rgb is reg, green, blue and 'a' is alpha. You can use alpha instead of percentage.
I am currently trying to implement semi-transparent polygons in sharpdx.
At the moment I am using GraphicsDevice and BasicEffect to draw my objects.
// Setup the vertices
game.GraphicsDevice.SetVertexBuffer(myModel.vertices);
game.GraphicsDevice.SetVertexInputLayout(myModel.inputLayout);
// Apply the basic effect technique and draw the object
basicEffect.CurrentTechnique.Passes[0].Apply();
game.GraphicsDevice.Draw(PrimitiveType.TriangleList, myModel.vertices.ElementCount);
This is working fine for normal objects, however I would like to make some of the objects partially transparent. I've set the alpha value of these object's colors to 50, however they are still being rendered as opaque. What do I need to do to achieve this effect?
Transparency in Sharpdx requires alpha blending value 0..1 for float colors. The comment Nico Schertler provided above solved the question and can be regarded as answer.
Without Alpha mode, there are two options, that you can use in the HLSL shader file
In the Pixel shader, use the clip() function, dependent on the input color. You could define your transparent black and not show any black triangles. Like so:
float4 PS( PS_IN input ) : SV_Target
{
clip(input.color[3] < 0.1f ? -1:1 );
return input.color;
}
ref: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-clip
See the effect:
modify the Vertex Shader to project these vertices to (0,0,0), dependent on the input color. You could define your transparent black and not show any black triangles. Like so:
PS_IN VS( VS_IN input)
{
PS_IN output = (PS_IN)0;
if ((input.color[0]!=0)||(input.color[1]!=0)||(input.color[2]!=0))
{
output.position = mul(worldViewProj,input.position);
}
output.color = input.color;
return output;
}
See below the effect on the edges of my HeightField mesh, on the left is the unchanged version..
NOTE: The latter solution gives sharper edges, but it only works when (0,0,0) is behind the object.
Is there a particular color operation I'm not seeing where you can invert colors? I'm seeing lots of color methods but could not see a way to do this.
reference:
http://lesscss.org/
There are multiple interpretation of inverting color.
You want a color with the opposite hue:
spin(#color, 180)
You want a color that the sum with current one is white:
#fff - #color
Unfortunately there's no invert() function in Less.
I think Less function spin() can be very helpful as xiaoyi's answer highlights. Use it on "colorful" colors like red or blue (spin(red, 180)) and we get the inverted color but we don't really get the same result on very dark or light colors since there's not much hue to rotate. For instance spin(#000011, 180) compiles into color #111100, which is also very dark.
I wanted to set the color of paragraphs to black if the background is light and set it to white if the background is dark. Here's how I do it with if(), boolean() and luma():
#bkg-color: #001;
#is-bg-dark: boolean(luma(#bkg-color) > 50%);
.container {
background-color: #bkg-color;
}
p {
color: if(#is-bg-dark, black, white);
}
Read more about Less functions such as boolean().
I don't think there is a specific function to invert colors, but what you could do is set your colors as variables. e.g.:
#color1: #666;
#color2: #fff;
body {
background-color: #color1;
color: #color2;
}
h1 {
color: #color2;
}
Then, simply make an alternate stylesheet with the inverted colors set to the variables used in the primary stylesheet. As long as you use the variables throughout the css, those color will be inverted.