Class: Chem::SWFWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/chem/db/swf.rb

Overview

Flash SWF writer Obsolete

Instance Method Summary collapse

Constructor Details

#initialize(mol) ⇒ SWFWriter

Returns a new instance of SWFWriter.



15
16
17
18
19
20
21
22
23
24
# File 'lib/chem/db/swf.rb', line 15

def initialize mol
  @m = SWFMovie.new
  @m.set_rate(5.0)
  @m.set_dimension(1000, 1000)
  @m.set_background(0xff, 0xff, 0xff)
  #    @m.add(make_atom(mol))
  0.upto(200) do |n|
    rotate(Math::PI * 0.01 * n, mol)
  end
end

Instance Method Details

#make_atom(mol) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chem/db/swf.rb', line 37

def make_atom mol
  a = SWFText.new
  f = SWFFont.new("EfontSerifB.fdb")
  a.set_font(f)
  a.set_color(0x00, 0x80, 0x40)
  height = 28
  a.set_height(height * 2)
  mol.atoms.each do |atom|
    a.move_to(atom.pos[0] - height, atom.pos[1] + height)
    a.add_string(atom.element)
  end
  a
end

#make_bond(mol) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/chem/db/swf.rb', line 51

def make_bond mol
  s = SWFShape.new
  mol.bonds.each do |bond|

    s.set_line(1, 0x0, 0, 0)
    s.move_pen_to(bond.b.pos[0], bond.b.pos[1])
    s.draw_line_to(bond.e.pos[0], bond.e.pos[1])
  end
  s
end

#rotate(n, mol) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/chem/db/swf.rb', line 26

def rotate n, mol
  t = Transform.translate(500.0, 500.0, 0) * Transform.scale(100, 100, 10) *
    Transform.rotate_z(n) * Transform.rotate_x(n)
  mol.transform(t)
  ib = @m.add(make_bond(mol))
  #    ia = @m.add(make_atom(mol))
  @m.next_frame
  @m.remove(ib)
  #    @m.remove(ia)
end

#save(fn) ⇒ Object



62
63
64
# File 'lib/chem/db/swf.rb', line 62

def save fn
  @m.save(fn)
end