Skip to content

Commit

Permalink
Merge pull request #13 from KennyOliver/pattern-magic-function
Browse files Browse the repository at this point in the history
Clr.pattern(string, *colors) Magic Function
  • Loading branch information
KennyOliver authored Dec 10, 2021
2 parents 622daeb + f75a480 commit c3abf51
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<a href="https://pypi.org/project/VividHues/"><img src="https://img.shields.io/badge/PyPi-3775A9?style=for-the-badge&logo=pypi&logoColor=white" /></a>

<img src="repo-imgs/vividhues-example.png" width="30%" align="none" />
<img src="repo-imgs/vividhues-console-example.png" width="30%" align="none" />

---

Expand Down Expand Up @@ -57,21 +57,22 @@ RUN pip install VividHues

## :snake: Python Example

<img src="repo-imgs/vividhues-example.png" width="30%" align="right" />
<img src="repo-imgs/vividhues-console-example.png" width="30%" align="right" />

```python
print(Clr.BO + Clr.UL + Clr.rainbow('I love VividHues!') + Clr.RS)
print(f"{Clr.RED}It's got my fave color!{Clr.RS}")
print(f"Soooo {Clr.jazzy('jazzy')}")
print(f"Soooo {Clr.jazzy('jazzy') + Clr.RESET}")
# ^^^
# you'll get an error using "" in f-string interpolations
print(Clr.pattern("Kenny Oliver", Clr.PURPLE, Clr.CYAN, Clr.LIME))
```

## :rainbow: Available Clr codes:
#### Just put a color in the gap ```Clr.___```
###### RED, ORANGE, YELLOW, LIME, GREEN, BLUE, CYAN, PURPLE, PINK, BLACK, WHITE
#### Or use a formatter
###### UNDERLINE, UL, BOLD, BO, RESET, RS
#### Just put a code in the gap ```Clr.___```

###### Clr: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RED, ORANGE, YELLOW, LIME, GREEN, BLUE, CYAN, PURPLE, PINK, BLACK, WHITE
###### Formatter: &nbsp;&nbsp; UNDERLINE, UL, BOLD, BO, RESET, RS


### :magic_wand: Magic Functions
Expand All @@ -95,6 +96,11 @@ print(Clr.rainbow(string))
```
###### Makes any string colored in a rainbow pattern.

#### :test_tube: Clr.pattern()
```python
print(Clr.pattern(string, *color))
```
###### Paint your letters in a repeating pattern, by specifying an unlimited amount of Clr codes!

---
Kenny Oliver ©2021
18 changes: 17 additions & 1 deletion VividHues/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def jazzy(cls, string_to_color: str) -> str:


@classmethod
def rainbow(cls, string_to_color: str):
def rainbow(cls, string_to_color: str) -> str:
""" colors each letter in a rainbow pattern """
rainbow_colors = [Clr.RED, Clr.ORANGE, Clr.YELLOW, Clr.GREEN, Clr.LIME, Clr.CYAN, Clr.BLUE, Clr.PURPLE, Clr.PINK]

Expand All @@ -72,3 +72,19 @@ def rainbow(cls, string_to_color: str):
colors_index = 0

return rainbow_str

@classmethod
def pattern(cls, string_to_color: str, *chosen_clrs) -> str:
""" allow custom definitions of Clr patterns """
pattern_str = ""
string_index = 0
colors_index = 0

while string_index <= len(string_to_color) - 1:
pattern_str += chosen_clrs[colors_index] + string_to_color[string_index]
colors_index += 1
string_index += 1
if colors_index == len(chosen_clrs):
colors_index = 0

return pattern_str
Binary file added repo-imgs/vividhues-console-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed repo-imgs/vividhues-example.png
Binary file not shown.

0 comments on commit c3abf51

Please sign in to comment.