p5rb 0.0.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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/lib/p5rb.rb +83 -0
  4. data/p5rb.gemspec +12 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b004484546d4bd943e52db2b0e8863d3e2a7e2ff
4
+ data.tar.gz: 242fcef182c7e183d1a10865d77cb7e9c1f1520b
5
+ SHA512:
6
+ metadata.gz: f1ea54e72cee551327a31ee3a186c7bb70ba1851e9d0eba3dffa246e019127ac4e61ede192a12a6e2195c20d8465d62ab9f4d031387a702bcc21ae695ff0302b
7
+ data.tar.gz: 0a6a027296c6e7381f3a1e470f530d7c9f724059ab4818c3cf972cd0365362d0cc6f83854652416f80a54a6feab21349f3e4104e6fa3908b891eecb22ba588b3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Victor Maslov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/lib/p5rb.rb ADDED
@@ -0,0 +1,83 @@
1
+ module P5
2
+ class << self
3
+ attr_reader :buffer_setup
4
+ attr_reader :buffer_draw
5
+ end
6
+ instance_variable_set :@buffer_setup, []
7
+ instance_variable_set :@buffer_draw, []
8
+
9
+ @buffer = []
10
+ class << self
11
+ def background c
12
+ @buffer.push "background(#{c})"
13
+ end
14
+ def translate x, y
15
+ @buffer.push "translate(#{x}, #{y})"
16
+ end
17
+ def circle x, y, r
18
+ @buffer.push "circle(#{x}, #{y}, #{r})"
19
+ end
20
+ def ellipse *args
21
+ @buffer.push "ellipse(#{args.join ?,})"
22
+ end
23
+ def noStroke
24
+ @buffer.push "noStroke()"
25
+ end
26
+ def fill color, alpha = nil
27
+ @buffer.push "fill(#{color}#{", #{alpha}" if alpha})"
28
+ end
29
+ def rect x, y, w, h, fill: nil
30
+ (@buffer.push "push()"; fill fill) if fill
31
+ @buffer.push "rect(#{x}, #{y}, #{w}, #{h})"
32
+ @buffer.push "pop()" if fill
33
+ end
34
+ def textSize size
35
+ @buffer.push "textSize(#{size})"
36
+ end
37
+ def textAlign *args
38
+ @buffer.push "textAlign(#{args.join ", "})"
39
+ end
40
+ def text text, x, y, fill: nil
41
+ (@buffer.push "push()"; fill fill) if fill
42
+ @buffer.push "text(#{text.inspect}, #{x}, #{y})"
43
+ @buffer.push "pop()" if fill
44
+ end
45
+
46
+ def setup &block
47
+ module_eval &block
48
+ @buffer_setup = @buffer
49
+ @buffer = []
50
+ end
51
+ def draw &block
52
+ module_eval &block
53
+ @buffer_draw = @buffer
54
+ @buffer = []
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ def P5 width, height, &block
61
+ P5.module_eval &block
62
+ <<~HEREDOC
63
+ <html>
64
+ <head>
65
+ <script src="https://github.com/processing/p5.js/releases/download/v1.4.2/p5.min.js"></script>
66
+ <script>
67
+ function setup() {
68
+ createCanvas(#{width}, #{height});
69
+ #{
70
+ P5.buffer_setup.join(";\n").gsub(/^/, ?\s*8)
71
+ }
72
+ }
73
+ function draw() {
74
+ #{
75
+ P5.buffer_draw.join(";\n").gsub(/^/, ?\s*8)
76
+ }
77
+ }
78
+ </script>
79
+ </head>
80
+ <body><main></main></body>
81
+ </html>
82
+ HEREDOC
83
+ end
data/p5rb.gemspec ADDED
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "p5rb"
3
+ spec.version = "0.0.0"
4
+ spec.summary = "Ruby DSL for p5.js"
5
+
6
+ spec.author = "Victor Maslov aka Nakilon"
7
+ spec.email = "nakilon@gmail.com"
8
+ spec.license = "MIT"
9
+ spec.metadata = {"source_code_uri" => "https://github.com/nakilon/p5rb"}
10
+
11
+ spec.files = %w{ LICENSE p5rb.gemspec lib/p5rb.rb }
12
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: p5rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Maslov aka Nakilon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: nakilon@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - lib/p5rb.rb
21
+ - p5rb.gemspec
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ source_code_uri: https://github.com/nakilon/p5rb
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.5.2.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Ruby DSL for p5.js
47
+ test_files: []