Top Level Namespace

Defined Under Namespace

Modules: P5

Instance Method Summary collapse

Instance Method Details

#P5(width, height, &block) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/p5rb.rb', line 178

def P5 width, height, &block
  ::P5.module_eval &block
  <<~HEREDOC
    <html>
      <head>
        <meta charset="UTF-8">
        <script src="https://github.com/processing/p5.js/releases/download/v1.4.2/p5.min.js"></script>
        <script>
          function setup() {
            createCanvas(#{width}, #{height});
#{
  ::P5.buffer_setup.join(";\n").gsub(/^/, ?\s*12)
}
          }
          function draw() {
#{
  ::P5.buffer_draw.join(";\n").gsub(/^/, ?\s*12)
}
          }
        </script>
      </head>
      <body style="margin: 0"><main></main></body>
    </html>
  HEREDOC
end