patches and links

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

patches and links

P.-M. Boulanger

Dear all,

Does a patch know if there in a link crossing it ? Can I ask a patch to ask the links crossing it to die ?

My problem is the following: I want the user being able to remove a link by a mouse-click on it but so far I haven't find the way to.

Thanks in advance for your suggestions

Regards


P.-M. Boulanger, [hidden email]
27/06/2013
Reply | Threaded
Open this post in threaded view
|

Re: patches and links

SethTisue
Administrator
>>>>> "P.-M." == P -M Boulanger <P.-M.> writes:

 P.-M.> Does a patch know if there in a link crossing it ? Can I ask a
 P.-M.> patch to ask the links crossing it to die ?

There's nothing built in that computes that.  You might look at
Intersecting Links Example, in the Code Examples section of the Models
Library, to get ideas for what the math required is like.

 P.-M.> My problem is the following: I want the user being able to
 P.-M.> remove a link by a mouse-click on it but so far I haven't find
 P.-M.> the way to.

If you can read Java, you might look at the math in
Protractor.distanceToLink(), here:

https://github.com/NetLogo/NetLogo/blob/5.0.x/src/main/org/nlogo/agent/Protractor.java

The distanceToLink() method is used to find nearby links when you
control- or right-click in the view, in order to offer the `inspect`
command on those links in the popup menu.  So it basically does exactly
what you want, but unfortunately there's nothing in the NetLogo language
that provides access to the routine.

If you can write Java, you could make an extension that provides access
to this routine.

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/
Reply | Threaded
Open this post in threaded view
|

Re: patches and links

James Steiner-2
In reply to this post by P.-M. Boulanger
in the past, I solved this by decorating the link with a turtle whose
position was maintained at the center of the link.

that turtle is the click target.

I've also done other things, like, dragging one end and tugging quickly
breaks the link, or allowing multiple node selection, and clinking a
link-selected-turtles button.

see the decorated turtles example on turtlezero.com
On Jun 27, 2013 1:56 PM, "P.-M. Boulanger" <[hidden email]> wrote:

>
>
>
> Dear all,
>
> Does a patch know if there in a link crossing it ? Can I ask a patch to
> ask the links crossing it to die ?
>
> My problem is the following: I want the user being able to remove a link
> by a mouse-click on it but so far I haven't find the way to.
>
> Thanks in advance for your suggestions
>
> Regards
>
>
>  P.-M. Boulanger, [hidden email]
> 27/06/2013
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: patches and links

Jim Lyons
In reply to this post by P.-M. Boulanger

On Jun 27, 2013, at 5:28 AM, P.-M. Boulanger <[hidden email]> wrote:

> Does a patch know if there in a link crossing it ? Can I ask a patch to ask the links crossing it to die ?
>  
> My problem is the following: I want the user being able to remove a link by a mouse-click on it but so far I haven't find the way to.

Here is a test program for a routine I wrote a while back. Maybe it will help.  -Jim

; Settings
;   View updates on ticks; wrapping OFF.

to setup  ; by observer
  clear-all
  set-default-shape turtles "dot"
  ask n-of 2 patches [ sprout 1 ]
  ask turtle 0 [ create-link-with turtle 1 ]
end

to go  ; by observer, forever
  ask links [ set color ifelse-value mouse-on? [yellow][gray] ]
  display
end

to-report mouse-on?  ;-- by link -- true if mouse on me
  report sum [distancexy mouse-xcor mouse-ycor] of both-ends
         - link-length < .1 / patch-size  ; about 2-3 pixels
end
Reply | Threaded
Open this post in threaded view
|

Re: patches and links

SethTisue
Administrator
>>>>> "Jim" == Jim Lyons <[hidden email]> writes:

 Jim> to-report mouse-on?  ;-- by link -- true if mouse on me
 Jim>   report sum [distancexy mouse-xcor mouse-ycor] of both-ends
 Jim>          - link-length < .1 / patch-size  ; about 2-3 pixels
 Jim> end

Very nice!  Better than my answer.

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/
Reply | Threaded
Open this post in threaded view
|

Re: patches and links

Stephen Guerin
On Fri, Jun 28, 2013 at 6:38 AM, Seth Tisue <[hidden email]> wrote:

> **
>
>
> >>>>> "Jim" == Jim Lyons <[hidden email]> writes:
>
> Jim> to-report mouse-on? ;-- by link -- true if mouse on me
> Jim> report sum [distancexy mouse-xcor mouse-ycor] of both-ends
> Jim> - link-length < .1 / patch-size ; about 2-3 pixels
> Jim> end
>
> Very nice! Better than my answer!
>

Yes, very elegant, Jim!
Reply | Threaded
Open this post in threaded view
|

Re: Re: [netlogo-users] patches and links

P.-M. Boulanger
In reply to this post by SethTisue
Many thanks to you, Seth, Jim and James.

The code below is all what I was looking for  but I have  found in Turtlezero's examples  a lot of ideas and suggestions that will  help me for others pieces of my current project.
 

P.-M. Boulanger, [hidden email]
29/06/2013
----- Message reçu -----
De : Seth Tisue
À : netlogo-users
Date : 2013-06-28, 14:38:36
Sujet : Re: [netlogo-users] patches and links


 
>>>>> "Jim" == Jim Lyons <[hidden email]> writes:

Jim> to-report mouse-on? ;-- by link -- true if mouse on me
Jim> report sum [distancexy mouse-xcor mouse-ycor] of both-ends
Jim> - link-length < .1 / patch-size ; about 2-3 pixels
Jim> end

Very nice! Better than my answer.

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/


Reply | Threaded
Open this post in threaded view
|

Re: patches and links

backspaces
Administrator
In reply to this post by Stephen Guerin
I'm loving the short and to the point "sketches" like this one.

We're reorganizing our github repo for AgentScript, so I think I'll start a
sketches folder, and definitely include this one.

The great thing about the sketches is that they always point out something
difficult or incomplete in AS.

   -- Owen


On Fri, Jun 28, 2013 at 10:54 PM, Stephen Guerin <[hidden email]
> wrote:

>
> On Fri, Jun 28, 2013 at 6:38 AM, Seth Tisue <[hidden email]> wrote:
>
>> **
>>
>>
>> >>>>> "Jim" == Jim Lyons <[hidden email]> writes:
>>
>> Jim> to-report mouse-on? ;-- by link -- true if mouse on me
>> Jim> report sum [distancexy mouse-xcor mouse-ycor] of both-ends
>> Jim> - link-length < .1 / patch-size ; about 2-3 pixels
>> Jim> end
>>
>> Very nice! Better than my answer!
>>
>
> Yes, very elegant, Jim!
>