Skip to content

Commit

Permalink
Merge pull request swyddfa#89 from alcarney/img-tweaks
Browse files Browse the repository at this point in the history
Tweaks to the Layered Image object
  • Loading branch information
alcarney committed Jan 12, 2019
2 parents 90d25e9 + facfb8a commit edaf18d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 65 deletions.
11 changes: 10 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
v0.9.2 - 2019-01-06
v0.9.3 - 2019-01-12
-------------------

Changed
^^^^^^^

- When adding layers the :code:`LayeredImage` now accepts the color as a
string automatically converting it to a :code:`FillColor` behind the scenes.

v0.9.2 - 2019-01-07
-------------------

Changed
Expand Down
58 changes: 24 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,30 @@ lines of Python


```python
from stylo.image import LayeredImage
from stylo.color import FillColor
from stylo.shape import Circle, Rectangle, Triangle
from stylo.domain.transform import translate

# Let's define some colours
black = FillColor("000000")
seablue = FillColor("0000ff")
white = FillColor("ffffff")
yellow = FillColor("ffff00")
red = FillColor("dd2300")

# Now for the shapes we will draw
sun = Circle(-7, 3.4, 1.5)
sea = Circle(0, -55, 55)
sails = Triangle((0.1, 0.6), (2.5, 0.6), (0.1, 3.5)) | Triangle((-0.1, 0.6), (-1.5, 0.6), (-0.1, 3.5))
boat = Rectangle(0, 0, 3.5, 1) | Triangle((1.75, -0.5), (1.75, 0.5), (2.25, 0.5))
mast = Rectangle(0, 2, 0.125, 3)

# Move some into position
boat = boat >> translate(0, -2)
sails = sails >> translate(0, -2)
mast = mast >> translate(0, -2)

# Finally let's bring it all together
image = LayeredImage(background="99ddee", scale=8)

image.add_layer(sun, yellow)
image.add_layer(sea, seablue)
image.add_layer(boat, red)
image.add_layer(mast, black)
image.add_layer(sails, white)

image(1920, 1080, filename="docs/_static/examples/a-boat.png");
import stylo as st

# Let's define the shapes we want to draw
sun = st.Circle(-7, 3.4, 1.5, fill=True)
sea = st.Circle(0, -55, 55, fill=True)
sails = st.Triangle((0.1, 0.6), (2.5, 0.6), (0.1, 3.5)) | st.Triangle((-0.1, 0.6), (-1.5, 0.6), (-0.1, 3.5))
boat = st.Rectangle(0, 0, 3.5, 1) | st.Triangle((1.75, -0.5), (1.75, 0.5), (2.25, 0.5))
mast = st.Rectangle(0, 2, 0.125, 3)

# Move some into position
boat = boat >> st.translate(0, -2)
sails = sails >> st.translate(0, -2)
mast = mast >> st.translate(0, -2)

# Finally let's bring it all together
image = st.LayeredImage(background="99ddee", scale=8)

image.add_layer(sun, "ffff00")
image.add_layer(sea, "0000ff")
image.add_layer(boat, "dd2300")
image.add_layer(mast, "000000")
image.add_layer(sails, "ffffff")

image(1920, 1080, filename="a-boat.png")
```

## Installation
Expand Down
44 changes: 17 additions & 27 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,28 @@ Python.
:include-code:
:display-width: 75%

from stylo.image import LayeredImage
from stylo.color import FillColor
from stylo.shape import Circle, Rectangle, Triangle
from stylo.domain.transform import translate

# Let's define some colours
black = FillColor("000000")
seablue = FillColor("0000ff")
white = FillColor("ffffff")
yellow = FillColor("ffff00")
red = FillColor("dd2300")

# Now for the shapes we will draw
sun = Circle(-7, 3.4, 1.5, fill=True)
sea = Circle(0, -55, 55, fill=True)
sails = Triangle((0.1, 0.6), (2.5, 0.6), (0.1, 3.5)) | Triangle((-0.1, 0.6), (-1.5, 0.6), (-0.1, 3.5))
boat = Rectangle(0, 0, 3.5, 1) | Triangle((1.75, -0.5), (1.75, 0.5), (2.25, 0.5))
mast = Rectangle(0, 2, 0.125, 3)
import stylo as st

# Let's define the shapes we want to draw
sun = st.Circle(-7, 3.4, 1.5, fill=True)
sea = st.Circle(0, -55, 55, fill=True)
sails = st.Triangle((0.1, 0.6), (2.5, 0.6), (0.1, 3.5)) | st.Triangle((-0.1, 0.6), (-1.5, 0.6), (-0.1, 3.5))
boat = st.Rectangle(0, 0, 3.5, 1) | st.Triangle((1.75, -0.5), (1.75, 0.5), (2.25, 0.5))
mast = st.Rectangle(0, 2, 0.125, 3)

# Move some into position
boat = boat >> translate(0, -2)
sails = sails >> translate(0, -2)
mast = mast >> translate(0, -2)
boat = boat >> st.translate(0, -2)
sails = sails >> st.translate(0, -2)
mast = mast >> st.translate(0, -2)

# Finally let's bring it all together
image = LayeredImage(background="99ddee", scale=8)
image = st.LayeredImage(background="99ddee", scale=8)

image.add_layer(sun, yellow)
image.add_layer(sea, seablue)
image.add_layer(boat, red)
image.add_layer(mast, black)
image.add_layer(sails, white)
image.add_layer(sun, "ffff00")
image.add_layer(sea, "0000ff")
image.add_layer(boat, "dd2300")
image.add_layer(mast, "000000")
image.add_layer(sails, "ffffff")

Be sure to check out `Stylo Doodles`_ - our community driven example gallery for
plenty of inspiration!
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "stylo"
version = "0.9.2"
version = "0.9.3"
description = "Drawing images with a blend of Python and Mathematics"
readme = "README.md"

Expand Down
2 changes: 1 addition & 1 deletion stylo/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.2"
__version__ = "0.9.3"
5 changes: 4 additions & 1 deletion stylo/image/layered.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from stylo.color import RGB8
from stylo.color import RGB8, FillColor
from stylo.domain import get_real_domain
from stylo.image import Image
from stylo.image.image import Drawable, render_drawable
Expand All @@ -22,6 +22,9 @@ def __init__(self, background=None, scale=2, colorspace=None):

def add_layer(self, shape, color, domain=None):

if isinstance(color, (str,)):
color = FillColor(color)

# Make sure everyone uses the same colorspace.
color.colorspace = self.colorspace

Expand Down

0 comments on commit edaf18d

Please sign in to comment.