Changing the color of agents in NetLogo according to a turtle-own variable - colors

I am writing a simple food exchange model in netlogo and I want the agents to change their color as their [food] level changes in the model. The amount of food is in range [0,1] and I want the color to change from white to red (white = food level of zero and red = food level of 1) with the code below:
ask turtles [
set color scale-color red food 1 0 ]
But my turtles turn black somehow in the middle of food exchange! Turtles own food value can be any floating point number in the range [0,1]. Does anyone know how I can keep the color within the light shades of red (red to white) and no black?

Scale-color and ranges
From the example above, the color and number are correct, but the issue seems to be with the range provided. Since food is within [0,1], the color gradient should match the changes, though it will be from 0 (white) to 1 (black).
As JenB mentioned, you might want to extend the range of the expected values. Changing the range from [0,1] to [0,2] for scale-color would help, since with scale-color the midpoint of the range is the color provided.
[ set color scale-color red food 2 0 ]
As long as food is within [0,1], this example should fluctuate between red and white.

Related

Power Query to sum for each color and each size, return a value on the available size list

I have a list of shirt colors and the suggested sizes of them. I would like to create a new column in the query and have a value of list based on the filtered elements ( I have no idea how to explain it differently, feel free to correct me). So the rules are:
If the current color has XS in the occurrence list then the value of the row needs to be "YES"
If the current color does not have XS but has XXL,XL or L then the value should be "XYES"
Otherwise the value needs to be "NO"
Jacket Color
Jacket Size
Black
XS
Black
XS
Black
S
Blue
XS
Blue
L
Blue
XL
Blue
XXL
Blue
XL
Blue
XXL
Green
XS
Green
S
Green
M
Red
XS
Red
XXL
Red
S
Red
XXL
White
S
White
M
The table should look like this:
Jacket Color
Jacket Size
New_col
Black
XS
YES
Black
XS
YES
Black
S
YES
Blue
XS
XYES
Blue
L
XYES
Blue
XL
XYES
Blue
XXL
XYES
Blue
XL
XYES
Blue
XXL
XYES
Green
XS
YES
Green
S
YES
Green
M
YES
Red
XS
XYES
Red
XXL
XYES
Red
S
XYES
Red
XXL
XYES
White
S
NO
White
M
NO
I am not that big of a tech guy myself, if you can help me how to google the answer, that is good aswell.Thank you in advance.
Tried everything I could with this little knowledge I have about power query. If this could be solved by me, I would have a job right now.
Your result data doesn't match your sample data but this is the process.
Import data in PQ
Select Jacket Color and then group by from the ribbon. Enter the following:
Add a new custom column from the ribbon and enter the following:
if List.Contains([All][Jacket Size], "XS") then "Yes" else if List.ContainsAny([All][Jacket Size], {"XXL","XL", "L"}) then "XYES" else "No"
Expand the column to get all rows back.

Why does paired columns with the same name from a df get changed after being imported on Python using pandas?

I realized of something very weird today, I have a .csv file which contains a df that is displayed as shown below when open with Excel:
One could think after executing the following code on Python3x:
import pandas as pd
metadata_file_path = r'C:\Users\ResetStoreX\Pictures\Metadata.csv'
df_metadata = pd.read_csv(metadata_file_path, index_col=0)
print(df_metadata)
The expected output should be this one down below:
0 0 1 1 2 2 3 3 4 4 5 5
0 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes None
1 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Brown
2 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Green
3 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Purple
4 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Sand
However, it ends up being this one instead:
0 0.1 1 1.1 2 2.1 3 3.1 4 4.1 5 5.1
0 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes None
1 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Brown
2 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Green
3 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Purple
4 Background Ocean Body Crab Colour Dark green Eyes type Antennae Claws None Spikes Sand
As can be seen, the columns with the same name were modified by Pandas (or Python) when imported, so it was added 0.1 to the next column with the same name of the previous one.
I don't understand why this happens, and if possible, I would like to know a way of preventing this unexpected modification.
Pandas read_* methods always prevent duplicated columns names, because is problem with selecting.
If use df[0] it select both columns, not one.
For original columns names is possible use:
df.columns = df.columns.str.split('.').str[0].astype(int)
Another idea is used first values before . for grouping without change columns names:
row = 0
d = {x.iat[0]: x.iat[1] for name, x in df.iloc[row].groupby(lambda x: x.split('.')[0], level=0)}

How to extract a particular word from a cell in excel that matches a list of values

How to extract a particular word from a cell in excel from a list (array) of possible values and return that matched word.
I have a list of products, but I just want to know the color. The color is embedded in the products description, therefore I need to extract it out of the item description. Here is a brief example of a list the item descriptions:
CORNER CCP 26" BARN RED
CORNER CCP 28" KHAKI
CORNER CCP 28" SLATE GRAY
CORNER RS EZ ANTIQUE GRAY
CORNER RS EZ 26" ASHWOOD GRAY
CORNER,RSC EZ,AUTUMN CEDAR
CORNER RS EZ 26" BARN RED
CORNER RS EZ 26" CANARY YELLOW
CORNER RS EZ 26" COASTAL BROWN
CORNER,RS EZ 26" COASTAL CLAY
CORNER,RS EZ 26"COASTAL CEDAR
CORNER RS EZ 26" CYPRESS GREEN
CORNER RS EZ 26" CLASSIC WHIT
I want to then compare that Item description with a list of colors I have and then just return those color names.
Amaranth
Amber
Amethyst
Apricot
Aquamarine
Azure
Baby blue
Beige
Black
Blue
Blue-green
Blue-violet
Blush
Bronze
Brown
Burgundy
Byzantium
Carmine
Cerise
Cerulean
Champagne
Chartreuse green
Chocolate
Cobalt blue
Coffee
Copper
Coral
Crimson
Cyan
Desert sand
Electric blue
Emerald
Erin
Gold
Gray
Green
Harlequin
Indigo
Ivory
Jade
Jungle green
Lavender
Lemon
Lilac
Lime
Magenta
Magenta rose
Maroon
Mauve
Navy blue
Ocher
Olive
Orange
Orange-red
Orchid
Peach
Pear
Periwinkle
Persian blue
Pink
Plum
Prussian blue
Puce
Purple
Raspberry
Red
Red-violet
Rose
Ruby
Salmon
Sangria
Sapphire
Scarlet
Silver
Slate gray
Spring bud
Spring green
Tan
Taupe
Teal
Turquoise
Violet
Viridian
White
Yankees Blue
Yellow
Place the data in column A.
Place the list of colors in column B.
Place the following array formula in column C and fill down:
=IFERROR(INDEX($B$1:$B$86,MATCH(1,COUNTIF($A1,"*"&$B$1:$B$86&"*"),0)),"")
Note that this is an array formula. In order for it to operate correctly, first copy and paste from your browser window to Excel, then, with the same cell selected, click in the formula bar (or press F2) and press Control + Shift + Enter. There should now be braces around the formula.
If the string in column A contains more than one of the colors in column B, the first matching column B color will be listed.

Changing Bar colors using VBA based on category label

I have a VBA code in excel to change colors of bar graph but its not working for category series.
ActiveChart.SeriesCollection(1).Interior.Color = RGB(0, 153, 64)
I want to change the color of a single bar. However, the above code changes the color of all bars.
For all bars I want one color (green) except for two bars representing two data points (Average1 and average2); these should be of a different color. Can anyone please tell me how to to this with VBA?
Jesse's answer is often the cleanest way to do it.
However, it is not accurate that "to have different colored bars they must be on different series" (my emphasis). You can mix and match colors within one series. For example, this makes the second bar of the first series red:
ActiveChart.SeriesCollection(1).Points(2).Interior.Color = RGB(255, 0, 0)
You can use this to do all kinds of neat tricks, such as highlighting bars that exceed some threshold, are associated with leap years, or whatever. You could certainly choose to highlight your average1 and average2 values this way.
If you want to change the color for a point that has a given characteristic, then you have to loop through all points until you find a point that has that characteristic. For example, if you want to color in red the point whose category (XValue) is "avg" then you could do this:
Dim c As Chart
Dim s As Series
Dim iPoint As Long
Dim nPoint As Long
Set c = ActiveChart
Set s = c.SeriesCollection(1)
nPoint = s.Points.Count
For iPoint = 1 To nPoint
If s.XValues(iPoint) = "avg" Then
s.Points(iPoint).Interior.Color = RGB(255, 0, 0)
End If
Next iPoint
Your problem isn't with the VBA, to have different colored bars they must be on different series.
Leave a gap in the base colored series and add the values you want colored on a second series and color that. Your data would look something like this:
Series | Month 1 | Month 2 | Month 3 | Month 4 | Month 5 | Month 6 | Month 7
1 10 12 15 14 10
2 17
3 18

How is transparency actually implemented ?

Given two images A,B I want a third image C which is as if B had transparency of t=0.5 and placed on top of A.
How is C calculated in reality and how n affects it ? I am not interested in any program or pseudo code I just want to know the basic rationale.
One way I think is C is nothing but alternating pixels of A and B. What are the other ways ?
The color and optionally transparency of each pixel of A and B is combined according to the weight.
If the transparency is 0.75, then typically 25% of the color values from B and 75% of the color values from A (the underlying image) would be used.
Basically, the red, green, blue, and optionally the alpha channels are each calculated like this, and then recombined to form one resulting pixel.
Example:
A = [1 0 0] <-- red
B = [0 1 0] <-- blue
a = 0.75 (which means B is more transparent than it is opaque)
C = [
0.75 = 1 * 0.75 + 0 * 0.25 (red component)
0.25 = 0 * 0.75 + 1 * 0.25 (green component)
0.00 = 0 * 0.75 + 0 * 0.25 (blue component)
] // A B
If the images have alpha channels on their own, the calculation becomes more complex.
I am not sure if by "reality" you mean source code that hacks such effect, or how it works in nature.
In code
You can overlay images transparently by a simple linear interpolation of both input images:
Color lerp (Color lhs, Color rhs, real f) {
return (1-f)*lhs + f*rhs;
}
Image overlay_transparent (Image a, Image b, real f) {
assert (a.width == b.width);
assert (a.height == b.height);
Image output;
for_each (y : 0 .. a.height)
for_each (x : 0 .. a.width)
output(x,y) = lerp(a(x,y), b(x,y), f);
return output;
}
You could then do a 50% overlay by calling overlay_transparent (a,b, 0.5).
In reality
Transparent materials reflect a fraction of the incoming light, some fraction is absorbed,
and another fraction is transmitted through the material.
A perfect mirror reflects all of the incoming light specularly, each particles outgoing vector
solely depends on its incoming vector.
A perfectly diffuse material reflects all of the incoming light, but for each incoming vector
there are infinitely many possible outoing vectors within the hemisphere over the hit-point.
A perfectly absorbing material is black like The Void itself.
A perfectly transmitting material that does not perturb particles on their way through the material
would be invisible.
All of these perfect materials are not found in nature so far, and most real world materials are a mix of them.
Note that this is a science in itself; for deeper knowledge, you could begin studying Realistic Image Synthesis
and Path Tracing, as well as the concept of BRDF/BSDF/... .
For each pixel, the value of each component in C (Red, Green Blue) is the average of the values for the components of A and B.
If the transparency is not 50% a weighted average is used.
If you use alternating pixels the result will not be smooth. If A is all black and B is all wight alternating pixels would give a striped pattern while average RGB values on each pixel gives an even 50% gray surface.

Resources