phlox 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/README.md +59 -0
- data/Rakefile +2 -0
- data/art/17.png +0 -0
- data/art/a1.png +0 -0
- data/art/a10.png +0 -0
- data/art/a11.png +0 -0
- data/art/a12.png +0 -0
- data/art/a13.png +0 -0
- data/art/a14.png +0 -0
- data/art/a15.png +0 -0
- data/art/a16.png +0 -0
- data/art/a18.png +0 -0
- data/art/a19.png +0 -0
- data/art/a2.png +0 -0
- data/art/a20.png +0 -0
- data/art/a21.png +0 -0
- data/art/a3.png +0 -0
- data/art/a4.png +0 -0
- data/art/a5.png +0 -0
- data/art/a6.png +0 -0
- data/art/a7.png +0 -0
- data/art/a8.png +0 -0
- data/art/a9.png +0 -0
- data/bin/console +14 -0
- data/bin/out.png +0 -0
- data/bin/phlox +7 -0
- data/bin/setup +8 -0
- data/default.nix +6 -0
- data/lib/phlox.rb +13 -0
- data/lib/phlox/gradient_gen.rb +132 -0
- data/lib/phlox/graphics.rb +33 -0
- data/lib/phlox/version.rb +3 -0
- data/out.png +0 -0
- data/phlox.gemspec +30 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9deeecfd6d219c5fe381f7ed5327675fc2d272c7e9c31b08184700983d9b10bc
|
4
|
+
data.tar.gz: 1621c0c35b35bb13284fac5159f4dcf3d6f89e91c2155f94d46a6d959c84824a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22b02aafb68307286392ac989077b0366ba649f06cbc3f447aa4638250b25653d539f9c6b0b9d30962578a951b1f7ad36d4246133852b3bc290edb963a5dc715
|
7
|
+
data.tar.gz: 857eca9dc946c3ff451c80ed64c419f64fcbe27506ba02e1c21addd1806bc8d4e191cfb8e4d4126f30a03cb71044b9aca37ac2af1878fa4852b061c27f18f0ae
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
phlox (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.5.0)
|
10
|
+
rmagick (4.0.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 2.0)
|
17
|
+
phlox!
|
18
|
+
rake (~> 10.0)
|
19
|
+
rmagick (~> 4.0.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Phlox
|
2
|
+
|
3
|
+
A gem for creating generative gradient art. In brief, here's how it works:
|
4
|
+
1. Three trees of mathematical expressions are randomly generated
|
5
|
+
2. These expression trees are used to evaluate the (r, g, b) color of each (x, y) pair in the grid
|
6
|
+
3. The color values for each spot in the grid are turned into pixels on an image
|
7
|
+
It works surprisingly well, and an infinite amount of interesting images can be made.
|
8
|
+
|
9
|
+
## Gallery
|
10
|
+
|
11
|
+
Here are some examples of what `phlox` can generate:
|
12
|
+

|
13
|
+

|
14
|
+

|
15
|
+

|
16
|
+

|
17
|
+

|
18
|
+

|
19
|
+

|
20
|
+

|
21
|
+

|
22
|
+

|
23
|
+
See the `art/` directory for more images.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'phlox'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install phlox
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
You can use the `Phlox::gen_pic` method to generate a gradient art image. All parameters to this method are
|
44
|
+
optional and have default values.
|
45
|
+
```ruby
|
46
|
+
gem 'phlox'
|
47
|
+
|
48
|
+
# generate a 255x255 gradient, scale it by 3, and write it to "out.png"
|
49
|
+
Phlox::gen_pic width: 255, height: 255, fpath: "out.png", scale: 3
|
50
|
+
```
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://gitlab.com/Bleu-Box/phlox.
|
data/Rakefile
ADDED
data/art/17.png
ADDED
Binary file
|
data/art/a1.png
ADDED
Binary file
|
data/art/a10.png
ADDED
Binary file
|
data/art/a11.png
ADDED
Binary file
|
data/art/a12.png
ADDED
Binary file
|
data/art/a13.png
ADDED
Binary file
|
data/art/a14.png
ADDED
Binary file
|
data/art/a15.png
ADDED
Binary file
|
data/art/a16.png
ADDED
Binary file
|
data/art/a18.png
ADDED
Binary file
|
data/art/a19.png
ADDED
Binary file
|
data/art/a2.png
ADDED
Binary file
|
data/art/a20.png
ADDED
Binary file
|
data/art/a21.png
ADDED
Binary file
|
data/art/a3.png
ADDED
Binary file
|
data/art/a4.png
ADDED
Binary file
|
data/art/a5.png
ADDED
Binary file
|
data/art/a6.png
ADDED
Binary file
|
data/art/a7.png
ADDED
Binary file
|
data/art/a8.png
ADDED
Binary file
|
data/art/a9.png
ADDED
Binary file
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "phlox"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/out.png
ADDED
Binary file
|
data/bin/phlox
ADDED
data/bin/setup
ADDED
data/default.nix
ADDED
data/lib/phlox.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "phlox/version"
|
2
|
+
require "phlox/graphics"
|
3
|
+
require "phlox/gradient_gen"
|
4
|
+
|
5
|
+
module Phlox
|
6
|
+
def self.gen_pic width: 255, height: 255, fpath: "out.png", scale: 1
|
7
|
+
graphics = Graphics.new width, height
|
8
|
+
gradient = GradientGen::gen_gradient
|
9
|
+
|
10
|
+
graphics.fill gradient
|
11
|
+
graphics.write fpath, scale
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Phlox
|
2
|
+
module GradientGen
|
3
|
+
# Create a Proc that calculates an [r, g, b] triple for given [x, y] coordinates
|
4
|
+
# based on randomly-generated calculation functions.
|
5
|
+
def self.gen_gradient
|
6
|
+
r, g, b = Node.new, Node.new, Node.new
|
7
|
+
|
8
|
+
Proc.new do |x, y|
|
9
|
+
[r.run(x, y) % 255,
|
10
|
+
g.run(x, y) % 255,
|
11
|
+
b.run(x, y) % 255]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# A node in an expression tree for a pixel color calculation.
|
16
|
+
# Initializing a node also generates its child nodes, and you can use `Node#run` to evaluate
|
17
|
+
# the expression tree into a numerical value.
|
18
|
+
class Node
|
19
|
+
def initialize
|
20
|
+
# calculate the node's value - it can either be a constant, one of the parameters,
|
21
|
+
# a unary function invocation on another node, or a binary invocation on two other nodes
|
22
|
+
types = [:param, :param, :const, :unary, :unary, :binary]
|
23
|
+
@type = types.sample
|
24
|
+
|
25
|
+
case @type
|
26
|
+
when :const
|
27
|
+
@val = const
|
28
|
+
when :param
|
29
|
+
@val = param
|
30
|
+
when :unary
|
31
|
+
unary_call
|
32
|
+
when :binary
|
33
|
+
binary_call
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Evaluate the node and its children into a number, given an x and y parameter.
|
38
|
+
# Any value that produce an error will equal 0.
|
39
|
+
def run x, y
|
40
|
+
begin
|
41
|
+
|
42
|
+
# try calculating the value
|
43
|
+
case @type
|
44
|
+
when :const
|
45
|
+
return @val
|
46
|
+
when :param
|
47
|
+
return {x: x, y: y}[@val]
|
48
|
+
when :unary
|
49
|
+
v1 = @val1.run x, y
|
50
|
+
return run_unary(v1).abs
|
51
|
+
when :binary
|
52
|
+
v1 = @val1.run x, y
|
53
|
+
v2 = @val2.run x, y
|
54
|
+
return run_binary(v1, v2).abs
|
55
|
+
end
|
56
|
+
|
57
|
+
# if something goes wrong, give up and just return 0
|
58
|
+
rescue => e
|
59
|
+
return 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# calculate a random constant, from 0 to 255
|
64
|
+
def const; rand 255; end
|
65
|
+
|
66
|
+
# choose one of the parameters randomly
|
67
|
+
def param; [:x, :y].sample; end
|
68
|
+
|
69
|
+
# make a new argument node and choose a unary function to apply it to
|
70
|
+
def unary_call
|
71
|
+
@val1 = Node.new
|
72
|
+
@fn = unary_fn
|
73
|
+
end
|
74
|
+
|
75
|
+
def binary_call
|
76
|
+
@val1 = Node.new
|
77
|
+
@val2 = Node.new
|
78
|
+
@fn = binary_fn
|
79
|
+
end
|
80
|
+
|
81
|
+
# choose a random unary function
|
82
|
+
def unary_fn
|
83
|
+
[:sq, :sin, :cos, :mod5, :log2, :tan].sample
|
84
|
+
end
|
85
|
+
|
86
|
+
# choose a random binary function
|
87
|
+
def binary_fn
|
88
|
+
[:mul, :add, :and, :or, :xor, :pow, :sub, :div].sample
|
89
|
+
end
|
90
|
+
|
91
|
+
# run @fn on the argument
|
92
|
+
def run_unary v1
|
93
|
+
case @fn
|
94
|
+
when :sq then v1 ** 2
|
95
|
+
when :sin then 50 * Math::sin(radians v1)
|
96
|
+
when :cos then 50 * Math::cos(radians v1)
|
97
|
+
when :mod5 then 10 * (v1.abs % 5)
|
98
|
+
when :log2 then 10 * Math::log2(v1.abs)
|
99
|
+
when :tan then 50 * Math::tan(radians v1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# run @fn on the arguments
|
104
|
+
def run_binary v1, v2
|
105
|
+
case @fn
|
106
|
+
when :mul then v1 * v2
|
107
|
+
when :add then v1 + v2
|
108
|
+
when :and then v1.to_i & v2.to_i
|
109
|
+
when :or then v1.to_i | v2.to_i
|
110
|
+
when :xor then v1.to_i ^ v2.to_i
|
111
|
+
when :pow then v1 ** (v2 % 10)
|
112
|
+
when :sub then v1 - v2
|
113
|
+
when :div then v1 / v2.to_f
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# converts a value from degrees to radians
|
118
|
+
def radians n
|
119
|
+
Math::PI * (n / 180.0)
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
case @type
|
124
|
+
when :const then @val.to_s
|
125
|
+
when :param then @val.to_s
|
126
|
+
when :unary then "#@fn(#@val1)"
|
127
|
+
when :binary then "#@fn(#@val1, #@val2)"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "rmagick"
|
2
|
+
|
3
|
+
module Phlox
|
4
|
+
class Graphics
|
5
|
+
def initialize(width=255, height=255)
|
6
|
+
@width, @height = width, height
|
7
|
+
@img = Magick::Image.new @width, @height
|
8
|
+
end
|
9
|
+
|
10
|
+
# Fill the image with a pixel gradient determined by the proc argument.
|
11
|
+
# The proc should yield a 3-element list of [r, g, b] values for each location.
|
12
|
+
def fill grad_prc
|
13
|
+
# make an array to hold the values
|
14
|
+
data = Array.new(@width) do |x|
|
15
|
+
Array.new(@height) do |y|
|
16
|
+
grad_prc.call x, y
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# write the color values into the image
|
21
|
+
data.each_with_index do |row, y|
|
22
|
+
row.each_with_index do |val, x|
|
23
|
+
@img.pixel_color y, x, "rgb(#{val.join ', '})"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Write the image file to `path` with optional scaling.
|
29
|
+
def write path, scale=1
|
30
|
+
@img.scale(scale).write path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/out.png
ADDED
Binary file
|
data/phlox.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "phlox/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "phlox"
|
8
|
+
spec.version = Phlox::VERSION
|
9
|
+
spec.authors = ["Benjamin Duchild"]
|
10
|
+
spec.email = ["xxarcajethxx@gmail.com"]
|
11
|
+
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.summary = %q{A gem that generates art based on flocking entities.}
|
15
|
+
spec.homepage = "https://gitlab.com/Bleu-Box/phlox/"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rmagick", "~> 4.0", ">= 4.0.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phlox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Duchild
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rmagick
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.0.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '4.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.0.0
|
61
|
+
description:
|
62
|
+
email:
|
63
|
+
- xxarcajethxx@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- art/17.png
|
74
|
+
- art/a1.png
|
75
|
+
- art/a10.png
|
76
|
+
- art/a11.png
|
77
|
+
- art/a12.png
|
78
|
+
- art/a13.png
|
79
|
+
- art/a14.png
|
80
|
+
- art/a15.png
|
81
|
+
- art/a16.png
|
82
|
+
- art/a18.png
|
83
|
+
- art/a19.png
|
84
|
+
- art/a2.png
|
85
|
+
- art/a20.png
|
86
|
+
- art/a21.png
|
87
|
+
- art/a3.png
|
88
|
+
- art/a4.png
|
89
|
+
- art/a5.png
|
90
|
+
- art/a6.png
|
91
|
+
- art/a7.png
|
92
|
+
- art/a8.png
|
93
|
+
- art/a9.png
|
94
|
+
- bin/console
|
95
|
+
- bin/out.png
|
96
|
+
- bin/phlox
|
97
|
+
- bin/setup
|
98
|
+
- default.nix
|
99
|
+
- lib/phlox.rb
|
100
|
+
- lib/phlox/gradient_gen.rb
|
101
|
+
- lib/phlox/graphics.rb
|
102
|
+
- lib/phlox/version.rb
|
103
|
+
- out.png
|
104
|
+
- phlox.gemspec
|
105
|
+
homepage: https://gitlab.com/Bleu-Box/phlox/
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.7.7
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A gem that generates art based on flocking entities.
|
129
|
+
test_files: []
|