filtress/receivers.go

119 lines
2.0 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"tildegit.org/sloum/filtress/parser"
)
2019-07-18 23:49:04 +00:00
func (f *filter) update(change parser.Expression) {
var err error
opand := change.Opperand
if change.Variable != "" {
opand, err = retrieveVariableValue(change.Variable)
if err != nil {
panic(fmt.Sprintf("Runtime error: Unknown variable %q encountered", change.Variable))
}
}
switch change.Opperator {
case '+':
f.val += opand
case '-':
f.val -= opand
case '*':
f.val *= opand
case '/':
if opand == 0 {
f.val = 1
} else {
f.val /= opand
}
2019-07-18 23:49:04 +00:00
case '%':
if opand == 0 {
f.val = 1
} else {
f.val %= opand
}
case '=':
f.val = opand
}
if f.val > f.max {
f.val %= f.max
}
if f.val < f.min {
f.val = f.max - f.val%f.max
}
}
2019-07-18 23:49:04 +00:00
func (p *point) update(change []parser.Expression) {
var err error
var totalX, totalY, val, opand, max int
var target *int
for i, e := range change {
if i == 0 {
target = &totalX
val = p.x
max = p.maxX
} else if i == 1 {
target = &totalY
val = p.y
max = p.maxY
} else {
break
}
opand = e.Opperand
if e.Variable != "" {
opand, err = retrieveVariableValue(e.Variable)
if err != nil {
panic(fmt.Sprintf("Runtime error: Unknown variable %q encountered", e.Variable))
}
}
switch e.Opperator {
case '+':
*target = val + opand
case '-':
*target = val - opand
case '*':
*target = val * opand
case '/':
if opand == 0 {
*target = 1
} else {
*target = val / opand
}
2019-07-18 23:49:04 +00:00
case '%':
if opand == 0 {
*target = 1
} else {
*target = val % opand
}
case '=':
*target = opand
}
if *target > max {
*target %= max
}
if *target < 0 {
*target = max - (*target * -1 % max)
}
}
p.x = totalX
p.y = totalY
}
func (c *col) update() {
imCol := im.RGBAAt(fil.location.x, fil.location.y)
fil.sample.red.val = int(imCol.R)
fil.sample.blue.val = int(imCol.B)
fil.sample.green.val = int(imCol.B)
fil.sample.alpha.val = int(imCol.A)
}