![]() ![]() Luminance is a way of describing how close a color is to black (0%) or white (100%). ![]() The relationship between two colors in WCAG 2.1 is described by their contrast ratio-that is, the number you get when you compare the luminance of two colors. The latest stable version, WCAG 2.1, covers an important accessibility requirement: minimum contrast. The guidelines that underpin these standards are called the Web Content Accessibility Guidelines, or WCAG. W3C’s Web Accessibility Initiative provides strategies, standards, and resources to ensure that the internet is accessible for as many people as possible. By the end of this post you'll have three new tools and techniques for inspecting, correcting, and verifying your web design contrast so you can tackle the hardest scenarios. ![]() Sometimes testing contrast is easy and sometimes it's really hard. While all of the examples may be readable to you, this isn't the case for everyone.Īccessible color contrast is a practice that ensures text is readable for everyone. I know very little about how it works or it's performance though.Say you have some text on a light background, like this: The _polygon function caught my attention. If you're feeling adventurous, you can look into the gfxdraw libraries for pygame. Also, copying a surface may not necessarily preserve the alphas, but like the last point, I've found that it does when the alphas are already defined in the original image. The StackOverflow question that I referenced details the two ways to ensure a surface has alphas which are unaffected by surfarray operations. So, the last few steps are actually taking your original surface and coloring it the way you need: origSurface = ('images/blue_circle.png')Ĭolor_surface(coloredSurface, 120, 78, 240)Ī couple of notes about this code: the call to convert_alpha on the surface seems to be unnecessary if the image already has per-pixel alphas defined. It might be necessary if you try to do more complicated things with the surface. Which I also left out because I've found this to be a startlingly slow call in practice. The tutorial I posted also uses an additional instruction, something like: iarray = numpy.array(arr) In that function, I use 3d because it references the pixels into an array, rather than copy them, making it a faster operation. def color_surface(surface, red, green, blue): Some credit goes to the poster who answered this question. Below is a code example of what you're looking to do. I did a bit of toying around to make sure that this works as you need it. I should still note that in practice, I've found it not to be fast enough for some applications, such as operating on large images, but if you're only operating on small particle sprites, you should be fine. Ordinarily, this would be a very slow operation, but surfarrays use numpy/numeric as their core, so the operation is quite fast. A simple tutorial on how to get started with them can be found here.Įssentially what a surfarray does is directly modify the pixel values of pygame surfaces, and can operate on each of the R, G, and B channels for every pixel "simultaneously," which I put in quotes because I just mean you can change all the pixels with just one line of code.
0 Comments
Leave a Reply. |