Skip to content

Commit

Permalink
Allow specifying where the connection between objects starts/ends
Browse files Browse the repository at this point in the history
  • Loading branch information
nmichaud committed Jun 9, 2024
1 parent f342607 commit d4c238d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions virtual-programs/connections.folk
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
# for wishes of the form:
# "Wish $tag is connected to $tag2" or "Wish $tag is dynamically connected to $tag2"

When /anyone/ wishes /source/ is connected to /sink/ & \
When /anyone/ wishes /source/ is connected to /sink/ {
Wish $source is connected to $sink from centroid to centroid
}

When /anyone/ wishes /source/ is dynamically connected to /sink/ {
Wish $source is dynamically connected to $sink from centroid to centroid
}

When /anyone/ wishes /source/ is connected to /sink/ from /p1/ to /p2/ & \
/source/ has region /source_region/ & \
/sink/ has region /sink_region/ {

if {$source == $sink} {return}

set source [region centroid $source_region]
set sink [region centroid $sink_region]
set source [region $p1 $source_region]
set sink [region $p2 $sink_region]

set direction [vec2 sub $sink $source]

Expand All @@ -25,14 +33,14 @@ set speed 75
set spacing 50
set maxsize 25

When /anyone/ wishes /source/ is dynamically connected to /sink/ & \
When /anyone/ wishes /source/ is dynamically connected to /sink/ from /p1/ to /p2/ & \
/source/ has region /source_region/ & \
/sink/ has region /sink_region/ {

if {$source == $sink} {return}

set source [region centroid $source_region]
set sink [region centroid $sink_region]
set source [region $p1 $source_region]
set sink [region $p2 $sink_region]

set direction [vec2 normalize [vec2 sub $sink $source]]
set distance [vec2 distance $sink $source]
Expand Down

0 comments on commit d4c238d

Please sign in to comment.