Skip to content

Commit

Permalink
Fix odd proportions in Spriter generate
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Dec 20, 2023
1 parent a04faf5 commit 6effa21
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Spriter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def generate(mx = 0, my = 0, falloff = :cosine, probmin = 10, probmax = 75, clea
mirror_y = rand(101) <= my
range_x = @width >> 1
range_y = @height >> 1
limit_x = mirror_x ? range_x : @width
limit_y = mirror_y ? range_y : @height
limit_x = mirror_x ? @width - range_x : @width
limit_y = mirror_y ? @height - range_y : @height
# Draw
index_y = 0
falloff_x = Array.new(limit_x) {|x| send(falloff, range_x, x)}
Expand Down Expand Up @@ -136,22 +136,23 @@ def generate(mx = 0, my = 0, falloff = :cosine, probmin = 10, probmax = 75, clea
# Mirror
if mirror_y
index_y = 0
mirror_y = @width * @height.pred
mirror_y = -@width
if mirror_x
limit_y.times {
@grid[index_y + range_x, range_x] = @grid[index_y, range_x].reverse!
@grid[index_y + limit_x, range_x] = @grid[index_y, range_x].reverse!
@grid[mirror_y - index_y, @width] = @grid[index_y, @width]
index_y += @width
}
else
limit_y.times {
range_y.times {
@grid[mirror_y - index_y, @width] = @grid[index_y, @width]
index_y += @width
}
end
elsif mirror_x
mirror_x = limit_x
limit_y.times {
@grid[limit_x, range_x] = @grid[limit_x - range_x, range_x].reverse!
@grid[limit_x, range_x] = @grid[limit_x - mirror_x, range_x].reverse!
limit_x += @width
}
end
Expand Down

0 comments on commit 6effa21

Please sign in to comment.