ascii_heart 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ascii_heart.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ # ASCII Heart #
2
+ <h2><font color="red">♥</font></h2>
3
+ ASCII Heart is a for-fun project I created for _why day that draws an ASCII art heart. It has one method that takes the size of the heart to draw. It has no business value, no tests, and is minimally commented. I based the algorithm on the formulas defined here <http://www.mathematische-basteleien.de/heart.htm>.
4
+
5
+ ## Showing the love ##
6
+ gem install 'ascii_heart'
7
+ ascii_heart 20
8
+
9
+ @@@@@@@@@ @@@@@@@@@
10
+ @@@@@@@@@@@@@ @@@@@@@@@@@@@
11
+ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@
12
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
13
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
14
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
15
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
16
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
17
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
18
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
19
+ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
20
+ @@@@@@@@@@@@@@@@@@@@@@@@@@
21
+ @@@@@@@@@@@@@@@@@@@@@@
22
+ @@@@@@@@@@@@@@@@@@@@
23
+ @@@@@@@@@@@@@@@@
24
+ @@@@@@@@@@@@
25
+ @@@@@@@@@@
26
+ @@@@@@
27
+ @@
28
+
29
+ ascii_heart 10
30
+
31
+ @@@@@@@ @@@@@@@
32
+ @@@@@@@@@@@@@@@@@@
33
+ @@@@@@@@@@@@@@@@@@
34
+ @@@@@@@@@@@@@@@@@@
35
+ @@@@@@@@@@@@@@@@
36
+ @@@@@@@@@@@@
37
+ @@@@@@@@@@
38
+ @@@@@@
39
+ @@
40
+
41
+ ascii_heart 1
42
+
43
+
44
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ascii_heart/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ascii_heart"
7
+ s.version = AsciiHeart::VERSION
8
+ s.authors = ["Jason Gilman"]
9
+ s.email = ["jason.gilman@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A module that will draw an ASCII art heart.}
12
+ s.description = %q{My (late) contribution to _why day. Defines a module and executable that will draw an ASCII art heart.}
13
+
14
+ s.rubyforge_project = "ascii_heart"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
+ require 'ascii_heart'
4
+ include AsciiHeart
5
+
6
+ bad_input = lambda do
7
+ puts "Bad input. Takes one argument of size"
8
+ exit(false)
9
+ end
10
+
11
+ if ARGV.size != 1
12
+ bad_input.call
13
+ end
14
+ begin
15
+ size = Integer(ARGV[0])
16
+ rescue => e
17
+ bad_input.call
18
+ end
19
+
20
+ puts heart(size)
@@ -0,0 +1,40 @@
1
+ require "ascii_heart/version"
2
+
3
+ # Defines a method that creates an ASCII art heart.
4
+ module AsciiHeart
5
+ include Math
6
+
7
+ RED = "\033[31m"
8
+ HEART = RED + "\u2665"
9
+
10
+ # Returns a string that will look like an heart
11
+ def heart(size)
12
+ return HEART if size < 3
13
+ px = size * 0.5
14
+ py = size * 0.37
15
+ r = size * 0.625
16
+
17
+ y_nums = (1..size).map {|m| m }.reverse
18
+ matrix = y_nums.map do |y|
19
+ (1..size).map do |x|
20
+ if y > size * 0.7
21
+ sqrt( (px - x) ** 2 + (py - y) ** 2 ) < r
22
+ else
23
+ x < 1.7 * y
24
+ end
25
+ end
26
+ end
27
+ matrix[0][0] = false
28
+ matrix[1][0] = false if matrix.size > 1
29
+
30
+ RED + matrix.map do |row|
31
+ row = row.dup.reverse + row.dup
32
+ row = row.map {|b| b ? "@" : " " }
33
+ row[0] = " "
34
+ row[row.size-1] = " "
35
+ row << "\n"
36
+ row.join
37
+ end.join
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ module AsciiHeart
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ascii_heart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Gilman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-20 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: My (late) contribution to _why day. Defines a module and executable
16
+ that will draw an ASCII art heart.
17
+ email:
18
+ - jason.gilman@gmail.com
19
+ executables:
20
+ - ascii_heart
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - .gitignore
25
+ - Gemfile
26
+ - README.markdown
27
+ - Rakefile
28
+ - ascii_heart.gemspec
29
+ - bin/ascii_heart
30
+ - lib/ascii_heart.rb
31
+ - lib/ascii_heart/version.rb
32
+ has_rdoc: true
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: ascii_heart
53
+ rubygems_version: 1.6.2
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: A module that will draw an ASCII art heart.
57
+ test_files: []