fogleman / primitive

Reproducing images with geometric primitives.
https://primitive.lol/
MIT License
12.35k stars 608 forks source link

Implement ability to export model to json #26

Closed devindi closed 11 months ago

devindi commented 7 years ago

Added ability to export steps into json. Based on #17 and my own requirements Example: primitive -i input.jpg -o out.json -n 10

output

{
  "width": 256,
  "height": 111,
  "background": "#ff6d4345",
  "steps": [
    {
      "type": "triangle",
      "color": "#80b67e99",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 255,
        "Y1": -16,
        "X2": -16,
        "Y2": 1,
        "X3": 269,
        "Y3": 65
      }
    },
    {
      "type": "triangle",
      "color": "#80200a00",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 121,
        "Y1": 126,
        "X2": -16,
        "Y2": 61,
        "X3": 264,
        "Y3": 68
      }
    },
    {
      "type": "triangle",
      "color": "#80412017",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 119,
        "Y1": 40,
        "X2": -15,
        "Y2": 118,
        "X3": 271,
        "Y3": 110
      }
    },
    {
      "type": "triangle",
      "color": "#802f1005",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 144,
        "Y1": 38,
        "X2": 147,
        "Y2": 7,
        "X3": 185,
        "Y3": 44
      }
    },
    {
      "type": "triangle",
      "color": "#80de8777",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 246,
        "Y1": 95,
        "X2": 241,
        "Y2": 16,
        "X3": 225,
        "Y3": 79
      }
    },
    {
      "type": "triangle",
      "color": "#80b28797",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 271,
        "Y1": -8,
        "X2": 197,
        "Y2": 47,
        "X3": 151,
        "Y3": 3
      }
    },
    {
      "type": "triangle",
      "color": "#8088516a",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 69,
        "Y1": 56,
        "X2": 102,
        "Y2": -16,
        "X3": -16,
        "Y3": 13
      }
    },
    {
      "type": "triangle",
      "color": "#80cf9da5",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 190,
        "Y1": 62,
        "X2": 178,
        "Y2": 63,
        "X3": 181,
        "Y3": 17
      }
    },
    {
      "type": "triangle",
      "color": "#801f0f02",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 216,
        "Y1": 44,
        "X2": 229,
        "Y2": 47,
        "X3": 211,
        "Y3": 82
      }
    },
    {
      "type": "triangle",
      "color": "#809a5231",
      "shape": {
        "W": 256,
        "H": 111,
        "X1": 79,
        "Y1": 16,
        "X2": 64,
        "Y2": 99,
        "X3": 85,
        "Y3": 86
      }
    }
  ]
}
Solido commented 7 years ago

This is it! Now it's no more an application but the beginning of a framework. It's getting so modular with your implementation it opens new horizons. I'm grateful to you @devindi for this pull.