# HG changeset patch # User Drew Perttula # Date 1492283792 0 # Node ID 69088fe2865e7f2a39e16647e3b22403cf5ea910 # Parent 15f296550447002a653298c058d2ddcac22f2aea more progress on paint Ignore-this: ff24e7a8e8f95bde364841c6076e839 diff -r 15f296550447 -r 69088fe2865e bin/paintserver --- a/bin/paintserver Sat Apr 15 04:03:28 2017 +0000 +++ b/bin/paintserver Sat Apr 15 19:16:32 2017 +0000 @@ -15,12 +15,15 @@ import light9.paint.solve from lib.cycloneerr import PrettyErrorHandler + class Solve(PrettyErrorHandler, cyclone.web.RequestHandler): def post(self): painting = json.loads(self.request.body) reload(light9.paint.solve) + solver = light9.paint.solve.Solver(self.settings.graph) + solver.loadSamples() with self.settings.stats.solve.time(): - out = light9.paint.solve.solve(painting) + out = solver.solve(painting) self.write(json.dumps(out)) class App(object): diff -r 15f296550447 -r 69088fe2865e light9/paint/solve.py --- a/light9/paint/solve.py Sat Apr 15 04:03:28 2017 +0000 +++ b/light9/paint/solve.py Sat Apr 15 19:16:32 2017 +0000 @@ -1,2 +1,47 @@ -def solve(painting): - return 0 +from light9.namespaces import RDF, L9 +from PIL import Image +import scipy.misc +import cairo + +class Solver(object): + def __init__(self, graph): + self.graph = graph + self.samples = {} # uri: Image array + + def loadSamples(self): + """learn what lights do from images""" + + with self.graph.currentState() as g: + for samp in g.subjects(RDF.type, L9['LightSample']): + path = 'show/dance2017/cam/test/%s' % g.value(samp, L9['path']) + img = Image.open(path) + img.thumbnail((100, 100)) + self.samples[samp] = scipy.misc.fromimage(img, mode='RGB') + + def draw(self, painting, w, h): + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) + ctx = cairo.Context(surface) + ctx.move_to(0, 0) + ctx.line_to(100,30) + + ctx.set_source_rgb(0.3, 0.2, 0.5) + ctx.set_line_width(20) + ctx.stroke() + # then blur? + surface.write_to_png('/tmp/surf.png') + + def solve(self, painting): + """ + given strokes of colors on a photo of the stage, figure out the + best light settings to match the image + """ + self.draw(painting, 100, 80) + return 0 + + + def simulationLayers(self, settings): + """ + how should a simulation preview approximate the light settings + (device attribute values) by combining photos we have? + """ + diff -r 15f296550447 -r 69088fe2865e light9/paint/solve_test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light9/paint/solve_test.py Sat Apr 15 19:16:32 2017 +0000 @@ -0,0 +1,12 @@ +import unittest +import solve + +class TestSolve(unittest.TestCase): + def testBlack(self): + s = solve.Solver() + s.loadSamples() + devAttrs = s.solve({'strokes': []}) + self.assertEqual([], devAttrs) + + + diff -r 15f296550447 -r 69088fe2865e light9/web/paint/bg2.jpg Binary file light9/web/paint/bg2.jpg has changed diff -r 15f296550447 -r 69088fe2865e light9/web/paint/paint-elements.coffee --- a/light9/web/paint/paint-elements.coffee Sat Apr 15 04:03:28 2017 +0000 +++ b/light9/web/paint/paint-elements.coffee Sat Apr 15 19:16:32 2017 +0000 @@ -1,7 +1,18 @@ +class Painting + constructor: -> + @strokes = [] + + addStroke: (pts, color) -> + @strokes.push({pts: pts, color: color}) + + getDoc: -> + {strokes: @strokes} + class Stroke - constructor: (pos) -> + constructor: (pos, @color) -> @path = document.createElementNS('http://www.w3.org/2000/svg', 'path') @path.setAttributeNS(null, 'd', "M #{pos[0]} #{pos[1]}") + @pts = [pos] @lastPos = pos appendElem: (parent) -> @@ -11,6 +22,7 @@ if Math.hypot(pos[0] - @lastPos[0], pos[1] - @lastPos[1]) < 30 return @path.attributes.d.value += " L #{pos[0]} #{pos[1]}" + @pts.push(pos) @lastPos = pos Polymer @@ -20,6 +32,7 @@ properties: { } ready: -> + @painting = new Painting() @$.paint.addEventListener('mousedown', @onDown.bind(@)) @$.paint.addEventListener('mousemove', @onMove.bind(@)) @$.paint.addEventListener('mouseup', @onUp.bind(@)) @@ -28,11 +41,12 @@ @$.paint.addEventListener('touchend', @onUp.bind(@)) evPos: (ev) -> - return (if ev.touches?.length? then [Math.round(ev.touches[0].clientX), Math.round(ev.touches[0].clientY)] else [ev.x, ev.y]) + return (if ev.touches?.length? then [Math.round(ev.touches[0].clientX), + Math.round(ev.touches[0].clientY)] else [ev.x, ev.y]) onDown: (ev) -> # if it's on an existing one, do selection - @stroke = new Stroke(@evPos(ev)) + @stroke = new Stroke(@evPos(ev), '#aaaaaa') @stroke.appendElem(@$.paint) @scopeSubtree(@$.paint) @@ -42,6 +56,9 @@ @stroke.move(@evPos(ev)) onUp: (ev) -> + @painting.addStroke(@stroke.pts, @stroke.color) + @$.solve.body = JSON.stringify(@painting.getDoc()) + @$.solve.generateRequest() @stroke = null onResize: (ev) -> diff -r 15f296550447 -r 69088fe2865e light9/web/paint/paint-elements.html --- a/light9/web/paint/paint-elements.html Sat Apr 15 04:03:28 2017 +0000 +++ b/light9/web/paint/paint-elements.html Sat Apr 15 19:16:32 2017 +0000 @@ -1,5 +1,6 @@ +