ID:2702277
 
(See the best response by Kaiochao.)
Hey folks, I have a question and I'm unsure if BYOND has a function for it.

I was working on my coloring for the game, right now stuff like grass and water has a single icon that has four directions with varying degrees of color changes.

I am wondering, is there a way I could just do something like src.icon += Color, but instead of that, I want it to pick a specific color of green from all green colors.

I am unsure how well I am explaining it. Right now my grass has four variations in color for N,S,E and W directions. I'd like to just have the icons change their colors, randomly picking from their entire green color selection, or maybe a range or something?

Sorry if this was hard to read.
color = "#0f0"
color = "#00ff00"


Can use the color variable and supply a green color to it.
I'm not sure if you mean you want the icon to randomly one of the four variations, or if you mean you want the actual color cast of the icon to vary beyond those four variations.

If you wanted to just have the icon use one of the four directions randomly when you start the world, you could do this:

turf/grass/New()
dir = pick(NORTH, SOUTH, EAST, WEST)

Mind you, New() procs on turfs can be a performance killer as you scale up, so you might instead want a proc that just loops through everything after the map loads and does all this in one swoop. But anyway that's something to think of down the road, not necessarily at this stage.

Now if you wanted something like altering the color a little bit at random, you could use atom.color for that. The color var is multiplied if you just use an ordinary color, or you can set a matrix if you want the color to be added or do more complex stuff.

If you're giving each turf a unique color, bear in mind that you'll be creating a lot more appearances, which will use more memory and require more network overhead. This isn't necessarily a bad thing if it's the look you want, but worth being aware of all the same.
In response to Lummox JR
Lummox JR wrote:
I'm not sure if you mean you want the icon to randomly one of the four variations, or if you mean you want the actual color cast of the icon to vary beyond those four variations.

If you wanted to just have the icon use one of the four directions randomly when you start the world, you could do this:

turf/grass/New()
> dir = pick(NORTH, SOUTH, EAST, WEST)

Mind you, New() procs on turfs can be a performance killer as you scale up, so you might instead want a proc that just loops through everything after the map loads and does all this in one swoop. But anyway that's something to think of down the road, not necessarily at this stage.

Now if you wanted something like altering the color a little bit at random, you could use atom.color for that. The color var is multiplied if you just use an ordinary color, or you can set a matrix if you want the color to be added or do more complex stuff.

If you're giving each turf a unique color, bear in mind that you'll be creating a lot more appearances, which will use more memory and require more network overhead. This isn't necessarily a bad thing if it's the look you want, but worth being aware of all the same.

The direction thing is how I'm doing it now, instead I was hoping there would be an easy way for me to have, say the grass, randomly choose a #Color, but only like within a specific range of color hues, in this case, every range of green.

I ended up deciding just to use pick() and then manually type every #Color I wanted.
In response to HartWing
Best response
HartWing wrote:
I was hoping there would be an easy way for me to have, say the grass, randomly choose a #Color, but only like within a specific range of color hues, in this case, every range of green.
You can use the gradient() function for this. Given two shades of green and a random index, you can get a random shade between them, for instance. With a white base grass texture icon, setting the color var of the grass to green will make it green. You could even set it to other colors based on the time of year.
In response to Kaiochao
Kaiochao wrote:
HartWing wrote:
I was hoping there would be an easy way for me to have, say the grass, randomly choose a #Color, but only like within a specific range of color hues, in this case, every range of green.
You can use the gradient() function for this. Given two shades of green and a random index, you can get a random shade between them, for instance. With a white base grass texture icon, setting the color var of the grass to green will make it green. You could even set it to other colors based on the time of year.

Yeah that was the plan, almost all terrain in the game has hues of colors associated during specific "seasons".

I didn't know you could use white, I've been using black. But now that I type this, I remember my Art teacher telling me white and black weren't considered colors, but void of colors. So in this case, is white and black interchangeable?
In response to HartWing
When the color var of an atom (such as a turf) is set to a singular literal color (not a color matrix), the atom is rendered with each pixel's RGB color components multiplied component-wise by the components of the assigned color, but the components are scaled to the 0-1 range instead of 0-255.

Black is (0, 0, 0), so any color multiplied by black becomes black.
White is (1, 1, 1), so any color multiplied by white is unchanged.
If your grass texture is white to begin with, and you multiply it by green, the result is green. Darker shades of white (gray) become darker shades of green.

It's just based on pretty simple math and it likely has nothing to do with what your art teacher has told you about colors.
In response to Kaiochao
Kaiochao wrote:
When the color var of an atom (such as a turf) is set to a singular literal color (not a color matrix), the atom is rendered with each pixel's RGB color components multiplied component-wise by the components of the assigned color, but the components are scaled to the 0-1 range instead of 0-255.

Black is (0, 0, 0), so any color multiplied by black becomes black.
White is (1, 1, 1), so any color multiplied by white is unchanged.
If your grass texture is white to begin with, and you multiply it by green, the result is green. Darker shades of white (gray) become darker shades of green.

It's just based on pretty simple math and it likely has nothing to do with what your art teacher has told you about colors.

Fair enough. I'm just awful at math and stay away from it.