Skip to content

Instantly share code, notes, and snippets.

@mroeder
Forked from anonymous/examples-untitled.eve
Last active March 14, 2017 18:44
Show Gist options
  • Save mroeder/4ae9096ca8bd7390063bfe9772f1b353 to your computer and use it in GitHub Desktop.
Save mroeder/4ae9096ca8bd7390063bfe9772f1b353 to your computer and use it in GitHub Desktop.
Eve - Wires
# Wires in Eve
## Logic and Detection
### Groups That Are Wires
```
search @canvas
[#group id strokes]
count[given: strokes, per: id] = 2
[#group id strokes: sensor]
sensor = [#stroke color: "red"]
[#group id strokes: conductor]
conductor != sensor
bind
wire = [#wire sensor: sensor conductor: conductor]
```
### Wires Can Be Live
```
search @canvas @session
liveWire = [#stroke color: "orange"]
wire = [#wire sensor conductor]
// simple check instead of real "intersects"
// sensor {x,y}1 and {x,y}2 are the same
sensor.y1 = liveWire.y1
bind
wire <- [live: true]
```
```
search @canvas @session
wire = [#wire conductor live]
live = true
bind @canvas @session
conductor <- [color: "orange"]
```
## Setup
### Add Strokes and Groups
(should be done visuallly)
```eve
// strokes for wire
commit @canvas
group = [#group id: "foo"]
stroke1 = [#stroke x1: 20 y1: 60 x2: 20 y2: 20]
stroke2 = [#stroke x1: 20 y1: 20 x2: 20 y2: 20 color: "red"]
group <- [strokes: stroke1]
group <- [strokes: stroke2]
```
```eve disabled
// live wire
commit @canvas
[#stroke x1: 15 y1: 20 x2: 30 y2: 20 color: "orange"]
```
## Visualization
```eve
search @canvas
stroke = [#stroke x1 x2 y1 y2]
color = if stroke.color then stroke.color
else "black"
type = if x1 = x2, y1 = y2 then "circle"
else "line"
cx = x1
cy = y1
bind @browser
[#svg viewBox: "-10 -10 110 110", fill: "#FFFFFF", width: "300px", children:
[#rect x: 0, y: 0, width: 100, height: 100, fill: "#FFFFFF"]
[tag: type x1 x2 y1 y2 cx cy r: 1 stroke: color fill: color]
]
```
## Debugging
### Debug Strokes
```eve
search @canvas
stroke = [#stroke x1 x2 y1 y2]
commit @canvas @session
stroke.printf := "(({{x1}},{{y1}}) to ({{x2}},{{y2}}))"
```
```eve disabled
search @canvas
stroke = [#stroke x1 x2 y1 y2]
withColor = if stroke.color then " with color {{stroke.color}}"
else ""
bind @browser
[#div text: "Stroke from {{stroke.printf}}{{withColor}}."]
```
### Debug Groups
```eve disabled
search @canvas
[#group id strokes]
strokeString = join[token: strokes.printf, given: strokes, with: ", "]
bind @browser
[#div text: "Group {{id}} with {{strokeString}}"]
```
### Debug Wires
```eve disabled
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