Skip to content

Instantly share code, notes, and snippets.

Created February 23, 2017 22:23
Show Gist options
  • Save anonymous/1025fb8137ff32e6e0fb2540045e96e1 to your computer and use it in GitHub Desktop.
Save anonymous/1025fb8137ff32e6e0fb2540045e96e1 to your computer and use it in GitHub Desktop.
# Wires in Eve
## Logic and Detection
### Groups That Are Wires
```
search @canvas
[#group id strokes: s1]
s1 = [#stroke color: red]
[#group id strokes: s2]
s2 != s1
commit
wire = [#wire sensor: s1 conductor: s2]
```
### Wires Can Be Live
```
search @canvas @session
liveWire = [#stroke color: "yellow"]
wire = [#wire sensor conductor]
isLive = if
// conductor {x,y}1 and {x,y}2 are the same
(conductor.x1 - liveWire.x1) / (liveWire.x2 - liveWire.x1) =
(conductor.y1 - liveWire.y1) / (liveWire.y2 - liveWire.y1)
then true
else false
commit
wire <- [live: isLive]
```
## Setup
### Add Strokes and Groups
(should be done visuallly)
```
commit @canvas
group = [#group id: "foo"]
stroke1 = [#stroke x1: 0 x2: 10 y1: 0 y2: 0]
stroke2 = [#stroke x1: 0 x2: 0 y1: 0 y2: 0 color: "red"]
group <- [strokes: stroke1]
group <- [strokes: stroke2]
// liveWire
[#stroke x1: -5 x2: 5 y1: 0 y2: 0 color: "yellow"]
```
## Debugging
### Debug Strokes
```eve disabled
search @canvas
stroke = [#stroke x1 x2 y1 y2]
withColor = if stroke.color then " with color {{stroke.color}}"
else ""
commit @canvas @session
stroke.printf := "(({{x1}},{{y1}}) to ({{x2}},{{y2}}))"
bind @browser
[#div text: "Stroke from ({{x1}},{{y1}}) to ({{x2}},{{y2}}){{withColor}}."]
```
### Debug Groups
```eve disabled
search @canvas
[#group id strokes]
str = strokes.printf
strokeString = join[str given: str, with: ", "]
bind @browser
[#div text: "Group {{id}} with {{strokeString}}"]
```
### Debug Wires
```eve
search
wire = [#wire sensor conductor]
onOff = if wire.live then "on"
else "off"
bind @browser
[#div text: "Wire: Sensor {{sensor.printf}}, Conductor {{conductor.printf}} is {{onOff}}."]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment