renderer.material.color giving strange results - colors

I have a weird problem, that i can't figure out.
I want to change a gameobjects base color via renderer.material.color.
But for whatever reason, this only works for some colors.
This is my code:
first, I declare the colors:
var color_movement_available = Color(0.17,0.68,0.05,1);
var color_movement_available_hover = Color(0.33,1.00,0.17,1);
then i assign them, like this
case ("movement_available") :
renderer.material.color = color_movement_available;
break;
case ("movement_available_hover") :
renderer.material.color = color_movement_available_hover;
break;
However, when I test the script, the hovering color (pinkish) will not show.
I checked in the inspector and the color is the one i aimed for and is correctly switched.
When i change it to a bright (basecolor) green, red, blue or yellow, it works as supposed.
Other colors will produce white and some wont change anything.
Has anyone an idea what's causing this effect, or better yet, how to solve it?
What i tried so far:
switching the material renderer to diffuse (from transparent/diffuse):
same results
changing the materials initial basecolor to grey (from white):
also, no change
Maybe this has something to do with the way colors are applied ...
cheers
Edit: Screenshots:
Also, apparently, colors that are close to each other, like the same color only darker/lighter appear to be the ones producing white

I'm guessing you have a mesh renderer on your object.
Try GetComponent< MeshRenderer >().material.color

Related

How to change log txt file color in node js

for example, something like this.
console.log("text", "red");
How can I set log txt file font color in node js. I have done this in terminal but want to same in log txt file.
is this possible to show different color for different message in log txt file just like in terminal.
How to get colors on the command line
When working on the command line, it can be both fun and extremely useful to colorize one's output. To colorize console output, you need to use ANSI escape codes. The module colors.js, available on npm, provides an extremely easy to use wrapper that makes adding colors a breeze.
First, install it to the directory you'd like to work in.
npm install colors
Now open up a little test script for yourself, and try something like this:
const colors = require('colors');
const stringOne = 'This is a plain string.';
const stringTwo = 'This string is red.'.red;
const stringThree = 'This string is blue.'.blue;
const today = new Date().toLocaleDateString(); // returns today's date in mm/dd/yyyy format
console.log(stringOne.black.bgMagenta);
console.log(stringOne.yellow.bgRed.bold);
console.log(`Today is: ${today}`.black.bgGreen);
console.log(stringTwo);
console.log(stringThree);
console.log(stringTwo.magenta);
console.log(stringThree.grey.bold);
There are several things to take note of here - first, the string object has been prototyped, so any color may be added simply by adding the property to the string! It works on string literals, template literals and on variables, as shown at the top of the example above.
Notice, also, from the second pair of console.log statements, that once set, a color value persists as part of the string. This is because under the hood, the proper ANSI color tags have been prepended and appended as necessary - anywhere the string gets passed where ANSI color codes are also supported, the color will remain.
The last pair of console.log statements are probably the most important. Because of the way colors.js and ANSI color codes work, if more than one color property is set on a string, only the first color property to be set on the string takes effect. This is because the colors function as 'state shifts' rather than as tags.
Let's look at a more explicit example. If you set the following properties with colors.js:
myString.red.blue.green
You can think of your terminal saying to itself, "Make this green. No, make this blue. No, make this red. No more color codes now? Red it is, then." The codes are read in the reverse order, and the last/'innermost' is applied. This can be extremely useful if you're using a library that sets its own default colors that you don't like - if you set a color code yourself on the string you pass in to the library, it will supersede the other author's color code(s).
The last thing to note is the final line of the example script. While a color code was set previously, a 'bold' code was not, so the example was made bold, but not given a different color.
Using colors without changing String.prototype
Now an instance of colors can also be used. Though this approach is slightly less nifty but is beginner friendly and is specially useful if you don't want to touch String.prototype. Some example of this are:
const colors = require('colors');
const stringOne = 'This is a plain string.';
const stringTwo = 'This string is red.';
const stringThree = 'This string is blue.';
const today = new Date().toLocaleDateString(); // returns today's date in mm/dd/yyyy format
console.log(colors.bgMagenta.black(stringOne));
console.log(colors.bold.bgRed.yellow(stringOne));
console.log(colors.bgGreen.black(`Today is: ${today}`));
console.log(colors.red(stringTwo));
console.log(colors.blue(stringThree));
console.log(colors.magenta.red(stringTwo));
console.log(colors.bold.grey.black.blue(stringThree));
Unlike the String.prototype approach, the chained methods on the colors instance are executed left to right i.e., the method closest to the string is finally applied. In the last console.log you can think of your terminal saying to itself, "Make this grey. Now, make this black. Now, make this blue. No more coloring methods now? Blue it is, then."
With the latest version of colors.js you can also define Custom Themes in color.js, which makes our code more Robust and allows better Encapsulation of data. A nice use case of this maybe:
var colors = require('colors');
colors.setTheme({
info: 'bgGreen',
help: 'cyan',
warn: 'yellow',
success: 'bgBlue',
error: 'red'
});
// outputs red text
console.log("this is an error".error);
// outputs text on blue background
console.log("this is a success message".success);
One last thing: the colors can look quite different in different terminals - sometimes, bold is bold, sometimes it's just a different color. Try it out and see for yourself!
For reference, here's the full list of available colors.js properties.
text colors
black
red
green
yellow
blue
magenta
cyan
white
gray
grey
background colors
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
styles
reset
bold
dim
italic
underline
inverse
hidden
strikethrough
extras
rainbow
zebra
america
trap
random

How do I tint an svg in processing and preserve brightness?

I've been trying to figure this out for 2 days now, so I hope somebody can help.
I need to load in svg files that have multiple values of gray within them and tint them with colors. So for example, say the svg file is an image of a rock and has 4 values of gray. I need to be able to display the rock as red and keep the differences between values in the different child shapes. In other words, I would like it to work just like PImage.tint().
I see there are tint() and setTint() methods to PShape but I can't seem to get them to work. I also though about recursing through the child shapes and reading each color individually and recoloring appropriately, but I couldn't even figure out how to read the color out in a way I understand.
Help, anyone?
If you have it as an <img> you can use the CSS filter property with hue-rotate https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/hue-rotate
Or you add the svg directly to the html and add classes to your elements. Then you could change the colors in your script.
If this is a flat colour then you could use the alpha value in RGB colour value. See 'color transparency' in the following link: https://processing.org/tutorials/color/
The fill value is fill(red, green, blue, transparency)
I hope this helps. If you want to share code and have a reason for using PImage I'd be happy to have a look.

SVGO: Killing #000000 fill

I'm using svgo and am running into an odd issue where it's killing my fill color, but only if it's #000000; or any variation of the sort, black, #000. I've tried setting removeUselessStrokeAndFill to false but it continues to remove that color only. Editing the src .svg file with something different maintains the fill color. Is there a setting I'm missing? Thanks!
No, you're doing it right. There is actually an issue #115 on the svgo about this.
To fix this, you have to set your color to another black, the closer to the real black is #000001. So you can change all your black color references to this in your svg, wait for a fix, or event better, install gulp-replace and do something like this :
gulp.task('blackify', function () {
return gulp.src('*.svg')
.pipe(replace('#000000', '#000001'))
.pipe(gulp.dest('./'));
});
To clarify, this is actually right behaviour of SVGO, because the default fill and stroke colour of an SVG is black and thus useless if it's redeclared as the fill. That's the reason it's removed from the output. Any other fill which is not the default, will be left alone as intended.
See: http://www.w3.org/TR/SVG/painting.html#FillProperties

Changing the color of an EditorGUI.ProgressBar?

I want to show a ProgressBar. I am using this code:
EditorGUI.ProgressBar(Rect(3,45,100-6,20),20/700.0, "Armor");
I want to change the color of the ProgressBar from a light blue color to a red color. How can I do this?
As it stands, it doesn't appear that you can. However, I had a similar issue where I wanted a very customized bar with different colors to denote different things. I ended up using EditorGUI.DrawPreviewTexture. If you initialize the colors you want to use as a Texture2D, then pass them into that function with the properly placed rectangles, you can create portions of a bar that can change size and location to give the appearance of a standalone progress bar, especially if you keep the positions and size updated in the Update() function.

Find most readable colour of text that is drawn on a coloured surface

I'm not sure how to ask this but here goes.
I draw a filled coloured rectangle on screen. The colour is in form of R,G,B
I then want to draw text on top of the rectangle, however the colour of the text has to be such that it provides the best contrast, meaning it's readable.
Example:
If I draw a black rectangle, the obvious colour for text would be white.
What I tried right now is this. I pass this function the colour of the rectangle and it returns an inverted colour that I then use for my text.
It works, but it's not the best way.
Any suggestions?
// eg. usage: Color textColor = GetInverseLuminance(rectColor);
private Color GetInverseLuminance(Color color)
{
int greyscale = (int)(255 - ((color.R * 0.30f) + (color.G * 0.59f) + (color.B * 0.11f)));
return Color.FromArgb(greyscale, greyscale, greyscale);
}
One simple approach that is guaranteed to give a significantly different color is to toggle the top bit of each component of the RGB triple.
Color inverse(Color c)
{
return new Color(c.R ^ 0x80, c.G ^ 0x80, c.B ^ 0x80);
}
If the original color was #1AF283, the "inverse" will be #9A7203.
The contrast will be significant. I make no guarantees about the aesthetics.
Update, 2009/4/3: I experimented with this and other schemes. Results at my blog.
The most readable color is going to be either white or black. The most 'soothing' color will be something that is not white nor black, it will be a color that lightly contrasts your background color. There is no way to programmatically do this because it is subjective. You will not find the most readable color for everyone because everyone sees things differently.
Some tips about color, particularly concerning foreground and background juxtaposition, such as with text.
The human eye is essentially a simple lens, and therefore can only effectively focus on one color at a time. The lenses used in most modern cameras work around this problem by using multiple lenses of different refractive indexes (chromatic lenses) so that all colors are in focus at one time, but the human eye is not that advanced.
For that reason, your users should only have to focus on one color at a time to read the text. This means that either the foreground is in color, or the background, but never both. This leads to a condition typically called vibration, in which the eye rapidly shifts focus between foreground and background colors, trying to resolve the shape, but it never resolves, the shape is never in focus, and it leads to eyestrain.
Your function won't work if you supply it with RGB(127,127,127), because it will return the exact same colour. (modifying your function to return either black or white would slightly improve things)
The best way to always have things readable is to have white text with black around it, or the other way around.
It's oftenly achieved by first drawing black text at (x-1,y-1),(x+1,y-1),(x+1,y-1),(x+1,x+1), and then white text at (x,y).
Alternatively, you could first draw a semi-transparent black block, and then non-transparent white text over it. That ensures that there will always be a certain amount of contrast between your background and your text.
why grey? either black or white would be best. white on dark colors, black on light colors. just see if luminance is above a threshold and pick one or the other
(you don't need the .net, c# or asp.net tags, by the way)
You need to study some color theory. A program called "Color Wheel Pro" is fun to play around with and will give you the general idea.
Essentially, you're looking for complimentary colors for a given color.
That said, I think you will find that while color theory helps, you still need a human eye to fine tune.

Resources