I Need to write a program to draw a graph using HP PCL 5e/HP/GL2 - colors

I have read an example and tried to duplicate it's methods but with weird results. This is a 1 shot deal so I do not want to buy a package to do this. Also, it will be executed on a Multi-Valued database in a Basic that not many programmers write in anymore.
If anyone can post a small example of this It would be most helpful. Specifically, I need a box centered on an 8x11 paper with the left 1/3 filled in Green, the center 1/3 in Yellow and the last 1/3 in Red. Then Draw a line thru 3 points within each color of the box.
Thanks.

The simplest way is to draw 3 boxes. You'll have to position each one on your own doing your own math to determine where to start the first one to make it centered etc.
First position your cursor at the top left of the first box, draw it, move to the top left of the next box, draw it, and do the same for the last. Here is some code:
<esc>&u300D<esc>*t300R<esc>*p300x300Y<esc>*r3U<esc>*v2S<esc>*c300a300b5P<esc>*p600x300Y<esc>*r3U<esc>*v3S<esc>*c300a300b5P<esc>*p900x300Y<esc>*r3U<esc>*v1S<esc>*c300a300b5P
Here is the explanation:
<esc>&u300D<esc>*t300R -- set the Unit of Measure and Resolution (in this case 300 dpi)
<esc>*p300x300Y -- move cursor to 300x 300y (1 inch x 1 inch)
<esc>*r3U<esc>*v2S -- set the color palette to RGB and use color 2 (green)
<esc>*c300a300b5P -- draw a box that is 300 wide and 300 tall, use current fill pattern
<esc>*p600x300Y -- move cursor to 600x 300y
<esc>*r3U<esc>*v3S -- set the color palette to RGB use color 3 (yellow)
<esc>*c300a300b5P -- draw a box that is 300 wide and 300 tall, use current fill pattern
<esc>*p900x300Y -- move cursor to 900x 300y
<esc>*r3U<esc>*v1S -- set the color palette to RGB use color 1 (red)
<esc>*c300a300b5P -- draw a box that is 300 wide and 300 tall, use current fill pattern
Here are the other colors and palettes, keep in mind this is the simple way, you can specify your own RGB etc.
RGB Palette
<esc>*r3U<esc>*v1S - Red
<esc>*r3U<esc>*v2S - Green
<esc>*r3U<esc>*v3S - Yellow
<esc>*r3U<esc>*v4S - Blue
<esc>*r3U<esc>*v5S - Magenta
<esc>*r3U<esc>*v6S - Cyan
CMYK Palette
<esc>*r-3U<esc>*v1S - Cyan
<esc>*r-3U<esc>*v2S - Magenta
<esc>*r-3U<esc>*v3S - Blue
<esc>*r-3U<esc>*v4S - Yellow
<esc>*r-3U<esc>*v5S - Green
<esc>*r-3U<esc>*v6S - Red
<esc>*r-3U<esc>*v7S - Black

Problem Solved: The error of my thinking was that it was a difference between 300 dpi and 600 dpi so I was dividing by 2 and the answer appeared almost correct. The Real problem was a difference between 3oo dpi and 720 Decipoints. The real factor needed to be 2.4 and now it works perfectly.

Related

How to get a color by substracting the other from their combination?

I have a table like this one: https://docs.google.com/spreadsheets/d/1Kn4vfbHwpif7u-6ZTznFpBJFNHhnStETPIQVyQq8xgY/edit#gid=0 with bottom / top color and the Red, Green, Blue (RGB) of the result (where it states 'Preparation' for the bottom color means the canvas so essentially its the RGB of the top color - those rows are the 'single colors').
I am looking for a relation between the double colors and the single colors. E.g. could I somehow subtract one color from their combination and get the other? Either by using the RGB values or using the images in some software?
Note that the type/formula/function/relation that I am looking for will be only for specific single colors and their combinations which I have already measured (do not care if it is valid beyond the dataset that I am working with)

Can I find a semi-transparent layer's colour and transparency using before and after values?

I have two images, one is a portion of an original image, the other is the whole of the original image covered by a uniform semi-transparent colour layer (in this case orange).
Can I use the colour difference between pixels from the first and second images to reverse engineer the colour and transparency of the covering, and if so can I then use it to find the original colour of a pixel without an uncovered equivalent? Is there just a nice single button solution within GIMP or do I need to do some actual programming/maths? I have basically no experience with image manipulation so any help would be appreciated.
Here are the uncovered and covered RGB values to help explain (and the missing value at the bottom).
Colour
Base
+Transparent
Colour 1
#179fb7
#f8b76f
Colour 2
#2fafc8
#f8bf6f
Colour 3
#3fc8d8
#f8c877
Colour 4
#578f08
#f8b73f
Colour 5
#6faf2f
#f8bf47
Colour 6
#87c847
#f8c84f
Colour 7
#9fd85f
#f8c857
Colour 8
#d0bf47
#f8bf4f
Colour 9
#8f9f1f
#f8b747
Colour 10
#6faf2f
#f8d077
Colour 11
?
#f8d06f
I assume you can find every possible colour-transparency pair that would cause the transformation for each row and the plot each as a line to find the intersection point, but I don't know enough about how colour works to do that.

How to select N Colors from the Spectrum?

Given the RGB color white #ffffff, how would one split this into N colors?
Imagine a Rainbow, it has 7 colors.
How would one programatically yield these 7 colors? If you can arrive at 7 colors in this known spectrum, how would one yield say 70 colors of this spectrum in the same relative order? Meaning that this rainbow would contain 10 "steps" between Orange and Yellow for example. The Orange and Yellow are no longer side by side but separated by an interpolation of color between them.

Calculate the apparent difference in color between two HSI color values

I have two color values in HSI (Hue Saturation and Intensity) and I want a number which represents the visual difference between the two colors. Hue is a number between 0 and 360 inclusive. Saturation is 0 to 1 and Intensity is 0 to 1.
Lets consider for example Red and Blue at Saturation of 100% and Intensity of 100%.
At this website is a way to display the color by entering in the following text.
red is:
hsv 0, 100%, 100%
blue is:
hsv 240, 100%, 100%
Clearly these are two very different colors, and so a simple way I could try to calculate the difference between colors is to use the Hue component and calculate the absolute difference in hue which would be 120 (360-240) since 360 is also equal to 0 in hue.
The problem arises where the Saturation or Intensity is very dark or light, consider a very dark red and blue.
dark red is:
hsv 0, 100%, 20%
dark blue is:
hsv 240, 100% 20%
Obviously the visual difference between these two colors is less than the bright red and blue colors, as a human would state if asked to compare the differences. What I mean here is, ask a friend "Which pair of colors is most different?" they will likely say the top bright red blue.
I am trying to calculate the difference between two colors as a human would notice. If a human being looked at two colors a and b, then two colors c and d, he could notice which ones are the most different. Firstly if the colors are bright (but not too bright) then the difference is hue based. If the colors are too bright such as white or too dark such as black or too grey then the differences are smaller.
It should be possible to have a function diff where x=diff(a,b) and y=diff(c,d) yields x and y, and I can use x and y to compare the differences to find the most different color or least different color.
The WCAG2.0 and 1.0 guidelines both make reference to different equations on perception of color difference:
contrast ratio (http: //www.w3.org/TR/2008/REC-WCAG20-20081211/Overview.html#contrast-ratiodef)
brigtness difference and 3. color difference (http://www.w3.org/TR/AERT#color-contrast).
I tried the Delta-e method(http: //colormine.org/delta-e-calculator/) but it is quasimetric so the difference measurement may change depending on the order you pass the two colors. If in your example you expect diff(a,b) to always equal diff(b,a) then this is not what you want(there may be different algorithms under this name that aren't quasimetric but I haven't looked into it past that site).
I think that the color difference metric is the closest to matching my expectations of color difference measurements. For your example it will yield that diff(a,b) > diff(c,d)
You can test it out for yourself using the tool at this website: http://www.dasplankton.de/ContrastA/
The general answer seems to be what David van Driessche said, to use Delta E. I found some Java code here: https://github.com/kennyliou/GAI
This is a answer to the question, may not be the best answer.

How to pick good contrast RGB colors programmatically?

Suppose, in your program:
color A is a color we randomly select
Knowing color A, how can I pick a color B that will be in high contrast with color A?
The problem can be further reduced to: "imagine 2 squares filled with color next to one another. It should be unambiguously clear to a human eye that colors are not the same"
Example:
Black --> White
Blue --> White
There is some information in the Web Content Accessibility Guidelines (WCAG) 2.0 (http://www.w3.org/TR/2008/REC-WCAG20-20081211)
Visual contrast: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast
Contrast ratio: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
Relative luminance : http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
There's a good example in this site but he calculate where two colors are enough, not how to get them.
To choose a color with good contrast, I'd go with complementary colors: for example, choose the random color A, transform it to a HSV space, get the complementary hue.
Complementary hue: after you transform color from RGB to HSV, complementary hue will be 180 degrees appart (or 0.5, in a 0-1 normalized hue value). This site has something about it in PHP
As I was searching for a better way to do this, i stumbled across the Adobe Illustrator guide which mentions how they create complementary colors. They say:
Complement Changes each component of a color to a new value based on the sum of the highest and lowest RGB values in the selected color. Illustrator adds the lowest and highest RGB values of the current color, and then subtracts the value of each component from that number to create new RGB values. For example, suppose you select a color with an RGB value of 102 for red, 153 for green, and 51 for blue. Illustrator adds the high (153) and low (51) values, to end up with a new value (204). Each of the RGB values in the existing color is subtracted from the new value to create new complementary RGB values: 204 – 102 (the current red value) = 102 for the new red value, 204 – 153 (the current green value) = 51 for the new green value, and 204 – 51 (the current blue value) = 153 for the new blue value.
It wouldn't be too hard to do this programmatically and think this time that it might actually work for what you are trying to do.
Good Luck!

Resources