Alpha in Hype, Processing - processing

I am generating a hexagon particle pattern for a design project in Processing, HYPE (see sample below).
My problem is that I cannot produce a visible alpha variations, like here, even with the same chunk of alpha code. Googling doesn't help. I'm not sure what exactly I'm doing wrong.
My code is here.
Thank you.

You're using web notation to define your colors, which doesn't support transparency. Instead, use one of the color() functions that take an alpha channel.
colors = new HColorPool()
.add(color(#32184E, 100))
//...
From the reference:
Web color notation only works for opaque colors. To define a color with an alpha value, you can either use color() or hexadecimal notation. For hex notation, prefix the values with 0x, for instance color c = 0xCC006699. In that example, CC (the hex value of 204) is the alpha value, and the remainder is identical to a web color. Note that in hexadecimal notation, the alpha value appears in the first position. (The alpha value appears last when used within color(), fill(), and stroke().) The following is an equivalent way of writing the preceding example, but using color() and specifying the alpha value as its second parameter: color c = color(#006699, 191)
For future reference, you should post your code as an MCVE directly in your question instead of posting a link to it.

Related

ZPL - How can we control width of the barcode in zpl

I am working on conversion of pdf in to ZPL. I am using zebra programming language(zpl).
I am trying to control the barcode(any barcode) width using By command.
^By4 is giving lower width and ^By5 is going out of the box.
My use case is I want to achieve narrow bar width in float number(here 4.5). We can not pass float number in By command.
Please let me know if we can achieve this using some other method in ZPL.
You don't mention what barcode format you're using. Some of them, like 2of5, can also accept the ratio parameter for ^BY. The default is ^BY2,3, changing that to ^BY2,2 can make a smaller version:
^XA
^POI
^CFO,20
^BY5,3
^FO100,400
^BJN,100,Y,N
^FD200940^FS
^BY5,2
^FO100,700
^BJN,100,Y,N
^FD200940^FS
^XZ
This generates two barcodes in 2of5, one with the default ratio and one with a smaller ratio. The second one has a tighter barcode that uses less space. Valid values are 2.0-3.0 (although many round off to the same values) so there is some flexibility. Please note, this only works with barcode formats that are not fixed ratio formats.
You can check the manual page for ^BY in the ZPL programmers guide, p123, for the table that shows valid values and which ones round off to the same value (ie, 2.0 and 2.1 give the same results)

Sass color transform calculation

I have two shades of the color blue (#1E95EF -> #1988DD), and need to figure out the color transformation that has happened in order to replicate it across other colors in my palette (red, green etc).
I've used combinations of darken()/lighten() & saturate()/desaturate() to eyeball the transformation, and have gotten it pretty close:
desaturate(darken(#1E95EF, 4.5%), 8%); === #1A88DC
But I need to get it exactly right, so that the small errors that I make with the percentage decimal points are not replicated across all of the colors. How can I figure out exactly what transformation has occurred?
Here is what I've tried:
sassmeister gist
In this snippet, the relevant classes to my example are .ga-primary and .ga-primary-hover
You can measure the differences between colors in different ways, depending on the color model/space you're using. Hex colors use RGB, but the HSL model will be more useful here. It records a color as 3 values: Hue, Saturation and Lightness.
We can use SASS's HSL functions to work out how each value of the color differs, and then selectively apply that difference to other colors:
$start-color: #1E95EF
$end-color: #1988DD
//We won't need the hue-difference in practice
$hue-difference: hue($start-color) - hue($end-color)
//These express the difference as a percentage
$saturation-difference: saturation($start-color) - saturation($end-color)
$lightness-difference: lightness($start-color) - lightness($end-color)
#function color-adjust($base-color)
//Apply the lightness and saturation changes but keep the original Hue
#return hsl(hue($base-color), saturation($base-color) + $saturation-difference, lightness($base-color) + $lightness-difference)
//To find the adjusted color, just pass whatever base color you like to the color-adjust function:
background: color-adjust(red)
Here's a demo with a few colors: http://codepen.io/anon/pen/bqOaZZ
Obviously that code can be compacted a lot - I'm thinking that what you really want is to define your variants as a set of Saturation/Lightness changes, and then apply them to your whole palette (rather than trying to 'reverse-engineer' it from one example pair). If you want help with something to do that, let me know!

Getting the standard deviation of an image in Julia

I'm using the Images package and I want to load in an image and get the mean and standard deviation of the pixels in r image.
I tried:
using Images, Color, FixedPointNumbers, ImageView, Testimages
img = testimage("mandril")
mean(data(img))
The mean worked fine, in fact in IJulia it displays the mean color of the image. However, when I tried to get the standard deviation of the image, I get:
std(data(img))
`varm` has no method matching varm(::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}}, ::RGB{Float32})
while loading In[66], in expression starting on line 1
in var at statistics.jl:162
How would one go about getting the standard deviation of the image?
You can use red, green and blue to extract the components of image,
and compute the standard deviation with std on the resulting matrices.
using Images
using TestImages
using Color
img = testimage("mandril")
data(img)
RGB(
std(red(img)),
std(green(img)),
std(blue(img))
)
# RGB{Float32}(0.22030124f0,0.18964756f0,0.24422659f0)
You could also build a 3-dimensional array with all the data,
with separate,
and apply std on the three 2-dimensional slices corresponding
to the three components, with mapslices.
vec( mapslices( std, separate(img), [1,2] ) )
If you want to figure out why mean(data(img)) works
and std(data(img)) does not (at least, currently),
you can check which method is called
with #which, and read the corresponding code, with #less.
#which mean(data(img))
# mean(A::AbstractArray{T,N}) at statistics.jl:17
#which std(data(img))
# std(A::AbstractArray{T,N}) at statistics.jl:204
#less mean(data(img))
#less std(data(img))
There are (at least) two problems: first, sqrt is not defined for colours,
second, some of the code in std assumes that the mean is a Number.

Color Space options for CIContext

When creating a Core Image CIContext using the following:
contextWithCGLContext:pixelFormat:colorSpace:options:
You can specify a color space with a CGColorSpaceRef. However, the options dictionary that you can pass also allows you to set certain color space parameters. From Apple's documentation:
kCIContextOutputColorSpace
A key for the color space to use for images before they are rendered
to the context. By default, Core Image uses the GenericRGB color
space, which leaves color matching to the system. You can specify a
different output color space by providing a Quartz 2D CGColorSpace
object (CGColorSpaceRef). (See Quartz 2D Programming Guide for
information on creating and using CGColorSpace objects.)
kCIContextWorkingColorSpace
A key for the color space to use for image operations. By default,
Core Image assumes that processing nodes are 128 bits-per-pixel,
linear light, premultiplied RGBA floating-point values that use the
GenericRGB color space. You can specify a different working color
space by providing a Quartz 2D CGColorSpace object (CGColorSpaceRef).
Note that the working color space must be RGB-based. If you have YUV
data as input (or other data that is not RGB-based), you can use
ColorSync functions to convert to the working color space. (See Quartz
2D Programming Guide for information on creating and using
CGColorSpace objects.)
My question is, how do these various color space parameters interact?
My assumption would be that creating the CIContext with with a color space set using the colorspace: parameter above would be the same as setting the color space using the kCIContextOutputColorSpace in the options: dictionary. Is that correct? If not, what does each parameter mean?
If so, then what happens if the color space is set using both the colorspace: parameter as well as the kCIContextOutputColorSpace key in the options: dictionary? Does one override the other? Is there some other behavior?

How to convert html color names into RGB values in Ruby?

I know there is a gem called Color. I installed it.
But for the life of me, I can't figure out how to use the thing.
I just want to convert a color name into its RGB values, if possible without copying the whole color table into my code.
I want to be able to convert something like red or Navy into three numeric values.
require 'color/css'
red_code = Color::CSS["red"].html
#=> "#ff0000"
Old question, but I just came across this gem in a current project and had to do the same. I needed RBG values like OP asked for and so I used the css_rbg instance method similar to how tokland produced the hex value with the html instance method.
require 'color/css'
red_code = Color::CSS["red"].css_rgb
#=> "rgb(100.00%, 0.00%, 0.00%)"
Html colours are expressed as an Hexadecimal colour, and it turns out that a RGB colour is not more than a Hexadecimal expression of the colour so:
#ff0000 = r:255 g:0 b:0

Resources