OBY 5
ForthDay (光あれ)
オビーに目をつける
お次はオビーにまずは1つだけ目をつけてあげます。
これが成功したら2つにしてあげるからね。
だんだん顔らしくなってくるね!!
■クラスを作る
● ObyEyeクラス
「EllipseMorph」を親にして「ObyEye」クラスを定義します。
インスタンス変数「iris」は黒目を入れるためのものっす。
--------------------------------------------
EllipseMorph subclass: #ObyEye
instanceVariableNames: 'iris '
classVariableNames: ''
poolDictionaries: ''
category: 'ObyMorph'
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
■メソッドを追加します。
● initializeメソッド
この「ObyEye」は白目なので
色は 白
大きさは 15@15
黒目「iris」は新たに「EllipseMorph」を生成します。
大きさは 6@6
枠線は ナシ
色は 黒
「ObyEye」のサブモーフにします。
「lookAtFront」は前を向くメソッドです。(この後作るっす)
--------------------------------------------
initialize
super initialize.
"白目の設定"
self color: (Color r: 1.0 g: 0.968 b: 0.935).
self extent: 15 @ 15.
"黒目の生成と設定"
iris _ EllipseMorph new.
iris extent: 6@6.
iris borderWidth: 0.
iris color: Color black.
self addMorphFront: iris.
self lookAtFront
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● LookAtFrontメソッド
黒目はデフォルトでは白目の左上にくるので
黒目を真中にくるようにするメソッドを作ります。
--------------------------------------------
lookAtFront
self iris position: self center - self iris center + self iris position
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● irisメソッド
インスタンス変数「iris」にアクセッスできるように
「iris」を返すメソッドを作っておきます。
--------------------------------------------
iris
^ iris
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● Obyクラスのinitializeメソッドを修正
目を土台にくっ付けます。
「ObyEye」のインスタンスを生成し
土台の「Oby」のサブモーフにします。
「Oby」のセンターと「ObyEye」のセンターを合わせます。
--------------------------------------------
initialize
super initialize.
"土台の設定"
self extent: 80@80.
self color: (Color r: 1.0 g: 1.0 b: 1.0 alpha: 0.5).
self borderWidth: 0.
"顔の生成"
face _ ObyFace new.
self addMorph: face.
face align: face center with: self center.
"目の生成"
eye _ ObyEye new.
self addMorph: eye.
eye align: eye center with: self center + (0 @ 0).
"口の生成"
lips _ ObyLips new.
self addMorph: lips.
lips align: lips center with: self center + (0 @ 30).
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
★インスタンスを出してみる
--------------------------------------------
Oby new openInWorld
--------------------------------------------
Alt + d ( Cmd + d )
一つ目小僧のオビーのできあがり!次は2つ目に挑戦だす。
▲PREV ------ ● TOP ● ------ NEXT▼
■ MEMO ■
Links to this Page
- I BOBY last edited on 28 April 2004 at 8:57:55 pm by tk0005-202x210x196x109.ap-TK.usen.ad.jp
- OBY 4 last edited on 17 June 2007 at 7:12:45 am by localhost.localdomain
- OBY 6 last edited on 23 March 2011 at 4:12:20 am by 65.49.33.65