I am currently trying to remodel the town and traffic crowd simulation found here to support self driving AI cars, which can be found here.
What I am currently stuck is is when the traffic lights where by the lights go from red straight to green, I want to add the yellow color into the simulation so the lights go from red, then to yellow then to green this is what i have but it just seems to freeze on yellow.
Please any help would be helpful, thanks.
I have below reformatted your control-traffic-lights code
to control-traffic-lights
if ticks mod (100) = 0
[ change-color lightsR ; red to yellow; others to red
change-color lightsL ; red to yellow; others to red
change-color lightsU ; red to yellow; others to red
change-color lightsD ; red to yellow; others to red
yellow-color lightsR ; yellow to green; others to yellow
yellow-color lightsL ; yellow to green; others to yellow
yellow-color lightsU ; yellow to green; others to yellow
yellow-color lightsD ; yellow to green; others to yellow
]
end
Imagine that you hit a relevant tick (every 100), start with the lightsR - any that are red get turned yellow on the first line, the get turned green on the fifth line. If they are any colour other than red on entry, they get turned red on the first line and yellow on the fifth line.
All four breeds of lights are going through the same logic. That is, the yellow-color procedure is being immediately applied to the lights based on the colour that they exit the change-color procedure.
UPDATE: I didn't make any changes to your code, I just formatted it so that it was readable to try to explain your logic issue.
If they enter as red, they get changed to green (via yellow)
If they enter as yellow, they exit as yellow (via red)
If they enter as green, they exit as yellow (via red)
What you need to do is change when the yellow-color procedure runs, so it's a few ticks later than the other colour change rather than in the same tick.
Try changing the second if ticks mod (100) = 0 [yellow-color l ...] to if ticks > 10 and ticks mod (105) = 0 [yellow-color l ...]
I'm trying to use the built-in PSReadLine (v2) module of Powershell (v5.1) to customize Powershell console text colors.
Previous versions of PSReadLine allowed you to simply specify -Background and -Foreground parameters for any given token type. But that is no longer the case. PSReadLine v2 introduced the use of ANSI escape codes to define color behavior. I gather that this allows for much greater flexibility, but it's extremely complicated for what it's meant to accomplish. Documentation about these codes is all over the place, and highly dependent on the implementation of the host application, which makes it that much harder to find answers.
Simply coloring text foreground is (relatively) easy with something like:
set-psreadlineoption -colors #{
CommandColor = "`e[93m"
CommentColor = "`e[32m"
}
However things get more complicated if you want to introduce decoration, such as bold, underline, or of particular interest to me, background color and combinations of these.
The default value for SelectionColor (which highlights selected text with a different background color) is`e[35;43m. But that big hint is still not enough to betray the syntactical secrets I'm searching for.
The doc for Set-PSReadLineOption very matter-of-factly states:
You can specify other escape sequences including:
256 color
24-bit color
Foreground, background, or both
Inverse, bold
... but provides no examples.
How would you go about specifying an escape code that defines both foreground and background color, or any other combination of colors and colored decorations?
Sources I've found helpful in learning about these escape codes are:
http://jafrog.com/2013/11/23/colors-in-terminal.html
https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
But I've not been able to fully wrap my head around any of this.
Solved:
Thanks to #LotPings. I was mistakenly assuming that escape codes could only have a set number of options given to them. In truth, I can specify as many as I want (or as many as I need to accomplish my goals). So for example:
$e = [char]0x1b
"$e[38;2;255;128;128;48;2;128;0;255;4mtest$e[0m"
... will result in the word test, which is underlined with a pink foreground and purple background. To break it down:
Use Get-PSReadLineOption to see current settings
Some attributes don't make sense in 256/24bit color modes.
Windows console doesn't support inverse (also in WSL)
The code from Jafrog's blog translated to PowerShell
## Q:\Test\2019\06\20\SO_56679782.ps1
Get-PSReadLineOption
$Esc=[char]0x1b
'The following command should print “hello” in bright red underscore text:'
"$Esc[91;4mHello$Esc[0m"
ForEach($code in 30..37){
"{0}[{1}mEsc[{1}m{0}[0m {0}[{1};1mEsc[{1};1m{0}[0m {0}[{1};3mEsc[{1};3m{0}[0m {0}[{1};4mEsc[{1};4m{0}[0m {0}[{2}mEsc[{2}m{0}[0m" -f $Esc,$code,($code+60)
}
pause
foreach($code in 0..255){"{0}[38;5;{1}mESC[38;5;{1}m{0}[0m" -f $Esc,$code}
Ansi Esc[ sequence (CSI)
Foreground Background
No Color normal bright normal bright
0 black 30 90 40 100
1 red 31 91 41 101
2 green 32 92 42 102
3 yellow 33 93 43 103
4 blue 34 94 44 104
5 violet 35 95 45 105
6 turqoise 36 96 46 106
7 grey 37 97 47 107
When I execute to a certain line of code in eclipse the background color of this line turns green. But sometimes it is a different green (light green). What does that mean?
I think following is the reason:
Green : The debugger is at that particular line at current instance
Light Green : The debugger control would come at this line once it moves past current line
Explanation with Example:
I have run some sample program(DBTest.java) in Debug mode,
Green: Current debug pointer is at line 42, hence its colour is green.
Light Green: If you at this point click on line 25 pointer it will be Light Green because control after line 42 is going to line 25.
AutoHotkey's PixelSearch allows one to search for a pixel of a certain color in an (X1,Y1)..(X2,Y2) rectangle.
But I want to find any pixel that isn't a certain color, i.e. given a background color, I want to detect when any other color comes up in the foreground.
Is there a way to do this using the built-in PixelSearch, or other built-in functions?
If you have some control over the background color, perhaps you can use PixelSearch's variation parameter.
If your background color is black, search for a white pixel with variation 254. PixelSearch should return any pixel that isn't black.
This code searches for any pixel other than BLACK (untested)
White := 0xFFFFFF
PixelSearch OutputVarX, OutputVarY, X1, Y1, X2, Y2, %White%, 254
If your background is midtone gray (0x7F7F7F), try searching for black and white with variation 127. Again, I haven't tested this. Maybe the variation should be 126 or 63. You might have to engage in some trial and error since the behavior of the variation parameter isn't comprehensively documented.
You can use PixelGetColor to look at an individual pixel. The instruction tells you the color of the pixel at location x, y. An If command determines whether the pixel is 0x9D6346 or not.
Using PixelGetColor in a Loop allows you to test a range of pixels, one at a time by incrementing x, y or both.
And yes the proper order is BGR not RGB. A look at the help file confirmed that. :)
Something is happening to change the color. Perhaps you can look for another way to detect the change on the screen. Is the change of color due to another window or message becoming active? If so there are a number of commands you can use to determine what is appearing on the screen.
The windows spy is good at determining the names of pop up messages. Even if they have the same name as an existing window you can determine which is which by the text included or excluded.
A change of the position of a particular window may be enough to detect the change you are looking for.
Perhaps a bit more detail describing what you are trying to detect will help. It would at least, confirm we are in the same ballpark.
I cannot think of a reliable way to solve this with only built-in functionality. However, you could write it yourself with help of the external GDI+-library.
backgroundColor = 0x644E37
pToken := GDIP_StartUp()
pBitMap := GDIP_BitmapFromScreen()
while(a_index <= a_screenWidth) {
w := a_index
while(a_index <= a_screenHeight) {
h := a_index
ARGB := GDIP_GetPixel(pbitmap, w, h)
RGB := ARGBtoRGB(ARGB)
if(RGB != backgroundColor) {
msgbox, % "found pixel at " w ", " h
}
}
GDIP_DisposeImage(pBitMap)
GDIP_Shutdown(pToken)
return
ARGBtoRGB( ARGB ) {
VarSetCapacity( RGB,6,0 )
DllCall( "msvcrt.dll\sprintf", Str,RGB, Str,"%06X", UInt,ARGB<<8 )
Return "0x" RGB
}
untested
Allegedly, this gdip_bitmapFromScreen() is actually faster than pixelSearch.
source
This pixel search worked for me to find any color other than white:
Search for black (0x000000),
if pixel not found
search for red (0xFF0000),
if pixel not found
search for lime (0x00FF00),
if pixel not found
search for blue (0x0000FF),
if pixel not found, the only color is pure white.
I Set all these to have a variation of 254. A variation of 255 finds everything, including white. I used lime instead of green because the official color called green has a green value of 128, while lime has a green value of 255 (red 0, green 255, blue 0). Seems that just searching for black usually finds NOT white, but sometimes you'll need to work your way down the list. This informs me whether or not there is ANY variation of ANY color other than white, including colors so close to white that I can't see them (when on a white background).
You might have to do a little math and/or experimentation for other colors, but I don't see why this method wouldn't work. I used fast RGB mode and window coordinates. Also I found helpful information here:
https://en.wikipedia.org/wiki/Web_colors
As a relative novice I hate to do this. :)
Right out of PixelSearch in the help file.
PixelSearch, Px, Py, 200, 200, 300, 300, 0x9d6346, 3, Fast
if ErrorLevel
MsgBox, That color was not found in the specified region.
else
MsgBox, A color within 3 shades of variation was found at X%Px% Y%Py%.
Understanding of hexadecimal and how the number applies to the color is necessary.
Color is expressed as a hexadecimal number. In this case 9d6346 and is broken down into three parts. I seem to recall 9d is the value for red, 63 for green, and 46 for blue. Those three numbers can range between Hex 00 to Hex FF (Decimal 0 to 255).
Variation is expressed as a Decimal number is the amount of allowable range in the search color
9D range being 9b to 9f. 63 = 61 to 66, 46 = 44 to 69. Depending on whether the search number is taken in or not my range could be out by 1.
If all else fails Google hexadecimal
Similar possibilities with PixelGetColor followed by a variety of If statements
Be prepared for a very wide variation. Some apps intermingle several distinctly different colors to achieve a desired color.
I'm searching for a method to write a text with different colors like I always saw on other IRC channels. I want to achieve this with Irssi which is CLI based. I have found multiple methods which didn't work as expected. How can I for example write
WHAT
with green color for example?
I would like to achieve the same effect from a simple Bash script too.
First, make sure to enable text colors with
/set hide_colors OFF
Within Irssi, to answer your concrete question, type
Ctrl+C 3 WHAT
and then Enter. The text will show up in green. This convention is known as mIRC colour codes. To make it more comfortable, download the colour_popup script, place it in your ~/.irssi/scripts/autorun folder and run this command:
/statusbar prompt add -after input -alignment right colours
Then it will show you the available colours once you type Ctrl + C.
On the other hand with Bash, you need to use ANSI colour codes. To output green text, try this command:
printf "\e[%dm%s\e[m\n" 32 hallo
\e[ is a CSI (terminal control sequence start) and m is the command; it means character graphics attributes like colour, bold, ...
3 refers to the dull foreground colour table, 2 is green; valid colours go from 0-7. Bright colours are 90-97; background colours are 40-47 and 100-107. There are even more colours possible with other encodings, such as 256 colour table "38;5;<idx>" where <idx> is from 0-255, or 24 bit RGB colours "38;2;12;34;56" (12/255 red, 34/255 green, 56/255 blue); this is not supported by all terminals.