kopia lustrzana https://github.com/sepandhaghighi/samila
Transparent Feature Added (#133)
* add : set_background function usage added to `genimage.py`. * add : `set_background` function added. * log : changes logged. (#118) * test : some tests added. * fix : minor typo in tests fixed. * add : transparent added to documents. * update : CHANGELOG.md updated. * fix : minor typo fixed. * edit : Transparent description added. * edit : make `Transparent` bold.pull/136/head
rodzic
6007ab4c16
commit
fd80f431ef
|
@ -6,10 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- `set_background` function
|
||||
- `is_valid_color` function
|
||||
- `color_complement` function
|
||||
- `select_color` function
|
||||
### Changed
|
||||
- Transparent mode support for `bgcolor` parameter
|
||||
- Random mode modified
|
||||
- Complementary color support for `color` and `bgcolor` parameters
|
||||
- `filter_color` function modified
|
||||
|
|
|
@ -180,6 +180,9 @@ Samila is a generative art generator written in Python, Samila let's you create
|
|||
3. Hex (example: `color="#eeefff"`)
|
||||
4. Random (example: `color="random"`)
|
||||
5. Complement (example: `color="complement", bgcolor="blue"`)
|
||||
6. Transparent (example: `bgcolor="transparent"`)
|
||||
|
||||
⚠️ **Transparent** mode is only available for background
|
||||
|
||||
### Regeneration
|
||||
```pycon
|
||||
|
|
|
@ -161,7 +161,10 @@
|
|||
" 2. RGB/RGBA (example: `color=(0.1,0.1,0.1)`, `color=(0.1,0.1,0.1,0.1)`)\n",
|
||||
" 3. Hex (example: `color=\"#eeefff\"`)\n",
|
||||
" 4. Random (example: `color=\"random\"`)\n",
|
||||
" 5. Complement (example: `color=\"complement\", bgcolor=\"blue\"`)"
|
||||
" 5. Complement (example: `color=\"complement\", bgcolor=\"blue\"`)\n",
|
||||
" 6. Transparent (example: `bgcolor=\"transparent\"`)\n",
|
||||
"\n",
|
||||
"⚠️ **Transparent** mode is only available for background"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -352,4 +355,4 @@
|
|||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
}
|
|
@ -157,6 +157,8 @@ def select_color(color):
|
|||
:return: color
|
||||
"""
|
||||
if isinstance(color, str):
|
||||
if color.upper() == "TRANSPARENT":
|
||||
return "TRANSPARENT"
|
||||
if color.upper() == "COMPLEMENT":
|
||||
return "COMPLEMENT"
|
||||
if color.upper() == "RANDOM":
|
||||
|
@ -172,6 +174,27 @@ def select_color(color):
|
|||
return None
|
||||
|
||||
|
||||
def set_background(bgcolor, fig, ax):
|
||||
"""
|
||||
Set background for figure and axis.
|
||||
|
||||
:param bgcolor: given background color
|
||||
:type bgcolor: any format
|
||||
:param fig: figure
|
||||
:type fig: matplotlib.figure.Figure
|
||||
:param ax: axis
|
||||
:type ax: matplotlib.axes._subplots.AxesSubplot
|
||||
:return: None
|
||||
"""
|
||||
if bgcolor == "TRANSPARENT":
|
||||
ax.patch.set_visible(False)
|
||||
fig.patch.set_visible(False)
|
||||
return
|
||||
fig.set_facecolor(bgcolor)
|
||||
ax.set_facecolor(bgcolor)
|
||||
return
|
||||
|
||||
|
||||
def filter_projection(projection):
|
||||
"""
|
||||
Filter given projection.
|
||||
|
|
|
@ -8,6 +8,7 @@ import matplotlib.pyplot as plt
|
|||
from .functions import _GI_initializer, plot_params_filter, generate_params_filter, save_params_filter
|
||||
from .functions import float_range, save_data_file, save_fig_file, save_fig_buf, save_config_file
|
||||
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload, fill_data
|
||||
from .functions import set_background
|
||||
from .params import *
|
||||
from warnings import warn
|
||||
|
||||
|
@ -126,9 +127,8 @@ class GenerativeImage:
|
|||
linewidth)
|
||||
fig = plt.figure()
|
||||
fig.set_size_inches(self.size[0], self.size[1])
|
||||
fig.set_facecolor(self.bgcolor)
|
||||
ax = fig.add_subplot(111, projection=self.projection)
|
||||
ax.set_facecolor(self.bgcolor)
|
||||
set_background(self.bgcolor, fig, ax)
|
||||
ax.scatter(
|
||||
self.data2,
|
||||
self.data1,
|
||||
|
|
|
@ -32,6 +32,8 @@ True
|
|||
>>> select_color(None)
|
||||
>>> select_color("complement")
|
||||
'COMPLEMENT'
|
||||
>>> select_color("transparent")
|
||||
'TRANSPARENT'
|
||||
>>> s = list(float_range(1,1.5,0.1))
|
||||
>>> s
|
||||
[1.0, 1.1, 1.2000000000000002, 1.3000000000000003, 1.4000000000000004]
|
||||
|
|
|
@ -161,6 +161,9 @@ True
|
|||
True
|
||||
>>> g = GenerativeImage()
|
||||
>>> g.generate()
|
||||
>>> g.plot(color="white", bgcolor="transparent")
|
||||
>>> g.bgcolor == "TRANSPARENT"
|
||||
True
|
||||
>>> g.plot(color="white", bgcolor="black", spot_size=0.1)
|
||||
>>> result = g.save_config()
|
||||
>>> result["status"]
|
||||
|
|
Ładowanie…
Reference in New Issue