rubysketch 0.3.22 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{release.yml → release-gem.yml} +21 -21
  3. data/.github/workflows/tag.yml +35 -0
  4. data/.github/workflows/test.yml +8 -9
  5. data/.github/workflows/utils.rb +55 -0
  6. data/ChangeLog.md +7 -164
  7. data/LICENSE +1 -1
  8. data/README.md +1 -1
  9. data/Rakefile +10 -34
  10. data/RubySketch.podspec +4 -3
  11. data/VERSION +1 -1
  12. data/examples/hello.rb +6 -6
  13. data/lib/rubysketch/all.rb +9 -0
  14. data/lib/rubysketch/context.rb +47 -0
  15. data/lib/rubysketch/{module.rb → extension.rb} +3 -3
  16. data/lib/rubysketch/graphics_context.rb +37 -0
  17. data/lib/rubysketch/helper.rb +5 -0
  18. data/lib/rubysketch/sprite.rb +101 -0
  19. data/lib/rubysketch.rb +30 -12
  20. data/rubysketch.gemspec +15 -8
  21. data/src/{RubySketch.h → RubyProcessing.h} +0 -4
  22. data/src/RubyProcessing.mm +25 -0
  23. data/test/helper.rb +3 -10
  24. data/test/test_sprite.rb +23 -0
  25. metadata +119 -35
  26. data/examples/breakout.rb +0 -212
  27. data/examples/camera.rb +0 -14
  28. data/examples/clock.rb +0 -57
  29. data/examples/delay_camera.rb +0 -33
  30. data/examples/glsl.rb +0 -14
  31. data/examples/image.rb +0 -13
  32. data/examples/shapes.rb +0 -121
  33. data/lib/rubysketch/app.rb +0 -13
  34. data/lib/rubysketch/glsl.rb +0 -44
  35. data/lib/rubysketch/processing.rb +0 -3191
  36. data/lib/rubysketch/window.rb +0 -232
  37. data/lib/rubysketch-glsl.rb +0 -12
  38. data/lib/rubysketch-processing.rb +0 -25
  39. data/src/RubySketch.mm +0 -55
  40. data/test/processing/helper.rb +0 -11
  41. data/test/processing/test_graphics.rb +0 -21
  42. data/test/processing/test_shader.rb +0 -47
  43. data/test/processing/test_utility.rb +0 -41
  44. data/test/processing/test_vector.rb +0 -394
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37319632030509f708c8ee98cbb6e4d8512b50ad7475cae37d595e3649a81c26
4
- data.tar.gz: c61938eefd83489171e8eff04721dfd08edcbae0ecb8472b34c58d1c09afc92a
3
+ metadata.gz: f9cecc3561d81fdd14730fcdbec957edaac4f5366a9777dc24666a529e539b8f
4
+ data.tar.gz: 588f15db62ccb22206347295c352786470c7d0fee1f3ad169763b6779742b94e
5
5
  SHA512:
6
- metadata.gz: e37b6b72fd7d3960434d47b302aec206332e85476a7e2cde3d4f56fd8b8946de685c27fc39d06094ddb0203141ba8282a2b521281218dd25970fceb18e80a83f
7
- data.tar.gz: 9c65761f2df604c2c79b30ccc5c6b23403d7aae5f2ea6858b62979b825d66ef1d54a9106ad37b4dfd5902697a91bd47c0c034e6fd21c93fe1593a58642fb20eb
6
+ metadata.gz: 379b68cba8c0d8323107092cadccf4cd9ccecb4608036ecac5cb34bf57f531f6e23a18d75aaf9f2dcb2da2da2018d04c182737d919455556204f784b906e9af1
7
+ data.tar.gz: f6427af7756e26b3394458c1701c59ff398dc31fac0faaf03b6f9aa7a4da1eb4c4b9db11121f4d000a7089aad63bffb38f004661e6c723402ab9ad1b52dfce3e
@@ -1,4 +1,4 @@
1
- name: Release
1
+ name: Release Gem
2
2
 
3
3
  on:
4
4
  push:
@@ -9,46 +9,46 @@ jobs:
9
9
  runs-on: macos-latest
10
10
 
11
11
  steps:
12
+ - name: ruby 3.2
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 3.2
16
+
12
17
  - name: checkout
13
18
  uses: actions/checkout@v2
14
19
 
15
- - name: ruby 3.0
16
- uses: actions/setup-ruby@v1
17
- with:
18
- ruby-version: 3.0.x
20
+ - name: setup dependencies
21
+ run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
19
22
 
20
23
  - name: install gems
21
- run: |
22
- gem install bundler
23
- bundle install --jobs 4 --retry 3
24
+ run: gem install yard
24
25
 
25
- - name: version
26
- id: version
27
- run: |
28
- echo ::set-output name=value::$(ruby -e 'print "${{ github.ref }}"[/\/v([\w\.\-]+)/, 1]')
26
+ - name: test
27
+ run: rake test
29
28
 
30
29
  - name: create gem
31
- run: rake clean gem
30
+ id: gem
31
+ run: |
32
+ rake gem
33
+ echo path=$(ruby -e 'print Dir.glob("*.gem").first') >> $GITHUB_OUTPUT
32
34
 
33
- - name: create release
34
- id: create_release
35
+ - name: create github release
36
+ id: release
35
37
  uses: actions/create-release@v1
36
38
  env:
37
39
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38
40
  with:
39
41
  tag_name: ${{ github.ref }}
40
42
  release_name: ${{ github.ref }}
41
- draft: false
42
- prerelease: false
43
43
 
44
- - name: upload to releases
44
+ - name: upload to github release
45
45
  uses: actions/upload-release-asset@v1
46
46
  env:
47
47
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48
48
  with:
49
- upload_url: ${{ steps.create_release.outputs.upload_url }}
50
- asset_path: ./rubysketch-${{ steps.version.outputs.value }}.gem
51
- asset_name: rubysketch-${{ steps.version.outputs.value }}.gem
49
+ upload_url: ${{ steps.release.outputs.upload_url }}
50
+ asset_path: ./${{ steps.gem.outputs.path }}
51
+ asset_name: ${{ steps.gem.outputs.path }}
52
52
  asset_content_type: application/zip
53
53
 
54
54
  - name: upload to rubygems
@@ -0,0 +1,35 @@
1
+ name: Tag
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ jobs:
8
+ tag:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: ruby 3.2
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 3.2
16
+
17
+ - name: checkout
18
+ uses: actions/checkout@v2
19
+ with:
20
+ fetch-depth: 0
21
+ token: ${{ secrets.PAT }}
22
+
23
+ - name: setup dependencies
24
+ run: "ruby -I.github/workflows -rutils -e 'setup_dependencies only: :xot'"
25
+
26
+ - name: setup user name and email
27
+ run: |
28
+ git config --global user.email "xordog@gmail.com"
29
+ git config --global user.name "xord"
30
+
31
+ - name: tag versions
32
+ run: "ruby -I.github/workflows -rutils -e 'tag_versions'"
33
+
34
+ - name: push tags
35
+ run: git push origin --tags
@@ -11,17 +11,16 @@ jobs:
11
11
  runs-on: macos-latest
12
12
 
13
13
  steps:
14
- - uses: actions/checkout@v2
15
-
16
- - name: ruby 3.0
17
- uses: actions/setup-ruby@v1
14
+ - name: ruby 3.2
15
+ uses: ruby/setup-ruby@v1
18
16
  with:
19
- ruby-version: 3.0.x
17
+ ruby-version: 3.2
18
+
19
+ - name: checkout
20
+ uses: actions/checkout@v2
20
21
 
21
- - name: install gems
22
- run: |
23
- gem install bundler
24
- bundle install --jobs 4 --retry 3
22
+ - name: setup dependencies
23
+ run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
25
24
 
26
25
  - name: test
27
26
  run: rake test
@@ -0,0 +1,55 @@
1
+ RENAMES = {reflex: 'reflexion'}
2
+
3
+ def sh(cmd)
4
+ puts cmd
5
+ system cmd
6
+ end
7
+
8
+ def setup_dependencies(build: true, only: nil)
9
+ gemspec_path = `git ls-files`.lines(chomp: true).find {|l| l =~ /\.gemspec$/}
10
+ return unless gemspec_path
11
+
12
+ gemspec = File.read gemspec_path
13
+ name = File.basename gemspec_path, '.gemspec'
14
+
15
+ exts = File.readlines('Rakefile')
16
+ .map {|l| l[%r|^\s*require\W+(\w+)/extension\W+$|, 1]}
17
+ .compact
18
+ .reject {|ext| ext == name}
19
+ exts = exts & [only].flatten.map(&:to_s) if only
20
+
21
+ exts.each do |ext|
22
+ gem = RENAMES[ext.to_sym].then {|s| s || ext}
23
+ clone = "git clone --depth 1 https://github.com/xord/#{ext}.git ../#{ext}"
24
+ ver = gemspec[/add_runtime_dependency.*['"]#{gem}['"].*['"]\s*~>\s*([\d\.]+)\s*['"]/, 1]
25
+
26
+ # 'rake subtree:push' pushes all subrepos, so cloning by new tag
27
+ # often fails before tagging each new tag
28
+ sh %( #{clone} --branch v#{ver} || #{clone} )
29
+ sh %( cd ../#{ext} && rake ext )
30
+ end
31
+ end
32
+
33
+ def tag_versions()
34
+ tags = `git tag`.lines chomp: true
35
+ vers = `git log --oneline ./VERSION`
36
+ .lines(chomp: true)
37
+ .map {|line| line.split.first[/^\w+$/]}
38
+ .map {|hash| [`git cat-file -p #{hash}:./VERSION 2>/dev/null`[/[\d\.]+/], hash]}
39
+ .select {|ver, hash| ver && hash}
40
+ .reverse
41
+ .to_h
42
+
43
+ changes = File.read('ChangeLog.md')
44
+ .split(/^\s*##\s*\[\s*v([\d\.]+)\s*\].*$/)
45
+ .slice(1..-1)
46
+ .each_slice(2)
47
+ .to_h
48
+ .transform_values(&:strip!)
49
+
50
+ vers.to_a.reverse.each do |ver, hash|
51
+ tag = "v#{ver}"
52
+ break if tags.include?(tag)
53
+ sh %( git tag -a -m \"#{changes[ver]&.gsub '"', '\\"'}\" #{tag} #{hash} )
54
+ end
55
+ end
data/ChangeLog.md CHANGED
@@ -1,173 +1,16 @@
1
- # RubySketch ChangeLog
1
+ # rubysketch ChangeLog
2
2
 
3
3
 
4
- ## [0.3.22] - 2022-11-14
4
+ ## [v0.5.1] - 2023-03-01
5
5
 
6
- RubySketch::Processing
7
- - add Shader class
8
- - add shader(), resetShader(), createShader(), loadShader(), and filter()
9
- - update the pixel density of context if the screen pixel density is changed
10
- - setUniform() can also take array of numbers, vector, and texture image.
11
- - pushStyle() manages states of textAlign, tint, and filter
12
- - push/pushMatrix/pushStyle call pop() on ensure
6
+ - fix bugs
13
7
 
14
- RubySketch::GLSL
15
- - displays with pixel density 1.0
16
8
 
9
+ ## [v0.5.0] - 2023-02-09
17
10
 
18
- ## [0.3.21] - 2022-09-05
11
+ - add Sprite class
19
12
 
20
- - add rubysketch-glsl.rb
21
- - add blend(), createImage(), setTitle(), tint() and noTint()
22
- - add save() that saves screen image to file
23
- - circle() function is affected by ellipseMode()
24
- - point() draws by line(x, y, x, y)
25
- - change initial values for strokeCap and strokeJoin to ROUND and MITER
26
13
 
14
+ ## [v0.4.0] - 2023-02-08
27
15
 
28
- ## [0.3.20] - 2022-07-24
29
-
30
- - add mouseClicked()
31
- - add blendMode()
32
- - add clip() and noClip()
33
- - translate() can take 'z' parameter
34
- - fix that resizing canvas consumes too much memory
35
-
36
-
37
- ## [0.3.19] - 2021-12-5
38
-
39
- - fix runtime error
40
-
41
-
42
- ## [0.3.18] - 2021-12-5
43
-
44
- - add 'mouseButton'
45
- - pointer cancel event calls pointer_up block
46
-
47
-
48
- ## [0.3.17] - 2021-12-5
49
-
50
- - add Touch#id
51
-
52
-
53
- ## [0.3.16] - 2021-2-14
54
-
55
- - add key, keyCode and keyPressed system values
56
- - add keyPressed(), keyReleased() and keyTyped() functions
57
- - add motionGravity value and motion() function
58
-
59
-
60
- ## [0.3.15] - 2020-12-12
61
-
62
- - delete temporary directory on launch
63
-
64
-
65
- ## [0.3.14] - 2020-12-12
66
-
67
- - fix loadImage() fails when Encoding.default_internal is not nil
68
-
69
-
70
- ## [0.3.13] - 2020-12-12
71
-
72
- - size(), createCanvas(): default pixelDensity is same as current value
73
-
74
-
75
- ## [0.3.12] - 2020-12-10
76
-
77
- - size() and createCanvas() take 'pixelDensity' parameter and default value is 1
78
-
79
-
80
- ## [0.3.11] - 2020-12-9
81
-
82
- - add size(), createCanvas() and pixelDensity()
83
-
84
-
85
- ## [0.3.10] - 2020-12-1
86
-
87
- - invert angle parameter value for arc() to fix compatibility to processing API
88
-
89
-
90
- ## [0.3.9] - 2020-11-30
91
-
92
- - Graphics#beginDraw() can take block to call endDraw automatically
93
- - Capture#start() always returns nil
94
- - add delay_camera.rb
95
-
96
-
97
- ## [0.3.8] - 2020-11-27
98
-
99
- - Capture#initialize() can take requestWidth, requestHeight and cameraName
100
- - add Capture#width and Capture#height
101
-
102
-
103
- ## [0.3.7] - 2020-11-18
104
-
105
- - add Capture class
106
- - add log(), exp(), sqrt() and PI
107
- - add examples/camera.rb
108
- - add examples/breakout.rb
109
- - fix error on calling image()
110
-
111
-
112
- ## [0.3.6] - 2020-08-02
113
-
114
- - random() can take array or nothing
115
- - use github actions to release gem package
116
-
117
-
118
- ## [0.3.5] - 2020-08-02
119
-
120
- - add random()
121
- - add sin(), cos(), tan(), asin(), acos(), atan() and atan2()
122
- - make Vector class accessible from user script context
123
- - fix error on calling rotate()
124
-
125
-
126
- ## [0.3.4] - 2020-08-02
127
-
128
- - delete Utility module
129
-
130
-
131
- ## [0.3.3] - 2020-08-01
132
-
133
- - add Vector class
134
-
135
-
136
- ## [0.3.2] - 2020-07-22
137
-
138
- - text() draws to the baseline by default
139
- - add textWidth(), textAscent(), textDescent() and textAlign()
140
- - change initial color for fill() and stroke()
141
- - change initial background color to grayscale 0.8
142
-
143
-
144
- ## [0.3.1] - 2020-07-17
145
-
146
- - add touchStarted(), touchEnded(), touchMoved() and touches()
147
- - make all event handler drawable
148
- - limit font max size to 256
149
-
150
-
151
- ## [0.3.0] - 2020-05-21
152
-
153
- - add createGraphics()
154
-
155
-
156
- ## [0.2.7] - 2020-04-17
157
-
158
- - add strokeCap() and strokeJoin()
159
-
160
-
161
- ## [0.2.6] - 2020-04-17
162
-
163
- - push(), pushMatrix() and pushStyle() take block to automatic pop
164
- - refine startup process
165
- - add curve() and bezier()
166
- - add imageMode(), Image#resize(), Image#copy() and copy()
167
- - add loop(), noLoop() and redraw()
168
-
169
-
170
- ## [0.2.5] - 2020-03-29
171
-
172
- - delete debug prints
173
- - show unsupported image type
16
+ - first version
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 xord.org
3
+ Copyright (c) 2023 xord.org
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RubySketch - Processing compatible Creative Coding Framework
1
+ # RubySketch - A game engine based on the Processing API
2
2
 
3
3
  by xordog@gmail.com
4
4
 
data/Rakefile CHANGED
@@ -1,50 +1,26 @@
1
1
  # -*- mode: ruby -*-
2
2
 
3
3
 
4
- %w[../xot ../rucy ../rays ../reflex .]
4
+ %w[../xot ../rucy ../beeps ../rays ../reflex ../processing .]
5
5
  .map {|s| File.expand_path "#{s}/lib", __dir__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
8
  require 'rucy/rake'
9
9
 
10
- require 'xot/module'
11
- require 'rucy/module'
12
- require 'rays/module'
13
- require 'reflex/module'
14
- require 'rubysketch/module'
10
+ require 'xot/extension'
11
+ require 'rucy/extension'
12
+ require 'beeps/extension'
13
+ require 'rays/extension'
14
+ require 'reflex/extension'
15
+ require 'processing/extension'
16
+ require 'rubysketch/extension'
15
17
 
16
18
 
17
- MODULES = [Xot, Rucy, Rays, Reflex, RubySketch]
19
+ EXTENSIONS = [Xot, Rucy, Beeps, Rays, Reflex, Processing, RubySketch]
18
20
 
19
21
  ENV['RDOC'] = 'yardoc --no-private'
20
22
 
23
+ default_tasks
21
24
  test_ruby_extension
22
25
  generate_documents
23
26
  build_ruby_gem
24
-
25
- task :default
26
-
27
-
28
- namespace :version do
29
-
30
- namespace :bump do
31
-
32
- task :major do
33
- update_and_tag_version 0
34
- end
35
-
36
- task :minor do
37
- update_and_tag_version 1
38
- end
39
-
40
- task :patch do
41
- update_and_tag_version 2
42
- end
43
-
44
- task :build do
45
- update_and_tag_version 3
46
- end
47
-
48
- end# bump
49
-
50
- end# version
data/RubySketch.podspec CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  Pod::Spec.new do |s|
5
5
  s.name = "RubySketch"
6
- s.version = File.readlines(File.expand_path 'VERSION', __dir__)[0].chomp
7
- s.summary = "Yet Another Processing implementation for Ruby"
8
- s.description = "Yet Another Processing implementation for Ruby"
6
+ s.version = File.read(File.expand_path 'VERSION', __dir__)[/[\d\.]+/]
7
+ s.summary = "A game engine based on the Processing API"
8
+ s.description = "A game engine based on the Processing API"
9
9
  s.license = "MIT"
10
10
  s.source = {:git => "https://github.com/xord/rubysketch.git"}
11
11
  s.author = {"xordog" => "xordog@gmail.com"}
@@ -18,6 +18,7 @@ Pod::Spec.new do |s|
18
18
  #{s.name}/src
19
19
  CRuby/CRuby/include
20
20
  Reflexion/reflex/include
21
+ RubyProcessing/src
21
22
  ].map {|s| "${PODS_ROOT}/#{s}"}
22
23
 
23
24
  s.preserve_paths = "src"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.22
1
+ 0.5.1
data/examples/hello.rb CHANGED
@@ -1,12 +1,12 @@
1
- %w[xot rays reflex rubysketch]
1
+ %w[xot rays reflex processing rubysketch]
2
2
  .map {|s| File.expand_path "../../#{s}/lib", __dir__}
3
3
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
4
4
 
5
- require 'rubysketch-processing'
6
-
5
+ require 'rubysketch'
6
+ using RubySketch
7
7
 
8
8
  draw do
9
- background 0, 10
10
- textSize 50
11
- text 'hello, world!', mouseX, mouseY
9
+ background 0
10
+ textSize 30
11
+ text "hello, rubysketch!", 10, 100
12
12
  end
@@ -0,0 +1,9 @@
1
+ require 'forwardable'
2
+ require 'processing/all'
3
+
4
+ require 'rubysketch/extension'
5
+ require 'rubysketch/helper'
6
+
7
+ require 'rubysketch/sprite'
8
+ require 'rubysketch/graphics_context'
9
+ require 'rubysketch/context'
@@ -0,0 +1,47 @@
1
+ module RubySketch
2
+
3
+
4
+ class Context < Processing::Context
5
+
6
+ include GraphicsContext
7
+
8
+ def initialize(window)
9
+ super
10
+ @sprites__ = window.add SpritesView.new
11
+ end
12
+
13
+ def createSprite(*args, **kwargs)
14
+ addSprite Sprite.new(*args, **kwargs)
15
+ end
16
+
17
+ def addSprite(sprite)
18
+ @sprites__.add sprite.getInternal__ if sprite
19
+ sprite
20
+ end
21
+
22
+ def removeSprite(sprite)
23
+ @sprites__.remove sprite.getInternal__ if sprite
24
+ sprite
25
+ end
26
+
27
+ def gravity(*args)
28
+ x, y =
29
+ case args
30
+ when Processing::Vector then args.array
31
+ else args
32
+ end
33
+ @sprites__.then do |v|
34
+ v.gravity x * v.meter, y * v.meter
35
+ end
36
+ end
37
+
38
+ class SpritesView < Reflex::View
39
+ def on_draw(e)
40
+ e.block
41
+ end
42
+ end
43
+
44
+ end# Context
45
+
46
+
47
+ end# RubySketch
@@ -1,7 +1,7 @@
1
1
  module RubySketch
2
2
 
3
3
 
4
- module Module
4
+ module Extension
5
5
 
6
6
  module_function
7
7
 
@@ -10,14 +10,14 @@ module RubySketch
10
10
  end
11
11
 
12
12
  def version()
13
- open(root_dir 'VERSION') {|f| f.readline.chomp}
13
+ File.read(root_dir 'VERSION')[/[\d\.]+/]
14
14
  end
15
15
 
16
16
  def root_dir(path = '')
17
17
  File.expand_path "../../#{path}", __dir__
18
18
  end
19
19
 
20
- end# Module
20
+ end# Extension
21
21
 
22
22
 
23
23
  end# RubySketch
@@ -0,0 +1,37 @@
1
+ module RubySketch
2
+
3
+
4
+ module GraphicsContext
5
+
6
+ def sprite(*sprites)
7
+ sprites.flatten! if sprites.first&.is_a? Array
8
+ sprites.each do |sp|
9
+ v = sp.getInternal__
10
+ f, angle, img, offset = v.frame, v.angle, sp.image, sp.offset
11
+ if angle == 0
12
+ drawSprite__ f.x, f.y, f.w, f.h, img, offset
13
+ else
14
+ pushMatrix do
15
+ translate f.x, f.y
16
+ rotate radians(angle)
17
+ drawSprite__ 0, 0, f.w, f.h, img, offset
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def drawSprite__(x, y, w, h, img, offset)
24
+ if img && offset
25
+ ox, oy = offset
26
+ copy img, ox, oy, w, h, x, y, w, h
27
+ elsif img
28
+ image img, x, y
29
+ else
30
+ rect x, y, w, h
31
+ end
32
+ end
33
+
34
+ end# GraphicsContext
35
+
36
+
37
+ end# RubySketch
@@ -0,0 +1,5 @@
1
+ class Rays::Point
2
+ def toVector()
3
+ Processing::Vector.new x, y, z
4
+ end
5
+ end