Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm logo animation #1018

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 > > .