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

デスクトップおロボットROBY

back

デスクトップおロボットROBYを作っちゃお。
OBYのロボット版ってことで「 ROBOT + OBY = ROBY 」
OBYの応用ってことで。



ソースコードを順番にドゥ〜イットしてみてください。
Alt + d ( Cmd + d )

ROBYの頭を作る

まずは頭を作るです。
----------------------------------------
head _ RectangleMorph new openInWorld.
head color: Color white.
head extent: 40@40.
head position: 50@50.
----------------------------------------

顔に右目をくっ付けます。
----------------------------------------
leftEye _ LineMorph new openInWorld.
head addMorph: leftEye.
leftEye setVertices: {0@0. 0@10}.
leftEye align: leftEye center with: head center + (-9@-1).
----------------------------------------

左目もね!
----------------------------------------
rightEye _ LineMorph new openInWorld.
head addMorph: rightEye.
rightEye setVertices: {0@0. 0@10}.
rightEye align: rightEye center with: head center + (9@-1).
----------------------------------------

口をくっ付け〜の。
----------------------------------------
lips _ LineMorph new openInWorld.
head addMorph: lips.
lips setVertices: {0@0. 10@0}.
lips align: lips center with: head center + (0@13).
----------------------------------------

アンテナもくっ付けまする。
----------------------------------------
antena _ LineMorph new openInWorld.
head addMorph: antena.
antena setVertices: {0@0. 0@7}.
antena align: antena bottomCenter with: head topCenter.
----------------------------------------




ROBYのボディーをつくる

体を作ります。
----------------------------------------
body _ RectangleMorph new openInWorld.
body color: Color white.
body extent: 45@20.
body position: 50@100.
----------------------------------------

ポケットをくっ付けよっと。
----------------------------------------
pocket _ LineMorph new openInWorld.
body addMorph: pocket.
pocket setVertices: {0@0. 12@0}.
pocket align: pocket rightCenter with: body rightCenter + (0@0).
----------------------------------------

左手をくっ付け〜の。
----------------------------------------
leftHand _ LineMorph new openInWorld.
body addMorph: leftHand.
leftHand setVertices: {0@0. -5@20}.
leftHand align: leftHand rightCenter with: body leftCenter + (1@1).
----------------------------------------

右手をくっ付けまする。
----------------------------------------
rightHand _ LineMorph new openInWorld.
body addMorph: rightHand.
rightHand setVertices: {0@0. 5@20}.
rightHand align: rightHand leftCenter with: body rightCenter + (-1@1).
----------------------------------------

左足をくっ付けてっと。
----------------------------------------
leftLeg _ LineMorph new openInWorld.
body addMorph: leftLeg.
leftLeg setVertices: {0@0. 0@7}.
leftLeg align: leftLeg topCenter with: body bottomCenter + (-10@0).
----------------------------------------

右足をくっ付けまして。
----------------------------------------
rightLeg _ LineMorph new openInWorld.
body addMorph: rightLeg.
rightLeg setVertices: {0@0. 0@7}.
rightLeg align: rightLeg topCenter with: body bottomCenter + (10@0).
----------------------------------------

ボディーに頭を合体させて、できあがり〜。
----------------------------------------
body addMorph: head.
head align: head bottomCenter with: body topCenter + (0@2).
leftHand comeToFront.
rightHand comeToFront.
----------------------------------------




いろいろなことさせちゃうっす。

ROBYにおしゃべらす。
----------------------------------------
head balloonColor: Color white.
head showBalloon: 'おいら、ロビですと'.
----------------------------------------

ROBYのくびふりふり。
----------------------------------------
head showBalloon: 'くびふるです'.
[2 timesRepeat: [
	(Delay forMilliseconds: 300) wait.
	head heading: 15.
	(Delay forMilliseconds: 300) wait.
	head heading: 0]] fork.

----------------------------------------

頭をが〜くがくさせる。
----------------------------------------
head showBalloon: 'あたまうごくす'.
[2 timesRepeat: [
	(Delay forMilliseconds: 300) wait.
	head position: head position - (0@2).
	(Delay forMilliseconds: 300) wait.
	head position: head position + (0@2)]] fork.

----------------------------------------

目をしばしばっとな。
----------------------------------------
head showBalloon: 'め、しばしばっす'.
[2 timesRepeat: [
	(Delay forMilliseconds: 300) wait.
	leftEye setVertices: {0@0. 7@0}.
	leftEye align: leftEye center with: head center + (-9@-1).
	rightEye setVertices: {0@0. 7@0}.
	rightEye align: rightEye center with: head center + (9@-1).
	(Delay forMilliseconds: 300) wait.
	leftEye setVertices: {0@0. 0@10}.
	leftEye align: leftEye center with: head center + (-9@-1).
	rightEye setVertices: {0@0. 0@10}.
	rightEye align: rightEye center with: head center + (9@-1).
]] fork.

----------------------------------------

口をパクパクするとおしゃべってるみたいっしょ?
----------------------------------------
head showBalloon: 'おしゃべるっす'.
[2 timesRepeat: [
	(Delay forMilliseconds: 200) wait.
	lips setVertices: {0@0. 0@3}.
	lips align: lips center with: head center + (0@13).
	(Delay forMilliseconds: 200) wait.
	lips setVertices: {0@0. 10@0}.
	lips align: lips center with: head center + (0@13).
]] fork.

----------------------------------------

アンテナするする、伸びたり縮んだり。
----------------------------------------
head showBalloon: 'あんてな、するする'.
[2 timesRepeat: [
	(Delay forMilliseconds: 300) wait.
	antena setVertices: {0@0. 0@20}.
	antena align: antena bottomCenter with: head topCenter.
	(Delay forMilliseconds: 300) wait.
	antena setVertices: {0@0. 0@7}.
	antena align: antena bottomCenter with: head topCenter.
]] fork.

----------------------------------------

左腕を動かすです。(まあ関節ないのでまわるだけっすけどね)
----------------------------------------
nowAngle _ ((leftHand vertices at: 2) - (leftHand vertices at: 1)) degrees.
pt1 _ leftHand vertices at: 1.
pt2 _ pt1 + (Point r: 20 degrees: nowAngle + 30).
leftHand setVertices: {pt1. pt2.}.
----------------------------------------

ってことで右腕もね!
----------------------------------------
nowAngle _ ((rightHand vertices at: 2) - (rightHand vertices at: 1)) degrees.
pt1 _ rightHand vertices at: 1.
pt2 _ pt1 + (Point r: 20 degrees: nowAngle - 30).
rightHand setVertices: {pt1. pt2.}.
----------------------------------------

左腕をぐるんぐるんと1回転。(ぐるんぐるんだから2回転じゃないの?)
----------------------------------------
head showBalloon: 'うでぐるぐる'.
nowAngle _ ((leftHand vertices at: 2) - (leftHand vertices at: 1)) degrees.
angle _ 0.
[[angle > 360] whileFalse: [
	(Delay forMilliseconds: 100) wait.
		pt1 _ leftHand vertices at: 1.
		pt2 _ pt1 + (Point r: 20 degrees: nowAngle + angle).
		leftHand setVertices: {pt1. pt2.}.
		angle _ angle + 20.
]] fork.

----------------------------------------




ROBY歩くか???

こんな感じと・・・・
----------------------------------------
pt1 _ leftHand vertices at: 1.
pt2 _ pt1 + (Point r: 15 degrees: 120).
leftHand setVertices: {pt1. pt2.}.
pt1 _ rightHand vertices at: 1.
pt2 _ pt1 + (Point r: 10 degrees: 73).
rightHand setVertices: {pt1. pt2.}.
pt1 _ leftLeg vertices at: 1.
pt2 _ pt1 + (Point r: 3 degrees: 90).
leftLeg setVertices: {pt1. pt2.}.
pt1 _ rightLeg vertices at: 1.
pt2 _ pt1 + (Point r: 10 degrees: 90).
rightLeg setVertices: {pt1. pt2.}.
----------------------------------------

こんな感じを・・・・
----------------------------------------
pt1 _ leftHand vertices at: 1.
pt2 _ pt1 + (Point r: 10 degrees: 107).
leftHand setVertices: {pt1. pt2.}.
pt1 _ rightHand vertices at: 1.
pt2 _ pt1 + (Point r: 15 degrees: 60).
rightHand setVertices: {pt1. pt2.}.
pt1 _ leftLeg vertices at: 1.
pt2 _ pt1 + (Point r: 10 degrees: 90).
leftLeg setVertices: {pt1. pt2.}.
pt1 _ rightLeg vertices at: 1.
pt2 _ pt1 + (Point r: 3 degrees: 90).
rightLeg setVertices: {pt1. pt2.}.
----------------------------------------

相互に繰り返すと・・・・・歩くわけよね。
(もちろん位置をY方向に10づつ追加してます)
----------------------------------------
head balloonColor: Color white.
head showBalloon: 'おいら、あるくっす'.
(Delay forMilliseconds: 300) wait.
[10 timesRepeat: [
	(Delay forMilliseconds: 200) wait.
		pt1 _ leftHand vertices at: 1.
		pt2 _ pt1 + (Point r: 15 degrees: 120).
		leftHand setVertices: {pt1. pt2.}.
		pt1 _ rightHand vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 73).
		rightHand setVertices: {pt1. pt2.}.
		pt1 _ leftLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 3 degrees: 90).
		leftLeg setVertices: {pt1. pt2.}.
		pt1 _ rightLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 90).
		rightLeg setVertices: {pt1. pt2.}.
		body position: body position + (0@5).
	(Delay forMilliseconds: 200) wait.
		pt1 _ leftHand vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 107).
		leftHand setVertices: {pt1. pt2.}.
		pt1 _ rightHand vertices at: 1.
		pt2 _ pt1 + (Point r: 15 degrees: 60).
		rightHand setVertices: {pt1. pt2.}.
		pt1 _ leftLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 90).
		leftLeg setVertices: {pt1. pt2.}.
		pt1 _ rightLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 3 degrees: 90).
		rightLeg setVertices: {pt1. pt2.}.
		body position: body position + (0@5)].
leftHand setVertices: {0@0. -5@20}.
leftHand align: leftHand rightCenter with: body leftCenter + (1@1).
rightHand setVertices: {0@0. 5@20}.
rightHand align: rightHand leftCenter with: body rightCenter + (-1@1).
leftLeg setVertices: {0@0. 0@7}.
leftLeg align: leftLeg topCenter with: body bottomCenter + (-10@0).
rightLeg setVertices: {0@0. 0@7}.
rightLeg align: rightLeg topCenter with: body bottomCenter + (10@0).
] fork.

----------------------------------------

右を向かせまして・・・・
----------------------------------------
head showBalloon: 'みぎむくっす'.
leftEye hide.
leftHand hide.
pocket hide.
lips align: lips rightCenter with: head rightCenter + (0@13).
pt1 _ rightHand vertices at: 1.
pt2 _ pt1 + (Point r: 20 degrees: 90).
rightHand setVertices: {pt1. pt2.}.
rightHand align: rightHand center with: body center + (0@0).
leftLeg align: leftLeg topCenter with: body bottomCenter + (-5@0).
rightLeg align: rightLeg topCenter with: body bottomCenter + (5@0).
----------------------------------------

こんなのと・・・・・・
----------------------------------------
pt1 _ rightHand vertices at: 1.
pt2 _ pt1 + (Point r: 20 degrees: 70).
rightHand setVertices: {pt1. pt2.}.
pt1 _ leftLeg vertices at: 1.
pt2 _ pt1 + (Point r: 10 degrees: 150).
leftLeg setVertices: {pt1. pt2.}.
pt1 _ rightLeg vertices at: 1.
pt2 _ pt1 + (Point r: 10 degrees: 30).
rightLeg setVertices: {pt1. pt2.}.
----------------------------------------

こんなのを・・・・・
----------------------------------------
pt1 _ rightHand vertices at: 1.
pt2 _ pt1 + (Point r: 20 degrees: 90).
rightHand setVertices: {pt1. pt2.}.
pt1 _ leftLeg vertices at: 1.
pt2 _ pt1 + (Point r: 7 degrees: 90).
leftLeg setVertices: {pt1. pt2.}.
pt1 _ rightLeg vertices at: 1.
pt2 _ pt1 + (Point r: 7 degrees: 90).
rightLeg setVertices: {pt1. pt2.}.
----------------------------------------

繰り返しますと・・・・・あるくです。
(X方向に10づつ追加してます)
----------------------------------------
head balloonColor: Color white.
head showBalloon: 'とてとて・・・'.
(Delay forMilliseconds: 300) wait.
[10 timesRepeat: [
	(Delay forMilliseconds: 200) wait.
		pt1 _ rightHand vertices at: 1.
		pt2 _ pt1 + (Point r: 20 degrees: 70).
		rightHand setVertices: {pt1. pt2.}.
		pt1 _ leftLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 150).
		leftLeg setVertices: {pt1. pt2.}.
		pt1 _ rightLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 30).
		rightLeg setVertices: {pt1. pt2.}.
		body position: body position + (10@0).
	(Delay forMilliseconds: 200) wait.
		pt1 _ rightHand vertices at: 1.
		pt2 _ pt1 + (Point r: 20 degrees: 90).
		rightHand setVertices: {pt1. pt2.}.
		pt1 _ leftLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 7 degrees: 90).
		leftLeg setVertices: {pt1. pt2.}.
		pt1 _ rightLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 7 degrees: 90).
		rightLeg setVertices: {pt1. pt2.}.
		body position: body position + (10@0).
]] fork.

----------------------------------------

前を向いてもらって・・・・
----------------------------------------
head showBalloon: 'まえむくっす'.
leftEye show.
rightEye show.
leftHand show.
rightHand show.
pocket show.
lips show.
lips align: lips center with: head center + (0@13).
leftHand setVertices: {0@0. -5@20}.
leftHand align: leftHand rightCenter with: body leftCenter + (1@1).
rightHand setVertices: {0@0. 5@20}.
rightHand align: rightHand leftCenter with: body rightCenter + (-1@1).
leftLeg setVertices: {0@0. 0@7}.
leftLeg align: leftLeg topCenter with: body bottomCenter + (-10@0).
rightLeg setVertices: {0@0. 0@7}.
rightLeg align: rightLeg topCenter with: body bottomCenter + (10@0).
----------------------------------------

そんでもっとすかさず、後ろ向きにして・・・・
----------------------------------------
head showBalloon: 'うしろむくです'.
leftEye hide.
rightEye hide.
pocket hide.
lips hide.
leftHand show.
rightHand show.
leftHand setVertices: {0@0. -5@20}.
leftHand align: leftHand rightCenter with: body leftCenter + (1@1).
rightHand setVertices: {0@0. 5@20}.
rightHand align: rightHand leftCenter with: body rightCenter + (-1@1).
leftLeg setVertices: {0@0. 0@7}.
leftLeg align: leftLeg topCenter with: body bottomCenter + (-10@0).
rightLeg setVertices: {0@0. 0@7}.
rightLeg align: rightLeg topCenter with: body bottomCenter + (10@0).
----------------------------------------

歩くです。
----------------------------------------
head balloonColor: Color white.
head showBalloon: 'ばいばい・・・'.
(Delay forMilliseconds: 300) wait.
[10 timesRepeat: [
	(Delay forMilliseconds: 200) wait.
		pt1 _ leftHand vertices at: 1.
		pt2 _ pt1 + (Point r: 15 degrees: 120).
		leftHand setVertices: {pt1. pt2.}.
		pt1 _ rightHand vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 73).
		rightHand setVertices: {pt1. pt2.}.
		pt1 _ leftLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 3 degrees: 90).
		leftLeg setVertices: {pt1. pt2.}.
		pt1 _ rightLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 90).
		rightLeg setVertices: {pt1. pt2.}.
		body position: body position + (0@-5).
	(Delay forMilliseconds: 200) wait.
		pt1 _ leftHand vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 107).
		leftHand setVertices: {pt1. pt2.}.
		pt1 _ rightHand vertices at: 1.
		pt2 _ pt1 + (Point r: 15 degrees: 60).
		rightHand setVertices: {pt1. pt2.}.
		pt1 _ leftLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 10 degrees: 90).
		leftLeg setVertices: {pt1. pt2.}.
		pt1 _ rightLeg vertices at: 1.
		pt2 _ pt1 + (Point r: 3 degrees: 90).
		rightLeg setVertices: {pt1. pt2.}.
		body position: body position + (0@-5)].
leftHand setVertices: {0@0. -5@20}.
leftHand align: leftHand rightCenter with: body leftCenter + (1@1).
rightHand setVertices: {0@0. 5@20}.
rightHand align: rightHand leftCenter with: body rightCenter + (-1@1).
leftLeg setVertices: {0@0. 0@7}.
leftLeg align: leftLeg topCenter with: body bottomCenter + (-10@0).
rightLeg setVertices: {0@0. 0@7}.
rightLeg align: rightLeg topCenter with: body bottomCenter + (10@0).
body delete.
] fork.

----------------------------------------

ってことでおしまい。


こんな風にいろいろWorkSpaceで形決めたりテストできるってのはお便利でする。
これをもとにROBYをクラスにしてみようかな・・・とおもっちょります。




下の入力ボックスに書き込んで”add to the page”ボタンで登録出来ます。
修正したい場合はページ左のアイコンの”edit”で出てくる画面で編集可能です。
ページ左のアイコンの”uploads”で画像(JPEG,GIF,PNG)のアップロードもできます。


Thursday, 2 September 2004, 12:14:15 pm
これを応用してデスクトップ・アシスタント(?)なんか出来たら面白いですね。--nanpiyo
  • ははは、昔AsistantPickleってえのをやってました。--thoru

Thursday, 2 September 2004, 11:27:02 am
scamperでの実行の手軽さにも驚きましたが、ROBYくんの魅力に,Squeakへの興味が倍増しました。
  • ありがとうです。Squeakいいっすよね!--thoru

Monday, 21 June 2004, 5:14:15 am
こ、これは!カワイイ。。。 --tak
  • ありがとです。なんかアイコンを大きくした感じがレトロでいいかなって・・・。--thoru

Link to this Page