summaryrefslogtreecommitdiff
path: root/ricky/pbgrid
diff options
context:
space:
mode:
Diffstat (limited to 'ricky/pbgrid')
-rw-r--r--ricky/pbgrid/__init__.py14
-rwxr-xr-xricky/pbgrid/options.py63
-rw-r--r--ricky/pbgrid/params.py130
-rw-r--r--ricky/pbgrid/probabilities.json87
-rwxr-xr-xricky/pbgrid/probabilities.py64
5 files changed, 358 insertions, 0 deletions
diff --git a/ricky/pbgrid/__init__.py b/ricky/pbgrid/__init__.py
new file mode 100644
index 0000000..4189231
--- /dev/null
+++ b/ricky/pbgrid/__init__.py
@@ -0,0 +1,14 @@
+from ricky.pb import Pb
+from ricky.pbgrid.params import Params
+from ricky.config import IMGRID_URL
+
+
+class PbGrid(Pb):
+ def __init__(self):
+ self.url = IMGRID_URL
+
+ def params_init(self):
+ new_params = Params()
+ # new_params = self.get_from_server()
+ new_params.api = self
+ return new_params
diff --git a/ricky/pbgrid/options.py b/ricky/pbgrid/options.py
new file mode 100755
index 0000000..38ba1ee
--- /dev/null
+++ b/ricky/pbgrid/options.py
@@ -0,0 +1,63 @@
+format_probabilities = Probabilities.from_dict(
+ { 'weight': 20, 'value': 'png' },
+ { 'weight': 0, 'value': 'gif' },
+ { 'weight': 0, 'value': 'jpg' },
+)
+transition_probabilities = Probabilities.from_dict(
+ { "value" : "background", "weight": 1 },
+ { "value" : "dither", "weight": 1 },
+ { "value" : "random", "weight": 1 },
+ { "value" : "tile", "weight": 1 },
+ { "value" : "edge", "weight": 1 },
+)
+skycolor_colors = \
+ bgcolor_colors = planebgcolor_colors = Probabilities.from_dict(
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : None, "weight" : 10 },
+)
+
+linecolor_colors = Probabilities.from_dict(
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+)
+swing_probabilities = tilt_probabilities = roll_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1},
+)
+width_probabilities = height_probabilities = Probabilities.from_dict(
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
+)
+linethickness_probabilities = Probabilities.from_dict(
+ {"value":1, "weight": 2},
+ {"value":2, "weight": 1},
+)
+opacity_probabilities = Probabilities.from_dict(
+ {"value":1, "weight": 2},
+ {"value":0.5, "weight": 1},
+)
+spacing_probabilities = Probabilities.from_dict(
+ {"value":10, "weight": 1},
+ {"value":15, "weight": 1},
+)
+vlines_probabilities = hlines_probabilities = Probabilities.from_dict(
+ {"value":"", "weight": 2},
+ {"value":"true", "weight": 1},
+)
+shadow_probabilities = Probabilities.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+zoom_probabilities = Probabilities.from_dict(
+ {"value": 0, "weight": 3},
+ {"value": 1.2, "weight": 1},
+ {"value": -1.2, "weight": 1},
+)
+trim_probabilities = Probabilities.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+
diff --git a/ricky/pbgrid/params.py b/ricky/pbgrid/params.py
new file mode 100644
index 0000000..850e180
--- /dev/null
+++ b/ricky/pbgrid/params.py
@@ -0,0 +1,130 @@
+from ricky.params import Params as _Params
+from ricky.param.username import Username
+from ricky.param.imageurl import PbageUrl
+from ricky.param.enum import Enum
+from ricky.param.constrainednumber import ConstrainedNumber
+from ricky.param.color import Color
+from ricky.param.bool import Bool
+
+_TRANSITION_OPTIONS = [
+ "background",
+ "dither",
+ "random",
+ "tile",
+ "edge"
+]
+
+_FILETYPE_OPTIONS = [
+ "png",
+ "jpg",
+ "gif",
+]
+
+
+class Params(_Params):
+ def __init__(self):
+ self._params = (
+ Username(name="username", required=False),
+ PbageUrl(name="bgimage", required=False),
+ PbageUrl(name="imageinstead", required=False),
+ PbageUrl(name="planebgimage", required=False),
+ Enum(
+ name="format",
+ required=False,
+ options=_FILETYPE_OPTIONS
+ ),
+ Enum(
+ name="transition",
+ required=True,
+ options=_TRANSITION_OPTIONS
+ ),
+ Color(name="skycolor", required=False),
+ Color(name="planebgcolor", required=False),
+ Color(name="bgcolor", required=False),
+ Color(name="linecolor", required=False),
+ ConstrainedNumber(
+ name="swing",
+ required=False,
+ enforce_int=True,
+ min=-170,
+ max=170),
+ ConstrainedNumber(
+ name="tilt",
+ required=False,
+ enforce_int=True,
+ min=-170,
+ max=170),
+ ConstrainedNumber(
+ name="roll",
+ required=False,
+ enforce_int=True,
+ min=-170,
+ max=170),
+ ConstrainedNumber(
+ name="width",
+ required=False,
+ enforce_int=True,
+ min=100,
+ max=800),
+ ConstrainedNumber(
+ name="height",
+ required=False,
+ enforce_int=True,
+ min=100,
+ max=800),
+ ConstrainedNumber(
+ name="linethickness",
+ required=False,
+ enforce_int=True,
+ min=1,
+ max=30
+ ),
+ ConstrainedNumber(
+ name="opacity", required=False, min=0, max=1, prec=2),
+ ConstrainedNumber(
+ name="spacing",
+ enforce_int=True,
+ required=False,
+ min=2,
+ max=100),
+ Bool(name="vlines", required=False),
+ Bool(name="hlines", required=False),
+ Bool(name="trim", required=False),
+ Bool(name="shadow", required=False),
+ ConstrainedNumber(
+ name="zoom",
+ required=False,
+ min=-12,
+ max=12,
+ forbidden_range_min=-1.1,
+ forbidden_range_max=1.1,
+ prec=1
+ )
+ )
+
+ def _test_values(self):
+ return not any([
+ (self.__getitem__('spacing').value >
+ self.__getitem__('width').value),
+ (self.__getitem__('spacing').value >
+ self.__getitem__('height').value),
+ (self.__getitem__('linethickness').value >
+ self.__getitem__('width').value),
+ (self.__getitem__('linethickness').value >
+ self.__getitem__('height').value),
+ ])
+
+ def randomize(self):
+ p = self._params
+ for el in p:
+ if el in ['spacing', 'linethickness']:
+ continue
+ el.randomize()
+ for name in ['spacing', 'linethickness']:
+ max_tries = 10000
+ while(max_tries):
+ self.__getitem__(name).randomize()
+ if self._test_values():
+ return
+ max_tries -= 1
+ raise ValueError
diff --git a/ricky/pbgrid/probabilities.json b/ricky/pbgrid/probabilities.json
new file mode 100644
index 0000000..f9defe8
--- /dev/null
+++ b/ricky/pbgrid/probabilities.json
@@ -0,0 +1,87 @@
+{
+ "format" : [
+ { "weight": 20, "value": "png" },
+ { "weight": 0, "value": "gif" },
+ { "weight": 0, "value": "jpg" }
+ ],
+ "transition" : [
+ { "value" : "background", "weight": 1 },
+ { "value" : "dither", "weight": 1 },
+ { "value" : "random", "weight": 1 },
+ { "value" : "tile", "weight": 1 },
+ { "value" : "edge", "weight": 1 }
+ ],
+ "skycolor" : [
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : null, "weight" : 10 }
+ ],
+ "bgcolor" : [
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : null, "weight" : 10 }
+ ],
+ "planebgcolor" : [
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : null, "weight" : 10 }
+ ],
+
+ "linecolor" : [
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 }
+ ],
+ "swing" : [
+ {"value": ", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1}
+ ],
+ "tilt" : [
+ {"value": ", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1}
+ ],
+ "roll" : [
+ {"value": ", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1}
+ ],
+ "width" : "height" : [
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 }
+ ],
+ "linethickness" : [
+ {"value":1, "weight": 2},
+ {"value":2, "weight": 1}
+ ],
+ "opacity" : [
+ {"value":1, "weight": 2},
+ {"value":0.5, "weight": 1}
+ ],
+ "spacing" : [
+ {"value":10, "weight": 1},
+ {"value":15, "weight": 1}
+ ],
+ "vlines" : [
+ {"value":", "weight": 2},
+ {"value":"true", "weight": 1}
+ ],
+ "hlines" : [
+ {"value":", "weight": 2},
+ {"value":"true", "weight": 1}
+ ],
+ "shadow" : [
+ {"value":", "weight": 1},
+ {"value":"true", "weight": 1}
+ ],
+ "zoom" : [
+ {"value": 0, "weight": 3},
+ {"value": 1.2, "weight": 1},
+ {"value": -1.2, "weight": 1}
+ ],
+ "trim" : [
+ {"value":", "weight": 1},
+ {"value":"true", "weight": 1}
+ ]
+}
diff --git a/ricky/pbgrid/probabilities.py b/ricky/pbgrid/probabilities.py
new file mode 100755
index 0000000..cdda026
--- /dev/null
+++ b/ricky/pbgrid/probabilities.py
@@ -0,0 +1,64 @@
+from ricky.param.probabilities import Probabilities
+format_probabilities = Probabilities.from_dict(
+ { 'weight': 20, 'value': 'png' },
+ { 'weight': 0, 'value': 'gif' },
+ { 'weight': 0, 'value': 'jpg' },
+)
+transition_probabilities = Probabilities.from_dict(
+ { "value" : "background", "weight": 1 },
+ { "value" : "dither", "weight": 1 },
+ { "value" : "random", "weight": 1 },
+ { "value" : "tile", "weight": 1 },
+ { "value" : "edge", "weight": 1 },
+)
+skycolor_colors = \
+ bgcolor_colors = planebgcolor_colors = Probabilities.from_dict(
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : None, "weight" : 10 },
+)
+
+linecolor_colors = Probabilities.from_dict(
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+)
+swing_probabilities = tilt_probabilities = roll_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1},
+)
+width_probabilities = height_probabilities = Probabilities.from_dict(
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
+)
+linethickness_probabilities = Probabilities.from_dict(
+ {"value":1, "weight": 2},
+ {"value":2, "weight": 1},
+)
+opacity_probabilities = Probabilities.from_dict(
+ {"value":1, "weight": 2},
+ {"value":0.5, "weight": 1},
+)
+spacing_probabilities = Probabilities.from_dict(
+ {"value":10, "weight": 1},
+ {"value":15, "weight": 1},
+)
+vlines_probabilities = hlines_probabilities = Probabilities.from_dict(
+ {"value":"", "weight": 2},
+ {"value":"true", "weight": 1},
+)
+shadow_probabilities = Probabilities.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+zoom_probabilities = Probabilities.from_dict(
+ {"value": 0, "weight": 3},
+ {"value": 1.2, "weight": 1},
+ {"value": -1.2, "weight": 1},
+)
+trim_probabilities = Probabilities.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+