forked from huangqiangsheng/Ruby_mask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatamap.rb
More file actions
83 lines (64 loc) · 1.66 KB
/
datamap.rb
File metadata and controls
83 lines (64 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
75
76
77
78
79
80
81
82
# Enter your Ruby code here
app = RBA::Application.instance
mw = app.main_window
# create a new layout
mw.create_layout( 0 )
view = mw.current_view
# create a new layer in that layout
layout = view.cellview( 0 ).layout
layer_ids = []
256.times { |l|
linfo = RBA::LayerInfo.new
layer_id = layout.insert_layer( linfo )
# create a layer view for that layer
ln = RBA::LayerPropertiesNode::new
ln.dither_pattern = 0
if l >= 128
# red colors for the positive values
c = (l - 128) * 2 * 0x10000
elsif l > 0
# blue colors for the negative values
c = (128 - l) * 2
else
c = 0xff
end
ln.fill_color = c
ln.frame_color = c
ln.width = 1
ln.source_layer_index = layer_id
view.insert_layer( view.end_layers, ln )
layer_ids.push( layer_id )
}
# replicate last layer to allow values of 256 (mapped to 255) ..
layer_ids.push( layer_ids[255] )
# create a top cell and start the recursion on this
topcell_id = layout.add_cell( "top" )
topcell = layout.cell( topcell_id )
# create an image
nx = 500
ny = 500
radius = 100
x = -nx / 2
nx.times {
y = -ny / 2
ny.times {
r = Math::sqrt( x * x + y * y ) * Math::PI * 2.0 / radius
if r.abs < 1e-6
v = 1.0
else
v = Math::sin( r ) / r
end
vi = ((v + 1.0) * 128.0 + 0.5).to_i
box = RBA::Box::new_lbrt( x * 100, y * 100, (x + 1) * 100, (y + 1) * 100 )
topcell.shapes( layer_ids[vi] ).insert_box( box )
y += 1
}
x += 1
}
# select his cell as the top cell, fit all and switch on all hierarchy levels
view.select_cell_path( [topcell_id], 0 )
view.update_content
view.zoom_fit
view.max_hier
# run the application
RBA::Application.instance.exec