I want a turtle to move randomly across the interface screen but I need the turtle to freeze if it lands on a 'danger patch'. If the turtle does not land on a 'danger patch' it continues to move. Could someone please help me figure this out?
Levi, in setup, you need to give each turtle a variable that indicates whether the turtle is frozen or not. You should decide what pcolor of patches you want to mean "danger!"
On each go step, if the turtle is not frozen, it can take a step and then check the pcolor of the patch it's on to see if it should be frozen now.
When every turtle is frozen, stop.
The code below will accomplish that.
globals [ danger-color ]
turtles-own [
frozen? ;; each turtle needs its own true-false switch for whether it's frozen.
;; this is a true/false variable so the name ends with "?"
]
to setup
clear-all
;; pick a color you like for dangerous areas. I picked red.
set danger-color red
;; set the bottom half of the viewing area to the danger color
no-display
ask patches with [pycor < 0] [set pcolor danger-color ]
display
;; create 2 big yellow turtles that are not frozen and move them up
create-turtles 2 [
set color yellow
set size 3
setxy random-pxcor 10 ;; put them somewhere on top half of the screen
set frozen? FALSE ;; initially all turtles are not frozen
]
reset-ticks
end
to go
;; see if there is any point in continuing to run
if not any? turtles with [frozen? = FALSE] [stop ]
ask turtles with [ frozen? = FALSE ]
[
set heading random 360
forward 1
;; and check to see if maybe NOW we should be frozen
if pcolor = danger-color
[
set frozen? TRUE
set color blue
]
]
tick
end
Note that I could have just put "red" instead of defining a danger-color, which would save a few keystrokes but that would also make the code harder to update and understand.
if pcolor = danger-color makes it clear what you are testing for, where
if pcolor = red is not so obvious. Trust me, a month later when you come back
to the code, you will appreciate the fact that you did this.
Using a variable like that also means that, if you change your mind about what color should represent danger, you only need to change it exactly one place in the code, and you know where that is. Having "red" hard-coded into your program multiple places makes it hard to find them to update and almost guarantees you will miss one.
Make a comment if this is not clear, and I'll try to explain it better!
Have fun with NetLogo! Thanks for looking for an answer here!
Related
I use Netlogo 6.0.4, In the interface there is a chooserbutton, which is a set of different colors
I want to change all patches colors when the color changes, i.e. when event happens. As alternative , I can add a button to color patches based on color which was chosen recently, but I prefer not to.
Is there some solution for that
A button pushes a piece of code into the run, but a chooser just selects a particular value of a variable. If you want to control colours during the run with a chooser, then you need to query that variable regularly. Since your question says that you want to change colour when an even happens, then you could simply query the variable when that event occurs.
Alternatively, just have ask patches [ set pcolor patch-color ] in the go procedure (assuming your chooser is called patch-color). Assuming you have the standard NetLogo setup of a go procedure with all your actions and the tick then your patches will be appropriately coloured but there will be a slight delay between the event occurring and the change of colour because it won't update until that code is reached.
[Edited question] If I have an api.ai discussion app which dynamically creates buttons with the intent names on them: Say I ordered a sandwich and now api.ai is asking me what spread I want, but, ALSO at the same time CHANGES THE UI and SHOWS me the options: Mayo, Mustard, Ketchup as checkbox-buttons to press. This app will be specific for a visually impaired but not totally blind person using this, who has VoiceOver set up for accessibility.
They now see:
Dressings Salads
[ ] Mayo $2.40 [ ] Tuna $11.50
[ ] Mustard $0.85 [ ] Olives $4.60
[ ] Ketchup $8.19 [ ] Anchovies $99.99
The voice-over will automatically say:
Dressings: Checkbox mayo dollars 2.40,
checkbox mustard dollars zero point 85, checkbox ketchup....
I do not want to hear that message, but rather the API.AI reply which would talk in "natural language discussional speak":
"Do you want anything added? We have salads and dressings..."
I don't want the voice-over and app.ai to interfere with each other. What do I do? Any thoughts? How do I temporarily disable the voice-over?
Important: If the semi-blind user momentarily leaves my app and goes to another app, or chooses my app's settings page, the voice-over should work as usual. Only while in this certain screen I want the voice-over disabled, and the API.AI to take over. Can this be done programatically?
Maybe as you click on the option, it says the option. So then they know what they've pressed. If you're worried about it overlapping the audio if you press two different options at nearly the same time, you could try to cut the audio short if there is a choice in different options .
I have to use a software which list my clients processes. I need a sound alert program if something change on 50x10 pixel region. I try to write a program on autohotkey but i can't succeed in. Anybody have this program?
Here is an example that you can use.
^Launch_Media:: ; Make a reference screenshot with NirSoft NIRCMD by pressing Ctrl+Media or any other program...
run, "C:\Program Files\1 My Programs\nircmd.exe" savescreenshot "c:\Temp\Screenshot.bmp" 33 40 17 20 ; Location of "Save As" Icon in SciTE4AutoHotKey Editor
Return
Launch_Media:: ; Launch this test manually with Media Button
CoordMode Pixel ; Interprets the coordinates below as relative to the screen rather than the active window.
ImageSearch, FoundX, FoundY, 0, 0, 200, 200, C:\Temp\Screenshot.bmp ; search for image in area staring at 0,0 to 200,200
if ErrorLevel = 2
MsgBox Could not conduct the search.
else if ErrorLevel = 1
MsgBox Image could not be found on the screen.
else
SoundBeep, 1000, 1000
MsgBox The Image was found at %FoundX% %FoundY%.
ClickX:=FoundX + 5 ; Move the mouse click away from the edge of the icon
ClickY:=FoundY + 5 ; Move the mouse click away from the edge of the icon
Click, %ClickX%, %ClickY% ; Click on the Save As icon.
Return
When we know more about what you want to test (I think that an area of 50x10 might be too small), and what you want to do in case the area has changed, we might be able to help you with a more suited script.
In this example I used NirSoft's nircmd.exe, but you can create a reference image by other means as well. If You only need an audible alarm, you can comment all the other commands under if, then, else out with ;.
Did you check this post from 2 years ago in the AutoHotKey community?
http://www.autohotkey.com/board/topic/56219-fast-screen-change-check-using-histograms/
The above script might be a little overwhelming, but you can also create a screenshot of a fixed area and do an image comparison in AutoHotKey as others have done before you.
Spent hours trying to figure this out and still haven't got it. None of the documentation mentions anything about it. Is this something rebol just can't do without manually having to rearrange everything with origin?
Perhaps I'm just expecting too much?
edit: well I've discovered a hack: indent num, then indent -num on the next line . Out of all the spectacular features of this language why couldn't they have just added a simple command like center?
There is a CENTER-FACE function you can reuse to align faces, but unfortunately it doesn't work very well from my experience. Here is a simpler replacement version that should do the trick:
center-face: func [face [object!] parent [object!]][
face/offset: parent/size - face/size / 2
]
Here is a usage example:
lay: layout [
size 300x300
b: button "Hello World"
]
center-face b lay
view lay
First off, VID is not Rebol, but a demonstration dialect written by the author, Carl Sassenrath, to demonstrate how interfaces could be dialected in Rebol. There are others including RebGUI ( http://www.dobeash.com/rebgui.html ) though I suspect there isn't a way to center buttons there either as neither author considered it important.
You can also use PAD to align the cursor close to the center of the layout.
We can't center or align stuff based on the window itself because controls do not have any way to refer to their parent face until AFTER the parent has had 'SHOW called on it.
face/parent-face isn't set until the parent has been shown. So in normal VID you need to tweak the gui just after the initial layout & view has been done.
here is a little script which shows how to center any face, after its been shown at least once.
view/new is used to delay event handling, in order to modify the layout.
rebol []
center: func [face][
face/offset/x: (face/parent-face/size/x / 2) - (face/size/x / 2)
show face
]
view/new layout [
across
t: h1 "This is a centered title!"
return
button "1"
button "2"
button "3"
button "4"
]
center t
do-events
I have a mac application that i have created that measures bandwidth. I have setup alerts for the user when they have reached a certain percent of the bandwidth. I have options to disable the warning value (yellow bars) and the critical cells (red bars).
The issue is that when the user "turns off" the critical value both upload and download bars turn red (no matter what their position is).
What I am doing is "Off" sets the critical or warning values to 100% of the maxValue. This seems to work for turning off both critical and warning alerts (only green bars).
So my question is, is there a way to disable the critical values (red) and/or the warning values (yellow)?
This is kind of a hack... but I've disabled the warning section in my app by doing something like the following:
levelIndicator.criticalValue = threshold;
levelIndicator.warningValue = threshold-.00001;
If I make them equal, both are disabled and the bar is always green, but by making the warning some tiny bit below the critical level, it goes from green to red, and I never see any yellow. (The difference between engineering and mathematics... )
To disable the critical/red section, and show only green and yellow, try something like:
levelIndicator.warningValue = threshold;
levelIndicator.criticalValue = levelIndicator.maxValue+1;