1.LineDemo
-------------------------------------------------------------------------
require "tkclass"

#テキストを配置

TkLabel.new{
   text "Line Demo      T.Tarui\n"
   pack
}
 

$c = Canvas.new                    #キャンバスの初期化
$c.pack

$c.width 500
$c.background "darkgreen"

Line.new($c,100,100,300,200)           # 直線
Line.new($c,300,200,400,100)           # 直線
Oval.new($c,100,100,200,200)           # 円(楕円)
Rectangle.new($c,200,100,300,200)   # 正方形(長方形)
Tk.mainloop
--------------------------------------------------------------------------

 

2.Color Demo
-------------------------------------------------------------------------
require "tkclass"

TkLabel.new{
   text "Color Demo      T.Tarui\nRuby\n"
   pack
}
 

canvas = TkCanvas.new

canvas.background "darkgreen"
canvas.width 600

TkcRectangle.new(canvas, '1c', '2c', '3c', '3c','outline' => 'black', 'fill' => 'LightBlue')

TkcRectangle.new(canvas,10,10,50,50,'outline' => 'black', 'fill' => 'Yellow')
TkcLine.new(canvas,100,100,300,200,'fill' => 'red')

canvas.pack
Tk.mainloop
-------------------------------------------------------------------------

 

3.Cycloid Demo
-------------------------------------------------------------------------
#########################################
# Cycloid Demo      Dec.10 2000 T.Tarui #
#########################################

require "tkclass"

# ラベル

TkLabel.new {
   text "Cycloid Demo      T.Tarui\n"+"r=50"
   pack
}

# サイクロイド描画

r=50

$c = Canvas.new
$c.pack

$c.width 400

Line.new($c,0,200,400,200)
Line.new($c,20,0,20,400)

x0=0
y0=0

for i in 1..360

  x=r*(3.14*i/180-Math.sin(3.14*i/180))
  y=r*(1-Math.cos(3.14*i/180))

    Line.new($c,x0+20,200-y0,x+20,200-y);

  x0=x
  y0=y

end

# Quitボタン

TkButton.new {
 text 'Quit'
  command proc{
    exit
  }
 pack('side'=>'bottom')
}

Tk.mainloop
-------------------------------------------------------------------------

 

4.Trocoid Demo
-------------------------------------------------------------------------
#########################################
# Trocoid Demo     Dec.10 2000 T.Tarui #
#########################################

require "tkclass"

# ラベル

TkLabel.new {
   text "Trocoid Demo      T.Tarui\n"+"r=50 "
   pack
}

# 描画領域作成

$r=50

$c = Canvas.new
$c.pack

$c.width 600

Line.new($c,0,200,600,200)
Line.new($c,20,0,20,500)
 

# ボタン

TkButton.new {
 text 'd=0'
  command proc{
    $d=0
    prot
  }
 pack('side'=>'left')
}

TkButton.new {
 text 'd=10'
  command proc{
    $d=10
    prot
  }
 pack('side'=>'left')
}
 

TkButton.new {
 text 'd=20'
  command proc{
    $d=20
    prot
 }
 pack('side'=>'left')
}
 

TkButton.new {
 text 'd=30'
  command proc{
    $d=30
    prot
  }
 pack('side'=>'left')
}

TkButton.new {
 text 'd=40'
  command proc{
    $d=40
    prot
  }
 pack('side'=>'left')
}

TkButton.new {
 text 'd=50 (Cycloid)'
  command proc{
    $d=50
    prot
  }
 pack('side'=>'left')
}

TkButton.new {
 text 'd=60'
  command proc{
    $d=60
    prot
  }
 pack('side'=>'left')
}

TkButton.new {
 text 'd=70'
  command proc{
    $d=70
    prot
  }
 pack('side'=>'left')
}

# Quitボタン

TkButton.new {
 text 'Quit'
  command proc{
    exit
  }
 pack('side'=>'right')
}

# 描画

def prot
 

x0=0
y0=0

for i in 1..600

  x=$r*3.14*i/180-$d*Math.sin(3.14*i/180)
  y=$r*1-$d*Math.cos(3.14*i/180)

    Line.new($c,x0+20,200-y0,x+20,200-y);

  x0=x
  y0=y

end

end
 
 

Tk.mainloop
------------------------------------------------------------------