View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

OBY 5

PREV ------ ● TOP ● ------ NEXTUploaded Image: imager.jpg


ForthDay (光あれ)

オビーに目をつける
お次はオビーにまずは1つだけ目をつけてあげます。
これが成功したら2つにしてあげるからね。
だんだん顔らしくなってくるね!!


      Uploaded Image: zu3.jpg




■クラスを作る

ObyEyeクラス
「EllipseMorph」を親にして「ObyEye」クラスを定義します。
インスタンス変数「iris」は黒目を入れるためのものっす。
--------------------------------------------
EllipseMorph subclass: #ObyEye
	instanceVariableNames: 'iris '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'ObyMorph'
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )

Uploaded Image: image19.jpg



■メソッドを追加します。

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 )

Uploaded Image: image20.jpg


LookAtFrontメソッド
黒目はデフォルトでは白目の左上にくるので
黒目を真中にくるようにするメソッドを作ります。
--------------------------------------------
lookAtFront
	self iris position: self center - self iris center + self iris position
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )

Uploaded Image: image21.jpg


irisメソッド
インスタンス変数「iris」にアクセッスできるように
「iris」を返すメソッドを作っておきます。
--------------------------------------------
iris
	^ iris
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )

Uploaded Image: image22.jpg




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 )

Uploaded Image: image23.jpg


★インスタンスを出してみる
--------------------------------------------
Oby new openInWorld
--------------------------------------------
Alt + d ( Cmd + d )


一つ目小僧のオビーのできあがり!次は2つ目に挑戦だす。

Uploaded Image: image24.jpg





PREV ------ ● TOP ● ------ NEXT







■ MEMO ■

Links to this Page