15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/p5rb_cli.rb', line 15
def new(name)
name += ".rb" unless name.end_with?(".rb")
if FileTest.exist?(name)
raise Thor::Error, "ERROR: '#{File.absolute_path(name)}' already exists"
end
File.write(name, " # p5.rb - A Ruby implementation of p5.js\n #\n # This library allows you to create sketches using Ruby, similar to p5.js.\n # \n # - Define `setup` and `draw` method to create a sketch.\n # - API is compatible with p5.js.\n # - API naming follows PascalCase for consistency with p5.js.\n #\n # Example:\n # def setup\n # createCanvas(400, 400)\n # end\n #\n # def draw\n # background(220)\n # ellipse(200, 200, 50, 50)\n # end\n #\n # --- Major Methods ---\n #\n # - createCanvas(width, height) -> Creates a drawing canvas.\n # - background(color) -> Sets the background color.\n # - fill(color) -> Sets the fill color for shapes.\n # - stroke(color) -> Sets the outline color for shapes.\n # - noStroke() -> Disables shape outlines.\n # - ellipse(x, y, w, h) -> Draws an ellipse at (x, y) with width w and height h.\n # - rect(x, y, w, h) -> Draws a rectangle at (x, y) with width w and height h.\n # - line(x1, y1, x2, y2) -> Draws a line from (x1, y1) to (x2, y2).\n # - text(str, x, y) -> Draws text at (x, y).\n # - push() -> Saves the current drawing state (transformation, styles, etc.).\n # - pop() -> Restores the last saved drawing state.\n # - width, height -> Returns the canvas dimensions.\n # - frameCount -> Returns the number of frames elapsed.\n # - mouseX, mouseY -> Returns the current mouse position.\n # - keyPressed? -> Returns true if a key is pressed.\n # - mousePressed? -> Returns true if the mouse button is pressed. \n\n def setup\n createCanvas(400, 400)\n background(200)\n end\n\n def draw\n background(200)\n (0..width).step(50) do |x|\n (0..height).step(50) do |y|\n ellipse(x, y, 40, 40)\n end\n end\n end\n CODE\nend\n")
|