Lembra daquele nosso gato em Java FX? Agora ele move os olhos com cliques em botões.
Código fonte:
import javafx.ui.canvas.*;
import javafx.ui.*;
class Cat extends CompositeNode{
attribute look: Number; // -1.0 to 1.0
operation lookLeft();
operation lookCenter();
operation lookRight();
}
attribute Cat.look = 0; // 0 = middle
operation Cat.lookLeft(){
look = [look, look - 0.1 .. -1.0] dur 1000;
}
operation Cat.lookCenter(){
var step = if look < 0 then 0.1 else -0.1;
look = [look, look+step .. 0.0] dur 1000;
}
operation Cat.lookRight(){
look = [look, look + 0.1 .. 1.0] dur 1000;
}
function Cat.composeNode(){
var head = Ellipse {cx:100, cy:100, radiusX:100, radiusY:50, fill:black };
var rightEar = Arc {x:100, y:10, height:150, width:100,
startAngle:-20, length:90, closure:PIE, fill:black};
var leftEar = Arc {x:000, y:10, height:150, width:100,
startAngle:110, length:90, closure:PIE, fill:black};
var leftEye = Ellipse { cx:60, cy:100, radiusX:30, radiusY:15, fill:white};
var rightEye = Ellipse { cx:140, cy:100, radiusX:30, radiusY:15, fill:white};
var nose = Arc { x:85, y:110, height:20, width:30,
startAngle:45, length:90, closure:PIE, fill:white};
var rightIris = Ellipse { cx: bind 140+look*20, cy:100,
radiusX:5, radiusY:15, fill:black};
var leftIris = Ellipse { cx: bind 60+look*20, cy:100,
radiusX:5, radiusY:15, fill:black};
return Group{content: [head, rightEar, leftEar, leftEye,
leftIris, rightEye, rightIris, nose]};
}
var myCat = Cat{};
var myCatControl = View {
transform: [translate(0, 150)]
content: GroupPanel {
cursor: DEFAULT
var row = Row {alignment: BASELINE}
var column1 = Column { }
var column2 = Column { }
var column3 = Column { }
var column4 = Column { }
var column5 = Column { }
rows: [row]
columns: [column1, column2, column3, column4]
content:
[SimpleLabel {
row: row
column: column1
text: "Look:"
},
Button {
row: row
column: column2
mnemonic: L
text: "Left"
action: operation() {
myCat.lookLeft();
}
},
Button {
row: row
column: column3
mnemonic: C
text: "Center"
action: operation() {
myCat.lookCenter();
}
},
Button {
row: row
column: column4
mnemonic: R
text: "Right"
action: operation() {
myCat.lookRight();
}
}]
}
};
Canvas {
content: [myCatControl, myCat]
}
Downloads:
- Código-fonte: cat_ver2.fx
- VÃdeo: moving_eyes_cat.ogg
Gostei! Ficou muito massa mesmo, parabéns! 😀
[…] ã“ã‚Œã ã‘ã§ã¯ãªã‚“ãªã®ã§ãƒ»ãƒ»ãƒ»ã€‚ å°‘ã—å‰ã«JavaFXã®ãƒ¦ãƒ¼ã‚¶ç”¨ãƒ¡ãƒ¼ãƒªãƒ³ã‚°ãƒªã‚¹ãƒˆã«ã€ŒçŒ«ä½œã£ãŸã‚ˆï½žã€ã¨ã„ã†ãƒ¡ãƒ¼ãƒ«ã‚’æµã—ãŸäººãŒå±…ã¦ã€çŒ«é£¼ã„ã®ç§ã¨ã—ã¦ã¯ã¡ã‚‡ã£ã¨æ°—ã«ãªã£ã¦ã„ãŸã®ã§ã™ãŒã€ä»Šæ—¥ã€Œç›®ãŒå‹•ãよã†ã«ãªã£ãŸã‚ˆï½žã€ã¨ã„ã†æ›´æ–°ãƒ¡ãƒ¼ãƒ«ãŒæµã‚Œã¦ã¾ã—ãŸã€‚ãã®æ–¹ã®ãƒ–ãƒã‚°ãŒã“ã¡ã‚‰ã€‚JavaFX 猫ãŒç›®ã‚’å‹•ã‹ã™ã¨ã“ã‚を見るã“ã¨ãŒã§ãã¾ã™ã€‚ […]
Java??
OO
Caraca, eu nunca consegui aprender direito essa linguagem
-.-
Fikou mtu loko, parabéns
haja saco pra fazer
huhuhuhu
bju
=*
Ps: Delphi plix
漂亮
nice!