package main import ( "fmt" "tildegit.org/sloum/filtress/parser" ) 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 } 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 } } 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 } 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 (f *filterState) getColors() { imCol := im.RGBAAt(fil.location.x, fil.location.y) f.red.val = int(imCol.R) f.blue.val = int(imCol.B) f.green.val = int(imCol.B) f.alpha.val = int(imCol.A) }