Skip to content

Commit 49e017f

Browse files
committed
grid method
1 parent 55b5b93 commit 49e017f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: post
3+
title: "Using JRubyArt grid method"
4+
date: 2019-03-01 12:58:08 +0000
5+
categories: vecmath update
6+
---
7+
8+
# Example Usage
9+
10+
```ruby
11+
# ===== Default : Default
12+
GEM_HOME = '/home/tux/.gem/ruby/2.6.0'
13+
require 'vecmath'
14+
15+
rect_mode(CORNER)
16+
no_stroke
17+
frame_rate(1) # set the frame rate to 1 draw call per second
18+
19+
def draw
20+
background(180) # clear the screen to grey
21+
grid_size = 5 # rand(3..12) # select a rand number of squares each frame
22+
gap = 5 # rand(5..50) # select a rand gap between each square
23+
# calculate the size of each square for the given number of squares and gap between them
24+
cellsize = (width - (grid_size + 1) * gap) / grid_size
25+
position = -> (count) { gap * (count + 1) + cellsize * count + rand(-5..5) }
26+
grid(grid_size, grid_size) do |x, y|
27+
rand(0..5) > 4 ? fill(color('#a11220'), 180.0) : fill(color('#884444'), 180.0)
28+
rect(position.call(x), position.call(y), cellsize, cellsize)
29+
end
30+
end
31+
32+
```

0 commit comments

Comments
 (0)