A beautiful, powerful, visual word search maker created with the power of Python!
It is a kind of puzzle where you have to find words from. Why don't you check out this Wikipedia page?
Right, you can simply use a word search generator websites. But do take a look at these:
- With Elektra, you can make a word search puzzle that looks waaaaaaaay better than other websites.
- It's written in Python! It uses Pillow, a fork of Python Imaging Library.
- It's really easy to use!
- It generates a PIL/Pillow Image object. So yes, you can edit it further, all you want!
- It's highly customizable. You can set your custom font, colors, grid size, box size etc! See the examples below.
- It's open source.
- Python, obviously! Get Python 2.7.x from here.
- Pillow. It is a fork of PIL. You can install it by
pip install pillow --upgrade
if you have pip.
That's it!
Unfortunately, I still haven't packaged it yet. You have to clone this repository and write your scripts in the same directory that these files live in. For example:
- Run
git clone https://github.com/naeem-hasan/elektra
in the terminal or download and unzip this repository. - Run
cd elektra
or manually go to that unzippedelektra
folder. - Write your script there so that you can
import elektra
with no problem.
Right. Consider this simple sample code:
from elektra import ElektraSearch
search = ElektraSearch()
search.add_words("python", "google", "harry", "potter", "accio")
search.make_puzzle()
search.render_image()
search.save_image("simple.jpg")
This produces the following result:
There, you're interested! An ElektraSearch object also has the following methods:
make_puzzle()
- Makes the word search puzzle.render_image()
- Renders the image! Note that, before calling this method, you have to make the puzzle itself by calling themake_puzzle()
method.render_and_show()
- Basically, for debugging. It renders and immediately shows the output to screen.get_image()
- Returns a PIL/Pillow Image object.save_image(path, format=None)
- Saves the rendered image topath
. Can also handle specifiedformat
.
For making the puzzle:
add_words(*args)
- Self explanatory. Use multiple arguments, if you want to use a list, don't forget to put an asterisk sign like thissearch.add_words(*mylist)
.set_grid_size(size)
- Specify the grid size by providing it a two number tuple like (x, y).set_difficulty(difficulty)
- Set your puzzle difficulty with it! Use a number from 0 to 5.- 0 - Right
- 1 - Right, down
- 2 - Right, down, with right-down diagonals
- 3 - Right, down, up, with right diagonals
- 4 - All directions, with right diagonals
- 5 - All directions, with all diagonals
- `set_iterations(x) - Default is 30. An iteration is like an attempt to place the words.
Note that, the default difficulty level is 2. You can simply specify it when you're making the object too!
And the following methods are for visual customization:
use_shade(b)
- Whether the boxes should have white shades. Put a boolean variable here. This is turned on by default.use_border(b)
- Whether the cells should be bordered. This is turned off by default. You can set the border width by callingset_border_width(x)
method. The default with is set to 1.set_border_color(x)
- Specify the border color here. Default is black. You can use a (R, G, B) tuple, or a hex string, or even a 'red' kind of string.set_box_size(size)
- Takes a (x, y) tuple. You can set the cell size here. Default is (80, 80).set_font_path(path)
,set_font_size(x)
,set_font_color(x)
- These are the methods for customizing fonts and text style.set_color_generator(generator)
- Pass on your color generator function if you wish. It uses a random color generator by default.
For solutions:
get_solutions()
- Returns a list with [word, pos, direction] for each used word in the grid.print_solutions()
- Prints all the used words' positions and directions.
Sure!
You can find all of these puzzles' codes in the examples folder!
I'd love if you contributed!
I wouldn't say my Elektra is really fast. Also, I didn't write the word_search.py file myself, only edited it a lot. I found the original script somewhere which I totally forgot. I'm feeling really bad for not being able to credit the actual author.