add rand
This commit is contained in:
parent
440f545d7d
commit
e375726ae8
1 changed files with 26 additions and 5 deletions
31
pattern.py
31
pattern.py
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import json
|
||||
import random
|
||||
|
||||
this = sys.modules[__name__]
|
||||
|
||||
|
@ -9,7 +10,9 @@ this.values = {
|
|||
"stack": 0,
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0
|
||||
"b": 0,
|
||||
"tick": 0,
|
||||
"index": 0
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,17 +38,33 @@ def sub(target, arg):
|
|||
return res
|
||||
|
||||
|
||||
def rand(target, arg):
|
||||
return random.randrange(0, 255)
|
||||
|
||||
|
||||
def _apply(target, arg, func):
|
||||
if type(arg is int):
|
||||
return func(target, arg)
|
||||
elif type(arg is str) and arg in this.values:
|
||||
return func(target, this.values[arg])
|
||||
|
||||
|
||||
def apply(targets, args, func):
|
||||
for target in range(len(targets)):
|
||||
if this.values[targets[target]['channel']] != None:
|
||||
this.values[targets[target]['channel']] = func(
|
||||
this.values[targets[target]['channel']], args[target])
|
||||
if target in args:
|
||||
this.values[targets[target]['channel']] = _apply(
|
||||
this.values[targets[target]['channel']], args[target], func)
|
||||
else:
|
||||
this.values[targets[target]['channel']] = _apply(
|
||||
this.values[targets[target]['channel']], 0, func)
|
||||
|
||||
|
||||
this.instructions = {
|
||||
"CONSTANT": constant,
|
||||
"ADD": add,
|
||||
"SUB": sub
|
||||
"SUB": sub,
|
||||
"RAND": rand
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,7 +77,9 @@ def pat(index, tick, previous_values):
|
|||
for i in range(len(this.pattern)):
|
||||
name = this.pattern[i]['instruction']['name']
|
||||
targets = this.pattern[i]['instruction']['targets']
|
||||
args = this.pattern[i]['instruction']['args']
|
||||
args = []
|
||||
if 'args' in this.pattern[i]['instruction']:
|
||||
args = this.pattern[i]['instruction']['args']
|
||||
if this.instructions[name] != None:
|
||||
apply(targets, args, this.instructions[name])
|
||||
r = this.values["r"]
|
||||
|
|
Loading…
Reference in a new issue