Class: AppMath::Graphs

Inherits:
Object
  • Object
show all
Defined in:
lib/graph.rb

Overview

The code

root = TkRoot.new{ title 'Test of ...'}
g = Graphs.new(root,3,2,1000,700)

generates a 2 times 3 matrix of Graph-objects

g.at(0,0), g.at(0,1), g.at(0,2)
g.at(1,0), g.at(1,1), g.at(1,2)

which together make up a rectangle of 1000 pixels in x-direction and 700 pixels in y-direction. Notice that the matrix is a grid with 3 items in x-direction and 2 items in y-direction. Since these items are of class Graph, they can be used for graphical representations of arrays and of functions without needing support fom the present class Graphs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, px, py, nx, ny) ⇒ Graphs

Generating a (py,px)-matrix of Graph-objects, in an rectangular area which is a (ny,nx)-matrix of pixels.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/graph.rb', line 257

def initialize(parent,px,py,nx,ny)
  zero = R.c0
  one = R.c1
  @px = px
  @py = py
  @mx = nx / @px
  @my = ny / @py
  ivx = Iv.new(zero,one)
  ivy = Iv.new(zero,one)
  @grs = Array.new
  py.times{ |r|
    gr = Array.new
    px.times{ |c|
      fr = TkFrame.new(parent).grid('row' => r, 'column' => c)
      gr << Graph.new(fr,@mx,@my,ivx,ivy)
    }
    @grs << gr
  }
end

Instance Attribute Details

#grsObject (readonly)

Returns the value of attribute grs.



253
254
255
# File 'lib/graph.rb', line 253

def grs
  @grs
end

#mxObject (readonly)

Returns the value of attribute mx.



253
254
255
# File 'lib/graph.rb', line 253

def mx
  @mx
end

#myObject (readonly)

Returns the value of attribute my.



253
254
255
# File 'lib/graph.rb', line 253

def my
  @my
end

#pxObject (readonly)

Returns the value of attribute px.



253
254
255
# File 'lib/graph.rb', line 253

def px
  @px
end

#pyObject (readonly)

Returns the value of attribute py.



253
254
255
# File 'lib/graph.rb', line 253

def py
  @py
end

Instance Method Details

#at(i, j) ⇒ Object

Access function. For a Graphs-object g, one has the Graph-objects

g.at(i,j), 0 <= i < p.py, 0 <= j < g.px .

All integer values are allowed and these then are understood periodically.



281
282
283
# File 'lib/graph.rb', line 281

def at(i,j)
  return @grs[i.to_i%@py][j.to_i%@px]
end