-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load visual effects in ~/.config/panon/
- Loading branch information
Showing
23 changed files
with
306 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
""" | ||
panon client | ||
Usage: | ||
freetile [options] [<effect-arguments>...] | ||
freetile -h | --help | ||
Options: | ||
-h --help Show this screen. | ||
--random-effect | ||
--effect-name=N | ||
--debug Debug | ||
""" | ||
from docopt import docopt | ||
import sys | ||
import json | ||
import os.path | ||
|
||
from helper import config_effect_home, applet_effect_home, read_file, read_file_lines | ||
|
||
arguments = docopt(__doc__) | ||
effect_name = arguments['--effect-name'] | ||
effect_arguments = arguments['<effect-arguments>'] | ||
if arguments['--random-effect']: | ||
import random | ||
import get_effect_list | ||
effect_list = get_effect_list.get_list() | ||
effect_name = random.choice(effect_list) | ||
effect_arguments = [] | ||
|
||
if effect_name.endswith(' '): | ||
effect_name = effect_name[:-1] | ||
effect_home = config_effect_home | ||
else: | ||
effect_home = applet_effect_home | ||
|
||
|
||
def value2str(value): | ||
t=type(value) | ||
if t==int: | ||
return str(value) | ||
elif t==float: | ||
return str(value) | ||
elif t==bool: | ||
return 'true' if value else 'false' | ||
|
||
def build_source(files, main_file, meta_file=None, effect_arguments=None): | ||
if not os.path.exists(main_file): | ||
return '' | ||
arguments_map = {} | ||
if meta_file is not None: | ||
if os.path.exists(meta_file): | ||
meta = json.load(open(meta_file, 'rb')) | ||
meta_arg = meta['arguments'] | ||
arguments_map = {arg['name']: arg['default'] for arg in meta_arg} | ||
if len(effect_arguments) > 0: | ||
for i in range(len(meta_arg)): | ||
value=effect_arguments[i] | ||
if meta_arg[i]['type']=='double': | ||
value=float(value) | ||
elif meta_arg[i]['type']=='int': | ||
value=int(value) | ||
elif meta_arg[i]['type']=='bool': | ||
value=(value=='true') | ||
arguments_map[meta_arg[i]['name']] = value | ||
|
||
version = next(read_file_lines(main_file)) | ||
source = version | ||
for path in files: | ||
if path == main_file: | ||
for line in list(read_file_lines(path))[1:]: | ||
lst = line.split() | ||
if len(lst) >= 3: | ||
if lst[2].startswith('$'): | ||
lst[2] = value2str(arguments_map[lst[2][1:]]) | ||
line = ' '.join(lst) + '\n' | ||
source += line | ||
else: | ||
source += read_file(path) | ||
return source | ||
|
||
|
||
if effect_name.endswith('.frag'): | ||
obj = { | ||
'image_shader': | ||
build_source([ | ||
os.path.join(applet_effect_home, 'hsluv-glsl.fsh'), | ||
os.path.join(applet_effect_home, 'utils.fsh'), | ||
os.path.join(applet_effect_home, 'shadertoy-api-head.fsh'), | ||
os.path.join(effect_home, effect_name), | ||
os.path.join(applet_effect_home, 'shadertoy-api-foot.fsh'), | ||
], os.path.join(effect_home, effect_name)) | ||
} | ||
json.dump(obj, sys.stdout) | ||
elif effect_name.endswith('/'): | ||
obj = { | ||
'image_shader': | ||
build_source( | ||
[ | ||
os.path.join(applet_effect_home, 'hsluv-glsl.fsh'), | ||
os.path.join(applet_effect_home, 'utils.fsh'), | ||
os.path.join(applet_effect_home, 'shadertoy-api-head.fsh'), | ||
os.path.join(effect_home, effect_name, 'image.frag'), | ||
os.path.join(applet_effect_home, 'shadertoy-api-foot.fsh'), | ||
], | ||
os.path.join(effect_home, effect_name, 'image.frag'), | ||
os.path.join(effect_home, effect_name, 'meta.json'), | ||
effect_arguments, | ||
), | ||
'buffer_shader': | ||
build_source( | ||
[ | ||
os.path.join(applet_effect_home, 'shadertoy-api-head.fsh'), | ||
os.path.join(effect_home, effect_name, 'buffer.frag'), | ||
os.path.join(applet_effect_home, 'shadertoy-api-foot-buffer.fsh'), | ||
], | ||
os.path.join(effect_home, effect_name, 'buffer.frag'), | ||
os.path.join(effect_home, effect_name, 'meta.json'), | ||
effect_arguments, | ||
), | ||
} | ||
json.dump(obj, sys.stdout) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import glob | ||
import sys | ||
import os | ||
from helper import config_effect_home, applet_effect_home | ||
|
||
|
||
def _get_list(root): | ||
l = glob.glob(os.path.join(root, '*/')) + glob.glob(os.path.join(root, '*.frag')) | ||
return [n[len(root):] for n in l] | ||
|
||
|
||
def get_list(): | ||
l1 = _get_list(applet_effect_home) | ||
l2 = _get_list(config_effect_home) | ||
l2 = [n + ' ' for n in l2] | ||
l = l1 + l2 | ||
l.sort() | ||
return l | ||
|
||
|
||
if __name__ == '__main__': | ||
import json | ||
json.dump(get_list(), sys.stdout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import sys | ||
import os | ||
config_effect_home = os.path.expanduser('~/.config/panon/') | ||
applet_effect_home = os.path.join(os.path.split(sys.argv[0])[0], '../shaders/') | ||
|
||
|
||
def read_file(path): | ||
return open(path, 'rb').read().decode(errors='ignore') | ||
|
||
|
||
def read_file_lines(path): | ||
for line in open(path, 'rb'): | ||
yield line.decode(errors='ignore') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
panon client | ||
Usage: | ||
freetile [options] <effect> <file> | ||
freetile -h | --help | ||
Options: | ||
-h --help Show this screen. | ||
--debug Debug | ||
""" | ||
from helper import config_effect_home, applet_effect_home, read_file | ||
from docopt import docopt | ||
import os.path | ||
arguments = docopt(__doc__) | ||
effect_name = arguments['<effect>'] | ||
|
||
if effect_name.endswith(' '): | ||
effect_name = effect_name[:-1] | ||
effect_home = config_effect_home | ||
else: | ||
effect_home = applet_effect_home | ||
s = read_file(os.path.join(effect_home, effect_name, arguments['<file>'])) | ||
print(s) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"arguments": [{ | ||
"name": "bar_width", | ||
"default": 5, | ||
"type": "int" | ||
}, { | ||
"name": "gap_width", | ||
"default": 2, | ||
"type": "int" | ||
}, { | ||
"name": "decay", | ||
"default": 0.003, | ||
"type": "double" | ||
}] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"arguments": [{ | ||
"name": "unit_radius", | ||
"default": 15.0, | ||
"type": "double" | ||
}, { | ||
"name": "strength", | ||
"default": 0.125, | ||
"type": "double" | ||
}, { | ||
"name": "particle_opacity", | ||
"default": 0.4, | ||
"type": "double" | ||
}, { | ||
"name": "height_ratio", | ||
"default": 1.0, | ||
"type": "double" | ||
}, { | ||
"name": "density", | ||
"default": 256, | ||
"type": "int" | ||
}] | ||
} |
Oops, something went wrong.