summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ricky/param/probabilities.py21
-rw-r--r--ricky/param/probability.py9
-rw-r--r--ricky/pb.py39
-rw-r--r--ricky/pbbreaker/__init__.py13
-rw-r--r--ricky/pbbreaker/params.py58
-rw-r--r--ricky/pbbreaker/probability.json35
-rw-r--r--ricky/pbgradient/__init__.py15
-rw-r--r--ricky/pbgradient/params.py166
-rw-r--r--ricky/pbgradient/probabilities.json120
-rw-r--r--ricky/pbgradient/probabilities.py102
-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
-rwxr-xr-xricky/pbpattern/__init__.py14
-rw-r--r--ricky/pbpattern/params.py24
17 files changed, 974 insertions, 0 deletions
diff --git a/ricky/param/probabilities.py b/ricky/param/probabilities.py
new file mode 100644
index 0000000..d109b18
--- /dev/null
+++ b/ricky/param/probabilities.py
@@ -0,0 +1,21 @@
+from ricky.param.probability import Probability
+import sys
+class Probabilities:
+ def __init__(self, *args):
+ self._values = args
+ def __iter__(self):
+ return iter(self._values)
+ def __len__(self):
+ return len(self._values)
+ def __str__(self):
+ return str(self._values)
+ def __getitem__(self, i):
+ return self._values[i]
+ def search(self, s):
+ for i in self:
+ if str(s) in i.value:
+ return i
+ @classmethod
+ def from_dict(cls, *args):
+ probabilities = map(lambda x: Probability(**x), args);
+ return cls(*probabilities);
diff --git a/ricky/param/probability.py b/ricky/param/probability.py
new file mode 100644
index 0000000..0d27b70
--- /dev/null
+++ b/ricky/param/probability.py
@@ -0,0 +1,9 @@
+class Probability(dict):
+ def __init__(self, **kwargs):
+ super(Probability, self).__init__(**kwargs)
+ self.value = kwargs["value"]
+ self.weight = kwargs["weight"]
+ def __getattr__(self, attr):
+ return self.get(attr)
+ __setattr__= dict.__setitem__
+ __delattr__= dict.__delitem__
diff --git a/ricky/pb.py b/ricky/pb.py
new file mode 100644
index 0000000..6e70ea6
--- /dev/null
+++ b/ricky/pb.py
@@ -0,0 +1,39 @@
+import urllib
+import urllib2
+import sys
+import simplejson as json
+from ricky.config import OFFLINE
+
+
+class Pb(object):
+ def __init__(self):
+ self._required_keys = []
+ self.url = ""
+ self._offline = OFFLINE
+
+ def post_request(self, url, params):
+ params = urllib.urlencode(params)
+ headers = {
+ "Content-type": "application/x-www-form-urlencoded",
+ "User-Agent": (
+ "Mozilla/5.0 (X11; Linux x86_64) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Chrome/40.0.2214.94 Safari/537.36"
+ ),
+ "Accept": "text/plain"
+ }
+ try:
+ req = urllib2.Request(url, params, headers)
+ response = urllib2.urlopen(req)
+ return response.read()
+ except urllib.error.HTTPError:
+ sys.stderr.write("Post Request failed!")
+
+ def call(self, params):
+ if self._offline:
+ sys.path.append("./photoblaster")
+ from photoblaster.modules import Pb
+ pass
+ return json.loads(
+ self.post_request(self.url, params.as_dict())
+ )
diff --git a/ricky/pbbreaker/__init__.py b/ricky/pbbreaker/__init__.py
new file mode 100644
index 0000000..3a25a2b
--- /dev/null
+++ b/ricky/pbbreaker/__init__.py
@@ -0,0 +1,13 @@
+from ricky.pb import Pb
+from ricky.pbbreaker.params import Params
+from ricky.config import IMBREAK_URL
+
+
+class PbBreaker(Pb):
+ def __init__(self):
+ self.url = IMBREAK_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/pbbreaker/params.py b/ricky/pbbreaker/params.py
new file mode 100644
index 0000000..57c93f3
--- /dev/null
+++ b/ricky/pbbreaker/params.py
@@ -0,0 +1,58 @@
+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.bool import Bool
+
+
+_BREAKTYPE_OPTIONS = [
+ "CLASSIC",
+ "REDUX",
+ "BLURRY_BREAK",
+ "BLURRY_BREAK_2",
+ "SWIPE",
+ "RGB_WASH",
+ "RGB_WASH_2",
+ "NOISY_BREAK",
+ "BROKEN_VIGNETTE",
+ "FAX_MACHINE",
+ "STRIPES",
+ "PHOTOCOPY"
+]
+_BREAKMODE_OPTIONS = [
+ "extreme",
+ "subtle",
+]
+_FINALFORMAT_OPTIONS = [
+ "png",
+ "jpg",
+ "gif",
+]
+
+
+class Params(_Params):
+ def __init__(self):
+ self._params = (
+ Username(name="username", required=False),
+ PbageUrl(name="url", required=True),
+ Enum(
+ name="finalformat",
+ required=False,
+ options=_FINALFORMAT_OPTIONS),
+ Enum(
+ name="breaktype",
+ required=True,
+ options=_BREAKTYPE_OPTIONS),
+ ConstrainedNumber(
+ name="breakangle",
+ required=False,
+ enforce_int=True,
+ min=-180,
+ max=180),
+ Enum(
+ name="breakmode",
+ required=True,
+ options=_BREAKMODE_OPTIONS),
+ Bool(name="expanded", required=False)
+ )
diff --git a/ricky/pbbreaker/probability.json b/ricky/pbbreaker/probability.json
new file mode 100644
index 0000000..9c28e6d
--- /dev/null
+++ b/ricky/pbbreaker/probability.json
@@ -0,0 +1,35 @@
+{
+ "breaktype" :[
+ {"value": "CLASSIC", "weight": 1},
+ {"value": "REDUX", "weight": 1},
+ {"value": "BLURRY_BREAK", "weight": 1},
+ {"value": "BLURRY_BREAK_2", "weight": 1},
+ {"value": "SWIPE", "weight": 1},
+ {"value": "RGB_WASH", "weight": 1},
+ {"value": "RGB_WASH_2", "weight": 1},
+ {"value": "NOISY_BREAK", "weight": 1},
+ {"value": "BROKEN_VIGNETTE", "weight": 1},
+ {"value": "FAX_MACHINE", "weight": 1},
+ {"value": "STRIPES", "weight": 1},
+ {"value": "PHOTOCOPY", "weight": 1}
+ ],
+ "breakmode" :[
+ {"value": "extreme", "weight": 1},
+ {"value": "subtle", "weight": 1}
+ ],
+ "finalformat" :[
+ {"value": "png", "weight": 5},
+ {"value": "jpg", "weight": 2},
+ {"value": "gif", "weight": 2}
+ ],
+ "breakangle" :[
+ {"value": 0, "weight": 9},
+ {"value": 90, "weight": 2},
+ {"value": -180, "weight": 2},
+ {"value": 180, "weight": 2}
+ ],
+ "expanded" :[
+ {"value": "", "weight": 11},
+ {"value": 1, "weight": 2}
+ ]
+}
diff --git a/ricky/pbgradient/__init__.py b/ricky/pbgradient/__init__.py
new file mode 100644
index 0000000..96b15a5
--- /dev/null
+++ b/ricky/pbgradient/__init__.py
@@ -0,0 +1,15 @@
+"""class for the imgradient api handler"""
+from ricky.pb import Pb
+from ricky.pbgradient.params import Params
+from ricky.config import IMGRADIENT_URL
+
+
+class PbGradient(Pb):
+ def __init__(self):
+ super(PbGradient, self).__init__()
+ self.url = IMGRADIENT_URL
+
+ def params_init(self):
+ new_params = Params()
+ new_params.api = self
+ return new_params
diff --git a/ricky/pbgradient/params.py b/ricky/pbgradient/params.py
new file mode 100644
index 0000000..48e25f5
--- /dev/null
+++ b/ricky/pbgradient/params.py
@@ -0,0 +1,166 @@
+from ricky.params import Params as _Params
+from ricky.param.username import Username
+from ricky.param.enum import Enum
+from ricky.param.constrainednumber import ConstrainedNumber
+from ricky.param.bool import Bool
+from ricky.param.color import Color
+
+
+_HALFTONE_OPTIONS = [
+ "",
+ "checkeredfade",
+ "etchedtransition",
+ "bendaydots",
+ "smallerdots1",
+ "smallerdots2",
+ "flatstripes",
+]
+
+_BEVEL_OPTIONS = [
+ "",
+ "flatout",
+ "flatinner",
+ "evenlyframed",
+ "biginner",
+ "bigouter",
+ "dramaticflatout",
+ "dramaticflatinner",
+]
+
+_FILETYPE_OPTIONS = [
+ "png",
+ "jpg",
+ "gif",
+]
+
+_GRADIENTTYPE_OPTIONS = [
+ "canvas",
+ "gradient",
+ "radial",
+ "colorspace",
+ "plasmawash",
+ "gradientwash",
+ "mirrored",
+ "noise",
+]
+
+
+class Params(_Params):
+ def __init__(self):
+ super(Params, self).__init__(
+ Username(name="username", required=False),
+ ConstrainedNumber(
+ name="width",
+ required=True,
+ enforce_int=True,
+ min=10,
+ max=800
+ ),
+ ConstrainedNumber(
+ name="height",
+ required=True,
+ enforce_int=True,
+ min=10,
+ max=800
+ ),
+ Color(name="color1", required=True),
+ Color(name="color2", required=True),
+ Enum(
+ name="filetype",
+ required=False,
+ options=_FILETYPE_OPTIONS
+ ),
+ Enum(
+ name="gradienttype",
+ required=True,
+ options=_GRADIENTTYPE_OPTIONS
+ ),
+ Enum(
+ name="halftone",
+ required=False,
+ options=_HALFTONE_OPTIONS
+ ),
+ Enum(
+ name="bevel",
+ required=False,
+ options=_BEVEL_OPTIONS
+ ),
+ ConstrainedNumber(
+ name="stripenumber",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=400
+ ),
+ ConstrainedNumber(
+ name="stripeintensity",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=5000
+ ),
+ ConstrainedNumber(
+ name="blurriness",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=200
+ ),
+ ConstrainedNumber(
+ name="contrast",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=200
+ ),
+ ConstrainedNumber(
+ name="brightness",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=200
+ ),
+ ConstrainedNumber(
+ name="saturation",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=200
+ ),
+ ConstrainedNumber(
+ name="hue",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=200
+ ),
+ ConstrainedNumber(
+ name="percentbeveled",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=100
+ ),
+ ConstrainedNumber(
+ name="rotate",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=360
+ ),
+ ConstrainedNumber(
+ name="tilt",
+ required=False,
+ enforce_int=True,
+ min=0,
+ max=360
+ ),
+ Bool(
+ name="flop",
+ required=False,
+ ),
+ Bool(
+ name="flip",
+ required=False
+ )
+ )
diff --git a/ricky/pbgradient/probabilities.json b/ricky/pbgradient/probabilities.json
new file mode 100644
index 0000000..0c6c0df
--- /dev/null
+++ b/ricky/pbgradient/probabilities.json
@@ -0,0 +1,120 @@
+{
+ "width" : [
+ {"value": 40, "weight": 10}
+ ],
+ "height" : [
+ {"value": 400, "weight": 100}
+ ],
+ "color1" : [
+ {"value": "", "weight": 0},
+ {"value": "black", "weight": 1},
+ {"value": "white", "weight": 2}
+ ],
+ "color2" : [
+ {"value": "", "weight": 0},
+ {"value": "black", "weight": 2},
+ {"value": "white", "weight": 1}
+ ],
+ "stripes" : [
+ {"value": "true", "weight": 3},
+ {"value": "false", "weight": 1}
+ ],
+ "stripenumber" : [
+ {"value": 3, "weight": 10},
+ {"value": 10, "weight": 10},
+ {"value": 20, "weight": 10},
+ {"value": 100, "weight": 10},
+ {"value": 40, "weight": 10},
+ {"value": 1, "weight": 50},
+ {"value": 2, "weight": 50},
+ {"value": 2, "weight": 50}
+ ],
+ "stripeintensity" : [
+ {"value": 1000, "weight": 10},
+ {"value": 4, "weight": 10}
+ ],
+ "contrast" : [
+ {"value": "", "weight": 0},
+ {"value": "", "weight": 300}
+ ],
+ "brightness" : [
+ {"value": "", "weight": 0},
+ {"value": "", "weight": 300}
+ ],
+ "saturation" : [
+ {"value": "", "weight": 0},
+ {"value": "", "weight": 300}
+ ],
+ "hue" : [
+ {"value": "", "weight": 0},
+ {"value": "", "weight": 300}
+ ],
+ "halftone" : [
+ {"value": "", "weight": 60},
+ {"value": "checkeredfade", "weight": 10},
+ {"value": "etchedtransition", "weight": 10},
+ {"value": "bendaydots", "weight": 10},
+ {"value": "smallerdots1", "weight": 10},
+ {"value": "smallerdots2", "weight": 10},
+ {"value": "flatstripes", "weight": 10}
+ ],
+ "bevel" : [
+ {"value": "", "weight": 4},
+ {"value": "flatout", "weight": 1},
+ {"value": "flatinner", "weight": 0},
+ {"value": "evenlyframed", "weight": 1},
+ {"value": "biginner", "weight": 1},
+ {"value": "bigouter", "weight": 1},
+ {"value": "dramaticflatout", "weight": 1},
+ {"value": "dramaticflatinner", "weight": 1}
+ ],
+ "blurriness" : [
+ {"value": 30, "weight": 10},
+ {"value": 10, "weight": 10},
+ {"value": 5, "weight": 10},
+ {"value": 20, "weight": 10},
+ {"value": 25, "weight": 10},
+ {"value": 7, "weight": 10},
+ {"value": "", "weight": 1}
+ ],
+ "percentbeveled" : [
+ {"value": 30, "weight": 10},
+ {"value": 10, "weight": 10},
+ {"value": 5, "weight": 10},
+ {"value": 20, "weight": 10},
+ {"value": 25, "weight": 10},
+ {"value": 7, "weight": 10},
+ {"value": "", "weight": 1}
+ ],
+ "rotate" : [
+ {"value": 0, "weight": 200},
+ {"value": 90, "weight": 2},
+ {"value": 180, "weight": 2},
+ {"value": 270, "weight": 2}
+ ],
+ "tilt" : [
+ {"value": 0, "weight": 200},
+ {"value": 90, "weight": 2},
+ {"value": 180, "weight": 2},
+ {"value": 270, "weight": 2}
+ ],
+ "flop_probabilities : flip" : [
+ {"value": "", "weight": 1},
+ {"value": "true", "weight": 1}
+ ],
+ "filetype" : [
+ {"value": "png", "weight": 10},
+ {"value": "jpg", "weight": 2},
+ {"value": "gif", "weight": 2}
+ ],
+ "gradienttype" : [
+ {"value": "canvas", "weight": 1},
+ {"value": "gradient", "weight": 5},
+ {"value": "radial", "weight": 1},
+ {"value": "colorspace", "weight": 1},
+ {"value": "plasmawash", "weight": 2},
+ {"value": "gradientwash", "weight": 1},
+ {"value": "mirrored", "weight": 0},
+ {"value": "noise", "weight": 1}
+ ]
+}
diff --git a/ricky/pbgradient/probabilities.py b/ricky/pbgradient/probabilities.py
new file mode 100644
index 0000000..d77739f
--- /dev/null
+++ b/ricky/pbgradient/probabilities.py
@@ -0,0 +1,102 @@
+from ricky.param.probabilities import Probabilities
+
+width_probabilities = Probabilities.from_dict(
+ {"value": 40, "weight": 10},
+)
+height_probabilities = Probabilities.from_dict(
+ {"value": 400, "weight": 100},
+)
+color1_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 0},
+# {"value": "black", "weight": 1},
+# {"value": "white", "weight": 2},
+)
+color2_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 0},
+# {"value": "black", "weight": 2},
+# {"value": "white", "weight": 1},
+)
+stripes_probabilities = Probabilities.from_dict(
+ {"value": "true", "weight": 3},
+ {"value": "false", "weight": 1},
+)
+stripenumber_probabilities = Probabilities.from_dict(
+ {"value": 3, "weight": 10},
+ {"value": 10, "weight": 10},
+ {"value": 20, "weight": 10},
+ {"value": 100, "weight": 10},
+ {"value": 40, "weight": 10},
+# {"value": 1, "weight": 50},
+# {"value": 2, "weight": 50},
+# {"value": 2, "weight": 50},
+
+)
+stripeintensity_probabilities = Probabilities.from_dict(
+ {"value": 1000, "weight": 10},
+ {"value": 4, "weight": 10},
+)
+# contrast_probabilities = \
+brightness_probabilities = \
+ saturation_probabilities = \
+ hue_probabilities = \
+ Probabilities.from_dict(
+ {"value": "", "weight": 0},
+# {"value": "", "weight": 300},
+)
+halftone_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 60},
+ {"value": "checkeredfade", "weight": 10},
+ {"value": "etchedtransition", "weight": 10},
+ {"value": "bendaydots", "weight": 10},
+ {"value": "smallerdots1", "weight": 10},
+ {"value": "smallerdots2", "weight": 10},
+ {"value": "flatstripes", "weight": 10},
+)
+bevel_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 4},
+ {"value": "flatout", "weight": 1},
+ {"value": "flatinner", "weight": 0},
+ {"value": "evenlyframed", "weight": 1},
+# {"value": "biginner", "weight": 1},
+ {"value": "bigouter", "weight": 1},
+ {"value": "dramaticflatout", "weight": 1},
+# {"value": "dramaticflatinner", "weight": 1},
+)
+
+blurriness_probabilities = \
+ percentbeveled_probabilities = Probabilities.from_dict(
+ {"value": 30, "weight": 10},
+ {"value": 10, "weight": 10},
+ {"value": 5, "weight": 10},
+ {"value": 20, "weight": 10},
+ {"value": 25, "weight": 10},
+ {"value": 7, "weight": 10},
+ {"value": "", "weight": 1},
+)
+rotate_probabilities = \
+ tilt_probabilities = Probabilities.from_dict(
+ {"value": 0, "weight": 200},
+ {"value": 90, "weight": 2},
+ {"value": 180, "weight": 2},
+ {"value": 270, "weight": 2},
+)
+flop_probabilities = flip_probabilities = Probabilities.from_dict(
+ {"value": "", "weight": 1},
+ {"value": "true", "weight": 1},
+)
+
+filetype_probabilities = Probabilities.from_dict(
+ {"value": "png", "weight": 10},
+ {"value": "jpg", "weight": 2},
+ {"value": "gif", "weight": 2},
+)
+gradienttype_probabilities = Probabilities.from_dict(
+ {"value": "canvas", "weight": 1},
+ {"value": "gradient", "weight": 5},
+ {"value": "radial", "weight": 1},
+ {"value": "colorspace", "weight": 1},
+ {"value": "plasmawash", "weight": 2},
+ {"value": "gradientwash", "weight": 1},
+ {"value": "mirrored", "weight": 0},
+ {"value": "noise", "weight": 1},
+)
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},
+)
+
diff --git a/ricky/pbpattern/__init__.py b/ricky/pbpattern/__init__.py
new file mode 100755
index 0000000..fe475cb
--- /dev/null
+++ b/ricky/pbpattern/__init__.py
@@ -0,0 +1,14 @@
+from ricky.pb import Pb
+from ricky.pbpattern.params import Params
+from ricky.config import IMPATTERN_URL
+
+
+class PbPattern(Pb):
+ def __init__(self):
+ self.url = IMPATTERN_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/pbpattern/params.py b/ricky/pbpattern/params.py
new file mode 100644
index 0000000..ea789cd
--- /dev/null
+++ b/ricky/pbpattern/params.py
@@ -0,0 +1,24 @@
+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.config import PATTERN_URL_BASE
+
+
+class Params(_Params):
+ def __init__(self):
+ self._params = (
+ Username(name="username", required=False),
+ PbageUrl(name="image_url", required=True),
+ Enum(
+ name="pattern_url",
+ required=True,
+ options=self._get_pattern_urls()
+ )
+ )
+
+ def _get_pattern_urls(self):
+ return set(
+ ["%s/img/%s.png" % (PATTERN_URL_BASE, i) for i in xrange(0, 97)] +
+ ["%s/img/a%s.png" % (PATTERN_URL_BASE, i) for i in xrange(1, 42)]
+ )