Skip to content

Commit

Permalink
swarm logo animation (#1018)
Browse files Browse the repository at this point in the history
./scripts/play.sh --scenario data/scenarios/Fun/logo-burst.yaml

![image](https://user-images.githubusercontent.com/261693/213022706-9ef7f8dc-03ef-4e84-8772-6ccd5645268f.png)
  • Loading branch information
kostmo authored Jan 17, 2023
1 parent ca98580 commit 22eb0c9
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/scenarios/Fun/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
GoL.yaml
logo-burst.yaml
12 changes: 12 additions & 0 deletions data/scenarios/Fun/_logo-burst/coordinator.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def forever : cmd unit -> cmd unit = \c. c ; forever c end

def alternate =
wait 50;
say "Green light";
make "bit (1)";
wait 100;
say "Red light";
make "bit (0)";
end;

forever alternate;
67 changes: 67 additions & 0 deletions data/scenarios/Fun/_logo-burst/drone.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

def repeat : int -> cmd unit -> cmd unit =
\n. \c. if (n == 0) {} {c ; repeat (n-1) c}
end
def abs = \n. if (n < 0) {-n} {n} end
def elif = \t. \then. \else. {if t then else} end
def else = \t. t end

def randdir : cmd dir =
d <- random 4;
return (
if (d == 0) {north}
$ elif (d == 1) {east}
$ elif (d == 2) {south}
$ else {west}
)
end;

def wander =
d <- randdir;
turn d;
dist <- random 4;
try {repeat dist move} {};
end;

def disperse =
r <- robotnamed "stoplight";
greenLight <- as r {has "bit (1)"};
if greenLight {
wander;
disperse;
} {};
end;

def converge = \loc. \currentLoc.

let xDist = fst currentLoc - fst loc in
let yDist = snd currentLoc - snd loc in

if (xDist < 0) {
turn east;
} {
if (xDist > 0) {
turn west;
} {};
};
repeat (abs xDist) move;

if (yDist < 0) {
turn north;
} {
if (yDist > 0) {
turn south;
} {};
};
repeat (abs yDist) move;
end;

def go = \loc.
disperse;
currentLoc <- whereami;
converge loc currentLoc;
go loc;
end;

loc <- whereami;
go loc;
84 changes: 84 additions & 0 deletions data/scenarios/Fun/logo-burst.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
version: 1
name: Logo burst
author: Karl Ostmo
description: |
Animate the Swarm logo
creative: false
seed: 0
robots:
# We include a base robot to stabilize the screen at a fixed position.
- name: base
display:
invisible: true
dir: [1, 0]
devices:
- logger
- hearing aid
- name: botRight
system: true
display:
invisible: false
dir: [1, 0]
program: |
run "scenarios/Fun/_logo-burst/drone.sw"
- name: botUp
system: true
display:
invisible: false
dir: [0, 1]
program: |
run "scenarios/Fun/_logo-burst/drone.sw"
- name: botLeft
system: true
display:
invisible: false
dir: [-1, 0]
program: |
run "scenarios/Fun/_logo-burst/drone.sw"
- name: botDown
system: true
display:
invisible: false
dir: [0, -1]
program: |
run "scenarios/Fun/_logo-burst/drone.sw"
- name: stoplight
system: true
display:
invisible: false
dir: [0, 1]
devices:
- lodestone
inventory:
- [1, bit (0)]
program: |
run "scenarios/Fun/_logo-burst/coordinator.sw"
known: [boulder, tree, water, wavy water]
world:
default: [blank]
upperleft: [0, 0]
offset: false
palette:
'Ω': [blank, null, base]
's': [blank, null, stoplight]
'.': [blank]
' ': [blank]
'@': [blank, boulder]
'T': [blank, tree]
'': [blank, water]
'~': [blank, wavy water]
'>': [blank, null, botRight]
'^': [blank, null, botUp]
'<': [blank, null, botLeft]
'v': [blank, null, botDown]
map: |
s v .
. .
. v<^vv<<@ ^^ vv >^v^T ^^^v< <>< v >
T ^< >^ < >> v> v< >T <v> <<▒^ @><> .
. <@v^^>> @v > <T <v<T<Ω^> v><v< << <<T^ v< .
. > >> v@ @@> << ~v < >~ ^~ >> @^ >v .
. >>^v^^^ < ~ T~v v< <~ >>T <v vv ▒> .
. ▒ .
. ^ ^ v > > .

0 comments on commit 22eb0c9

Please sign in to comment.