I want to create a Maxwell color triangle
(https://homepages.abdn.ac.uk/npmuseum/article/Maxwell/Legacy/MaxTri.html)
using Matplotlib.
I have found code for something similar: http://www.f-legrand.fr/scidoc/docmml/image/niveaux/couleurs/couleurs.html
However, in that case, equal proportions of R, G, and B yield darker colors which is not what I want.
Any ideas are welcome. I am really struggling with this.
Inside Maxwell Triangle: r + g + b = 1.0, it means the center will be RGB(1/3, 1/3, 1/3) ([0.0,1.0] range) which is dark compared to white RGB(1.0,1.0,1.0).
In order to get white (RGB(1.0,1.0,1.0)) at the center it is possible to multiply RGB values by 3.0: center would be perfectly white but out-of-bound values would be cropped ie RGB(2.0,1.0,1.0) would be displayed as RGB(1.0, 1.0, 1.0).
Another way is to maximize brightness: RGB(r,g,b) -> 1 / max(r,g,b) * RGB(r, g, b) e.g. RGB(0.2, 0.5, 0.1) -> RGB(0.4, 1.0, 0.2). That way values are never clipped and brightness is maximal.
Related
I'm having a fragment shader that draw some stuff. On top of that I want it to draw 1-pixel thick rectangle around the fragment. I have using step function, but the problem is the UV coordinates that is between 0.0 -1.0. How do I know when the fragment is at a specific pixel? For this I want to draw on the edges.
c.r = step(0.99, UV.x);
c.r += step(0.99, 1.0-UV.x);
c.r += step(0.99, UV.y);
c.r += step(0.99, 1.0-UV.y);
The code above just draw a rectangle, but the problem thicknes is 0.01% of total width/hight.
Is there any good description of UX, FRAGCOORD, SCREEN_TEXTURE and SCREEN_UV?
If it is good enough for you to work in screen coordinates (i.e., you want to define position and thickness in terms of screen space) you can use FRAGCOORD. It corresponds to the (x, y) pixel coordinates within the viewport, i.e., with the default viewport of 1024 x 600, the lower left pixel would be (0, 0), and the top right would be (1024, 600).
If you want to map the fragment coordinates back to world space (i.e., you want to define position and thickness in terms of world space), you must follow the work-around mentioned here.
I´d like to draw a circumference in a graph in Excel based on a radius value written in a cell.
I know how to draw Circle by macro but not in an Excel Graph.
Any help are welcome
Thx so much
M.
Your best bet would be to do some off to the side calculations. For example, with columns t, X, and Y:
Your first point (x, y) will be any point on the circle with radius r.
Your next point will use the math here https://www.mathopenref.com/coordparamcircle.html based on the first point and whatever t you wish (smaller increments will produce a more accurate circle)
Keep using that math until you hit 360 degrees.
Assuming r = 5, centered at (5, 10), and using t increments of 0.25:
Using C# I'd like to find out if a Hex color (web format, e.g: #FF2233) is dark or light based on which I can decide what the fore color (font color) should be.
The color is selected by application's users as background of certain elements.
The program then needs to figure out if the user's background color is dark then choose white as the font color (for best readability and contrast) otherwise black is chosen.
So far I have been trying to count the number of occurrences of the "F","E","C","D","B" and "A". If there are at least 4 occurrences I consider the color bright. It works for about 70% of times.
Is there a better solution for this?
What if you convert your [Hex color to rgb][1] format then you make the summ of red green and blue
if it's over ((255*3)/2) it's a dark color, else it's light color
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#FF2233");
if (col.R * 0.2126 + col.G * 0.7152 + col.B * 0.0722 < 255 / 2)
{
// dark color
}
else
{
// light color
}
Edit: Updated with Luminance, thanks to #Jon idea
[1]: How do I get the color from a hexadecimal color code using .NET?
Edit: fixed condition, thanks to #sam360
It's pretty straightforward to compute the luminance of the color from the RGB components. While this will not give the most accurate result on the planet if judged from a human's perspective, it's going to be massively better than other naive attempts.
Given the values of the color components R, G, B, the luminance Y is
Y = 0.2126 R + 0.7152 G + 0.0722 B
You would then pick an arbitrary threshold for Y that separates "dark" from "light" colors.
How does one get the colour value (rgb) after applying an alpha to a colour?
I would like to apply an alpha to a colour and get the rgb values from the result.
Maybe I am over thinking this, or is it just the value e.g. 120 * alpha (0.6) = resulting colour? White is at 255 though, so should it be 120 += 120 * alpha (0.6) ?
The resulting color of the pixel would be dependent on what color was painted behind it, if the color is partially transparent. Which makes this far more complex that you might think.
The rgb values of the color do not change at all when you apply the alpha. All the changes is how that color will blend with other elements in the view.
So you would have to know where on the screen the color will be drawn, and query the view for the color at that pixel, and then blend it with your color according to the colors alpha value.
//psuedocode
resultColor = (backgroundColor * (1 - alpha)) + (myColor * alpha)
So if your alpha was 0.2 you blend the colors so the result is 80% background color and 20% foreground color.
I'm struggling with a problem when making plots with filledcurves. Between the filled areas, there seems to be a "gap". However, these artifacts do not appear on the print, but depend on the viewer and zoom-options. In Gnuplot I use the eps terminal, the eps-files look great, but the lines appear when I'm converting to pdf. The conversion it either done directly after plotting or when converting the latex-document from dvi to pdf. As most of the documents are here on the display nowadays, this is an issue. The problem also appears when I'm directly using the pdfcairo terminal in Gnuplot, so it's not caused by the conversion (tried epstopdf and ps2pdf) alone.
I attached a SCREENSHOT of a plot displayed in "acroread" (same problem in other pdf-viewers).
Has anybody an idea how to get rid of it but keeping the graphic vectorized?
I just ran into the same issue. Apparently the filling between two curves
is done as a set of polygons that do not exactly touch one another, thus
the thin white lines visible on some PDF viewers.
One way to fix the issue is to draw over these polygon boundaries. First
define min and max functions in gnuplot:
min(x, y) = x < y ? x : y
max(x, y) = x > y ? x : y
Then, assuming that column 1 of "datafile" contains your x values and
that columns 2 and 3 contain the y values of curves 2 and 3, write:
plot "datafile" using 1:2:3 with filledcurves lc rgb "gray", \
"" using 1:2:(min($2, $3)):(max($2, $3)) with yerrorbars ps 0 lt 1 \
lc rgb "gray" lw 0.5
The first plot instruction fills the spaces between the curves in gray.
The second plot instruction draws points of zero size (ps 0) at each
x value (1) on curve (2) with thin (lw 0.5), continuous (lt 1), gray
(lc rgb "gray"), vertical errorbars (yerrorbars) from the lower to
the higher of curves 2 and 3.
This covers the white lines. To get best results you may need to
experiment with the thickness of the bars (e.g., lw 0.6, lw 0.2).
This issue is fixed with gnuplot 5.2, see https://sourceforge.net/p/gnuplot/patches/749/
The actual problem was, that filled curves were previously plotted as many quadrilaterals, which leads to artifacts (white stripes) in many viewers due to antialiasing.
Since version 5.2 filled curves are rendered as single polygon, which prevents these problems (see issue linked above).
The problem is still present in Gnuplot 5.0.4 and at least the cairolatex terminal which I use to output PDFs.
I also wanted to color the area between two curves, in my case defined as functions.
When I used something like
f(x) = 2 + sin(x)
g(x) = cos(x)
plot '+' using 1:(f($1)):(g($1)) with filledcurves closed
I got the same vertical white lines as in the question.
A simple solution for curves where one is always above the other is to let Gnuplot fill the area from the upper curve to the x-axis with the desired color and then paint it over with white from the lower curve downwards:
f(x) = 2 + sin(x)
g(x) = cos(x)
plot f(x) with filledcurves x1, g(x) w filledc x1 fs lc rgb "white"
Apparently this filledcurves style (not between curves but between a curve and an axis) avoids the trapezoid artifacts.
This can be readily extended for plotting data files and multiple stacked cures like in the question. Just paint from top to bottom and finish with white for the empty area between the lowest curve and the x-axis.
For overlapping curves a construction of minimum and maximum curves like in the answer from françois-tonneau might do the trick.
If you're talking about the red and cyan bits the gap could be an illusion caused by the Red + Cyan = White on a RGB screen. Maybe there's no gap, but the border areas appear as white due to the proximity of the pixels.
Take the screenshot and blow it up so you can see the individual pixels around the perceived gap.
If this is the case, maybe selecting a different colour scheme for the adjacent colurs would get rid of the effect. I certainly can't see anything matching your description on anywhere but the red and cyan bits.
From https://groups.google.com/forum/#!topic/comp.graphics.apps.gnuplot/ivRaKpu5cJ8, it seemed to be a pure Gostscript issue.
Using the eps terminal of Gnuplot and converting the eps file to pdf with
epstopdf -nogs <file.eps> -o <file.pdf>
solved the problem on my system. From the corresponding Man page, the "-nogs" option instructs epstopdf not to use Gostscript.