• Stars
    star
    1,256
  • Rank 37,419 (Top 0.8 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 11 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create beautiful generative geometric background images from a string.

This project is largely unmaintained now.

I'll happily accept PRs to keep things in working order, but I no longer plan to make updates.


Ruby Ruby Style Guide

GeoPattern

Generate beautiful tiling SVG patterns from a string. The string is converted into a SHA and a color and pattern are determined based on the values in the hash. The color is determined by shifting the hue and saturation from a default (or passed in) base color. One of 16 patterns is used (or you can specify one) and the sizing of the pattern elements is also determined by the hash values.

You can use the generated pattern as the background-image for a container. Using the base64 representation of the pattern still results in SVG rendering, so it looks great on retina displays.

See the GitHub Guides site and the Explore section of GitHub are examples of this library in action. Brandon Mills has put together an awesome live preview page that's built on his Javascript port.

Installation

Note: as of version 1.4.0, Ruby version 2 or greater is required.

Add this line to your application's Gemfile:

gem 'geo_pattern'

And then execute:

$ bundle

Or install it yourself as:

$ gem install geo_pattern

Usage

Make a new pattern:

pattern = GeoPattern.generate('Mastering Markdown')

To specify a base background color (with a hue and saturation that adjusts depending on the string):

pattern = GeoPattern.generate('Mastering Markdown', base_color: '#fc0')

To use a specific background color (w/o any hue or saturation adjustments):

pattern = GeoPattern.generate('Mastering Markdown', color: '#fc0')

To use a specific pattern generator:

pattern = GeoPattern.generate('Mastering Markdown', patterns: :sine_waves)

To use a subset of the available patterns:

pattern = GeoPattern.generate('Mastering Markdown', patterns: [:sine_waves, :xes])

Get the SVG string:

puts pattern.to_svg
# => <svg xmlns="http://www.w3.org/2000/svg" ...

Get the Base64 encoded string:

puts pattern.to_base64
# => PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC...

You can then use this string to set the background:

<div style="background-image: <%= pattern.to_data_uri %>"></div>

Available patterns

Note: As of version 1.3.0, string references (e.g. overlapping_circles) are deprecated in favor of symbol references (e.g. :overlapping_circles).

:chevrons

:octagons

:overlapping_circles

:plus_signs

:xes

:sine_waves

:hexagons

:overlapping_rings

:plaid

:triangles

:squares

:nested_squares

:mosaic_squares

:concentric_circles

:diamonds

:tessellation

Inspection of pattern

If you want to get some more information about a pattern, please use the following methods.

pattern = GeoPattern.generate('Mastering Markdown', patterns: [:sine_waves, :xes])

# The color of the background in html notation
pattern.background.color.to_html

# The color of the background in svg notation
pattern.background.color.to_svg


# The input colors
pattern.background.preset.color
pattern.background.preset.base_color

# The generator
pattern.background.generator

To get more information about the structure of the pattern, please use the following methods:

pattern = GeoPattern.generate('Mastering Markdown', patterns: [:sine_waves, :xes])

# The name of the structure
pattern.structure.name

# The generator of the structure
pattern.structure.generator

Rake Support

string = 'Mastering markdown'

require 'geo_pattern/geo_pattern_task'

GeoPattern::GeoPatternTask.new(
  name: 'generate',
  description: 'Generate patterns to make them available as fixtures',
  data: {
    'fixtures/generated_patterns/diamonds_with_color.svg'      => { input: string, patterns: [:diamonds], color: '#00ff00' },
    'fixtures/generated_patterns/diamonds_with_base_color.svg' => { input: string, patterns: [:diamonds], base_color: '#00ff00' }
  }
)

Developing

Generate Fixtures

rake fixtures:generate

Run tests

rake test

Contributing

  1. Fork it ( https://github.com/jasonlong/geo_pattern/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Development

Prefix rspec-commandline with RSPEC_PROFILE=1 to output the ten slowest examples of the test suite.

RSPEC_PROFILE=1 bundle exec rspec

Ports & related projects

JavaScript port by Brandon Mills: https://github.com/btmills/geopattern

TypeScript port by MooYeol Lee: https://github.com/mooyoul/geo-pattern

Python port by Bryan Veloso: https://github.com/bryanveloso/geopatterns

Elixir port by Anne Johnson: https://github.com/annejohnson/geo_pattern

PHP port by Anand Capur: https://github.com/redeyeventures/geopattern-php

Go port by Pravendra Singh: https://github.com/pravj/geopattern

CoffeeScript port by Aleks (muchweb): https://github.com/muchweb/geo-pattern-coffee

Cocoa port by Matt Faluotico: https://github.com/mattfxyz/GeoPattern-Cocoa

Middleman extension by @maxmeyer: https://github.com/fedux-org/middleman-geo_pattern

Dart(Flutter) port by @suyash: https://github.com/suyash/geopattern

Lua port by Ivan Azoyan: https://github.com/azoyan/geopattern

More Repositories

1

isometric-contributions

Browser extension for rendering an isometric pixel art version of your GitHub contribution graph.
JavaScript
3,395
star
2

cayman-theme

A responsive theme for GitHub Pages
CSS
1,505
star
3

mater

πŸ… A simple menubar Pomodoro app
JavaScript
524
star
4

lavalamp

A text editor theme that visually differentiates languages.
Vim Script
327
star
5

iterm2-icons

Replacement icon for iTerm2 or other macOS terminal apps. Designed for Big Sur.
242
star
6

jasonlong

HTML
180
star
7

benfords-law

Experimenting with Benford's Law
CSS
133
star
8

architect-theme

Open Source version of the GitHub Pages theme
CSS
91
star
9

vim-replacement-icon

A simple and clean replacement icon for Vim.
39
star
10

vim-textobj-css

Vim text objects for CSS, Sass, etc.
Vim Script
33
star
11

tactile-theme

Open Source version of the GitHub Pages theme
CSS
29
star
12

dotfiles

Files. With dots in front of them.
Shell
28
star
13

blackantmedia

Portfolio site of Jason Long
PHP
26
star
14

jasonlong.me

My personal site
Astro
20
star
15

reddit-tighty-whities

A userstyle that strips Reddit down to the bare minimum.
CSS
10
star
16

json-contributions

Serverless function to get a JSON format of a user's GitHub contribution chart
JavaScript
10
star
17

iterm-clrs

An iTerm theme based on @mrmrs nicer color palette for the web.
9
star
18

3d-contributions

JavaScript
7
star
19

training-cert-generator

Command line tool for generating PDF training certificates
Ruby
7
star
20

next.js-three.js-demo

JavaScript
7
star
21

nord-iterm2

A slightly higher-contrast version of Nord
4
star
22

ultisnippets

My snippets for Ultisnip in Vim
3
star
23

backups-ui

Static templates for backups UI
JavaScript
3
star
24

processing-fm

Experiments with Processing.js and Last.FM API
JavaScript
2
star
25

cinecastfilms.com

JavaScript
2
star
26

pixelbits

A daily creative coding exercise.
HTML
1
star
27

sell.github.io

CSS
1
star
28

responsive-actions-logs

Small Node app to prototype a responsive version of the Actions log view
HTML
1
star
29

pixel-hubbers

Pixelcat experiment with three.js
JavaScript
1
star
30

nugit

Quick spike of refreshing git-scm.com with Tachyons
CSS
1
star
31

dynamic-favicons

JavaScript
1
star
32

brave-replacement-icon

macOS replacement icon for Brave
1
star