Ask turtle to turn face other target depending on patch features - algorithm

I'm stuck at this part of my code.
I want to move my turtle under my control. I mean when it first reached a house, it must turn and move to another house.
In this code, it will move -10 5 which red patch and house shape here.
Now, how can I tell this turtle ''you are here and you must go there'' !?
(I use a red patch because I tried to move the turtle depending on patch but can't find any solution.)
breed [cities city]
breed [flag person]
to setup
clear-all
set-default-shape cities "house"
create-flag 1
[ set SIZE 6 set shape "by" setxy -5 3 set HEADING 0 ]
create-flag 1
[ set SIZE 6 set shape "sel" setxy 12 5 set HEADING 0 ]
create-cities 1
[set color yellow set SIZE 2 setxy 8 2]
create-cities 1
[ set color yellow set SIZE 2 setxy -10 5]
ask patch -10 5 [set pcolor red]
end
to go
ask flag with [ shape = "by" ] [ facexy -10 5 forward 1 set HEADING 0 ]
end
Update
I understand and tried this code from #jenB's answer and it's yet not moving as I want. Thank you for your interest, but there are two problems here that I tried to explain with this picture.
I've started a new question about this here:
Turtles, patches and their moving sequentially from one patch to the next

Look up turtles-on in the NetLogo dictionary. From your other question, I know that you are trying to make your flags move sequentially from one house to the next. One way to do that is to have the flag store its target and simply change the target when it reaches one. Something like this (this will not work as it is incomplete)
breed [cities city]
breed [flag person]
flag-own
[ target
]
to setup
clear-all
create-flag 1
[ set size 6
set shape "by"
setxy -5 3
set target patch -10 5
face target
]
< other commands >
end
to go
ask flag-on patch -10 5
[ set target patch <next place you want it to go>
face target
]
ask flag with [ shape = "by" ]
[ forward 1 ]
end
I also got rid of all your set heading commands. The command face turns the turtle so that forward is towards whatever the turtle is facing. The command set heading turns the turtle so that forward is in the direction given by the heading (for example set heading 90 will make it move to the right if told to go forward).

Take a look at Move Towards Target Example, in the Code Examples section of NetLogo's Models Library. It does exactly this, if I understand your question correctly.

Related

GIMP Script-Fu: "Error: <: argument 1 must be: number"

I'm having an issue with writing a GIMP Script that applies a drop shadow. So this is how the script looks when you pull it from the console:
(script-fu-drop-shadow run-mode image drawable value value value color value toggle)
And these are the values I've entered:
(script-fu-drop-shadow 1 image layer 0 0 3 '(115.9 200.9 245.1) 1 0)
When I try to run it, I get the following error:
Execution error for 'MUA Portrait Outline - Blue Glow':
Error: <: argument 1 must be: number
I think I'm not really understanding all the values that I need to enter.
run-mode is straightforward, since it says to either use 1 or 0.
Based on prior scripts I've tried, I'm pretty sure that I leave image as image since it's just for the current image.
I'm not too sure what drawable is, but I read that drawables include layers, so I put layer. Not sure if that's accurate.
The next 3 value variables are for the x offset, y offset, and blur radius. Straightforward.
I'm not too sure if I'm entering color correctly as I've never actually used a script that asks for the color, but I think I did it correctly just based on some research I did online.
The last value variable is also straightforward, as it's the opacity of the shadow.
I have no clue what to set for toggle. It says it accepts INT32 for that, so I figured I would just put 0. I tried to do some online research, but I couldn't find anything
Any help would be greatly appreciated! I'm not well-versed in Script-fu. I've tried a few things here and there, but I don't know much formal stuff. Feel free to explain things as simply as possible :)
You have to find numbers of current image and current drawable (if you are working with multiple images, these don't have to be 1 and 3), then call it without run-mode:
> (gimp-image-list)
(1 #(1)) <-- All images, current image is one number from vector #(1)
> (gimp-image-get-active-drawable 1)
(3) <-- Current drawable of current image
> (script-fu-drop-shadow 1 3 0 0 20 '(255 0 0) 100 0)
(#t)
If you don't know meaning of some arguments, you can check Procedure Browser (Help → Procedure Browser)- toggle argument is Allow resizing and you can also use TRUE or FALSE as value, because they evaluate to 1 or 0 respectively.
EDIT: If you want run this as .scm script, follow these steps:
.scm file should look like this:
(define (script-fu-my-script image drawable)
(script-fu-drop-shadow image drawable 0 0 20 '(255 0 0) 100 0))
(script-fu-register "script-fu-my-script"
_"Add _Drop _Shadow..."
_"Add drop shadow"
"Author's name"
"Author's name"
"12/9/21"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0)
(script-fu-menu-register "script-fu-my-script"
"<Image>/My_Scripts/Drop")
Find correct folder for your scripts: Edit -> Preferences -> Folders -> Scripts and move your .scm file to one from these folders.
Restart GIMP or refresh your scripts: Filters -> Script-Fu -> Refresh Scripts
Right click on image, My Scripts -> Drop -> Add Drop Shadow.
It works if you drop the run-mode argument.
(script-fu-drop-shadow 1 3 3 3 3 '(115 200 245) 50 0)
Don't ask me why, I write my scripts in Python :)
For that matter most of the code in that script is handling things that mostly make sense when using it interactively. In most case your code can do it by selecting alpha, adding a layer, filling the selection, blurring it and adjusting the offset.

Assign Turtles to Random Empty Patch

In my setup, I am using the following code to create agents called "darks", and these agents are assigned to a designated set of patches (free-patches).
I am trying to have each turtle assigned to a random patch within the designated area without any of the turtles sharing a patch.
I have stumbled across code that tells a patch to sprout a specific turtle, but can I accomplish my goal without resorting to the patch sprout?
create-darks #-of-darks [
set shape "person"
set size 1
set color black
move-to one-of free-patches
]
You can just get a patch with no darks there.I would also only create a dark if there's enough space.
let n-or-remaining-spaces min (list n (count patches with [not any? darks-here]))
create-darks n-or-remaining-spaces
[
;;Your other setup code
move-to one-of patches with [not any? darks-here]
]

Animating a single data file using gnuplot

I use FORTRAN 77 code to generate data (saved as filename.dat) of simple physics situations containing x-y co-ordinates like a projectile.
My data files usually have 2 or 3 columns like so:
1 1
2 2
3 3
4 4
5 5
I can plot (2d and 3d) using Gnuplot just fine but I want to animate the point and make it look like a real projectile on the graph and then save it as a .gif file.
I am new to bash scripts so please assume I do not know a single thing about scripts, if it involves using those.
Thanks!
Problem solved. This is the code I am using:
set terminal gif animate delay 100
set output 'output.gif'
stats 'data.dat' nooutput
set xrange [-0.5:1.5]
set yrange [-0.5:5.5]
do for [i=1:int(STATS_blocks)] {
plot 'data.dat' index (i-1) with circles
}
Gnuplot version 4.6 or higher is required for this to work. This code must be entered in gnuplot. This requires the data to be in the following format:
1 1
2 2
3 3
4 4

How can I modify a screensaver (.saver)?

My goal is to be able to modify a Matrix screensaver that is no longer being supported by the developers. I simply want to be able to change the color of the glyphs from green to red. From what I've read, I might need to edit the compiled .nib file. And supposedly, there are tricks to do this.
The only files I see within the .saver file are:
Unix Executable File
InfoPlist.strings
Matrix.nib
a Glyphs.png (its in grayscale, so the color affect must come from programming)
A Matrix.nib file in a folder entitled Japanese.lproj
I don't see any other files that I could edit that would let me achieve this, so I am looking for some guidance.
EDIT: The author posted the source code for his screensaver on his github. Now i'm just trying to figure out exactly what needs to be changed.
The modification of the source code isn't very hard. The colors are computed on the fly, so an asset can't be modified to change the color.
In line 226 of MatrixStrip.m change the 1 before the left bracket to a 0. In Line 228 Change the 0 to a 1. The column below the V in the code.
.... V
226: colorArray[16*i + 4*c + 0] = (cellState[i] == 0) ? 0.0 : g;
227: // Cells which are very bright are slightly whitened
228: colorArray[16*i + 4*c + 1] = ((g > 0.7) && (cellState[i] != 0)) ? (g - 0.6) : 0.0;
Make the same change to lines 253 and 255. You are putting the numbers in column column 34 in the inner loops in order. In the original code, reading down column 34 the numbers a 1, 0, 2, 3. This has to be done in both of the inner loops on the 4 lines I indicated. These numbers are the indices to the RGBA color.
I'm not sure if my explanation is adequate, so instead of expanding this to 1000 words, I'll include a screen shot of the diff with the relevant parts highlighted by Kaleidoscope. The original code is on the left.
I had to download the image to see the relevant details.

Default colour set on gnuplot website

Ok, I know this question might sound silly, but I cannot find out why the demo from the gnuplot official website (you can see an example on the left hand side in the picture below) looks different (and much nicer) than what I get from running the same demo on my machine (on a wxt terminal).
Is there a configuration file (something like a ~/.gnuplotrc) where a theme has been specified? If so, does anyone know what theme has been used here?
Here you have an image where you can compare the website and the locally-made versions
Moreover, just an off topic curiosity, is anyone using gnuplot seriously, or it's basically used to plot simple batch plots and for Octave?
It is very likely that the person who made the demo (likely Ethan Merritt) has defined his/her own set of default line colors, which are reflected in the demo images. You can do this yourself (see help set linetype). Example from gnuplot e-mail list:
# Ethan A Merritt - my preference for gnuplot colors
# 2 3 4 5 6 8 are borrowed from the colors_podo set
#
set linetype 1 lc rgb "dark-violet" lw 1
set linetype 2 lc rgb "#009e73" lw 1
set linetype 3 lc rgb "#56b4e9" lw 1
set linetype 4 lc rgb "#e69f00" lw 1
set linetype 5 lc rgb "#f0e442" lw 1
set linetype 6 lc rgb "#0072b2" lw 1
set linetype 7 lc rgb "#e51e10" lw 1
set linetype 8 lc rgb "black" lw 1
set linetype 9 lc rgb "gray50" lw 1
set linetype cycle 9
There are no built-in gnuplot themes, only sets of settings which change colors.
And yes, I do use gnuplot seriously! I use it both for simple plotting and for scientific publication.
There are nice palettes available at https://github.com/Gnuplotting/gnuplot-palettes and https://github.com/aschn/gnuplot-colorbrewer
These define line styles that you can use explicitly, but with some shell escaping tricks you can make them override the default linetypes, with something like this in your .gnuplot:
palettefile(n) = sprintf("<sed 's/set style line/set linetype/' /path/to/gnuplot-gnuplot-palettes/%s.pal", n)
load palettefile("rdbu")
You can then call load palettefile(palettename) (where palettename is one of the ones available in the palette repository) whenever you want to change the default palette, so gets quite close to the theming notion mentioned above.
It looks like you are using an older version - the demos are probably made with version 5, which has a new default palette. Your colors look like version 4 or below.
The new version has a lot of new, more powerful features. The new cariolatex terminal can produce really nice publication quality plots out of the box, or with very few tweaks.
The most recent versions of gnuplot (5) have the left hand colour palette by default (at least the wxt terminal). They mention it helps readers with colour blindness.
I suggest you type in: help set colorsequence.
p.s. I also use gnuplot always for all my scientific publications.
Although the result is similar to that of andyras, here is another solution:
as the default colours depend on the terminal type, switch to the desired terminal type with set term and then type
show linetype

Resources