SlideShare una empresa de Scribd logo
1 de 62
Descargar para leer sin conexión
Raphael Marques

Mestrando em Informática da UFPB
jose.raphael.marques@gmail.com
raphaelmarques.wordpress.com
2
var seq1 : Integer[ ] = [1,2,3,4,5,6,7,8,9,10];
println(seq1);
//[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
var seq2 = [1..10];
println(seq2);
//[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
var seq3 = [1..10 step 2];
println(seq3);
//[ 1, 3, 5, 7, 9 ]
var seq4 = [10..1 step -2];
println(seq4);
//[ 10, 8, 6, 4, 2 ]

                                                  3
var seq1 = [1..3 step 0.5];
println(seq1);
//[ 1.0, 1.5, 2.0, 2.5, 3.0 ]
var seq2 = [1.5..3];
println(seq2);
//[ 1.5, 2.5 ]
var seq3 : (Integer[ ])[ ] = [1,2,3,4,5,6];
println(seq3);
//[ [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ] ]
var seq4 : (Integer[ ])[ ] = [ [1..3] , [4..6] ];
println(seg4);
//[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]

                                                    4
var seq1 : Integer[] = 0;
println(seq1);
//[ 0 ]

var seq2 = [1..5];
println(seq2);
//[ 1, 2, 3, 4, 5 ]

seq2[0] = 0;
println(seq2);
//[ 0, 2, 3, 4, 5 ]
                            5
var seq1 = [1..5];
var seq2 = seq1;

seq2[0] = 0;

println(seq1);
//[ 1, 2, 3, 4, 5 ]

println(seq2);
//[ 0, 2, 3, 4, 5 ]

                      6
var uteis = ["seg","ter","qua","qui","sex"];
var fds = ["sab","dom"];

var semana = [uteis,fds];
var semana2 = [uteis,["sab","dom"]];
var semana3 = [uteis,"sab","dom"];


                                               7
var n = [1..10];
var pares = n[i | i mod 2 == 0];
println(pares);
//[ 2, 4, 6, 8, 10 ]
println(sizeof pares);
//5



                                   8
var n = [1..5];        //[ 1, 2, 3, 4, 5 ]
insert 4 into n;       //[ 1, 2, 3, 4, 5, 4 ]
insert 7 before n[3]; //[ 1, 2, 3, 7, 4, 5, 4 ]
insert 8 after n[3]; //[ 1, 2, 3, 7, 8, 4, 5, 4 ]
delete 4 from n;    //[ 1, 2, 3, 7, 8, 5 ]
delete n[2] from n; //[ 1, 2, 7, 8, 5 ]
delete n[2];           //[ 1, 2, 8, 5 ]
delete n;              //[ ]
                                                    9
var n = [1..5];            //[ 1, 2, 3, 4, 5 ]
n = reverse n;             //[ 5, 4, 3, 2, 1 ]
var n2 = [5..1 step -1];   //[ 5, 4, 3, 2, 1 ]
println(n == n2);          //true




                                                 10
var n = [1..10]; //[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
n[0..4]           //[ 1, 2, 3, 4, 5 ]
n[0..<4]          //[ 1, 2, 3, 4 ]
n[5..]            //[ 6, 7, 8, 9, 10 ]
n[0..<]           //[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]



                                                       11
12
   Tudo em JavaFX é uma expressão
     loops, condicionais, blocos


   Em alguns casos as expressões tem tipo Void.
     while, classes


   A ultima expressão de um bloco é o retorno
    dele.

                                                   13
var x = {
   var a = 5;
   a * 2;
};

println(x);     //10



                       14
var x = 10;       var x = 10;          var a : Number;
var a = 0;        var a = 0;
if(x > 0){        var b = if(x > 0){   var b = a = 1;
   a = 1;            a = 1;
}else{            }else{               println(b);//1.0
   a = 2;            a = 2;
}                 };

println(a); //1   println(a); //1
                  println(b);//1
                                                        15
var x = 0;         var x = 0;
while(x < 10){     while(x < 10)
  x++;               x++;
}
println(x); //10   println(x); //10




                                      16
for(i in [1..5]){    var a = for(i in [1..5])
   print("[{i}]");      i*i;
}                    println(a);
//[1][2][3][4][5]    //[ 1, 4, 9, 16, 25 ]

var a = [1..5];      var b = for(i in [1,4,9,16,25])
for(i in a)             Math.sqrt(i);
   print("[{i}]");   println(b);
//[1][2][3][4][5]    //[ 1.0, 2.0, 3.0, 4.0, 5.0 ]


                                                  17
18
class Conta{
  var nome: String;
  var numero: Integer;
  var saldo = 1000;
    init{
    }
    function deposito(valor: Integer):Void{
       saldo += valor;
    }
    override function toString(){
      "Conta({nome},{numero},${saldo})";
    }
}
                                              19
var conta = Conta{
   nome: "Raphael"
   numero: 123
};
println(conta);
//Conta(Raphael,123,$1000)




                             20
class MyClass extends Conta {
}
class MyClass extends Serializable {
}
class MyClass extends Conta, Serializable {
}




                                              21
mixin class Terrestre{
  function andar(){ println("andando"); }
}
mixin class Aquativo{
  function nadar(){ println("nadando"); }
}
class Jacare extends Terrestre, Aquativo{ }
var jacare = Jacare{};
jacare.andar();
jacare.nadar();
                                              22
   default
     Visível apenas no script
   package
     Visível no mesmo pacote
   protected
     Visível no mesmo pacote ou subclasses.
   public
     Sem restrições

                                               23
   public-read
     Sem restrição para leitura
     Só pode ser escrito dentro do script
     Para permissão de escrita:
      ▪ package public-read
      ▪ protected public-read
   public-init
     Pode ser inicializado na criação do objeto, em
     outros casos é igual ao public-read
                                                       24
arquivo MyClass.fx:
          public var x = 1;
          public class MyClass{
               public var y = 2;
          }
outro arquivo:
          MyClass.x = 0;
          var obj = MyClass{};
          obj.y = 0;
                                   25
26
class Donut extends CustomNode {
  public var x = 0.0;
  public var y = 0.0;
  public var raioExterno = 10.0;
  public var raioInterno = 5.0;
  public var fill: Paint = Color.BLACK;
  public var stroke: Paint;

    ...
}
                                          27
class Donut extends CustomNode {
  ...
    public override function create(): Node {
      Group{
             content: bind ShapeSubtract{
                   a: Circle{radius: raioExterno}
                   b: Circle{radius: raioInterno}
                   fill: bind fill
                   stroke: bind stroke
                   translateX: bind x
                   translateY: bind y
             }
      }
    }
}                                                   28
class Donut extends CustomNode {
  ...
    public override function create(): Node {
      Group{
             content: bind ShapeSubtract{
                   a: Circle{radius: raioExterno}
                   b: Circle{radius: raioInterno}
                   fill: bind fill
                   stroke: bind stroke
                   translateX: bind x
                   translateY: bind y
             }
      }
    }
}                                                   29
class Donut extends CustomNode {
  ...
    public override function create(): Node {
      Group{
             content: bind ShapeSubtract{
                   a: Circle{radius: raioExterno}
                   b: Circle{radius: raioInterno}
                   fill: bind fill
                   stroke: bind stroke
                   translateX: bind x
                   translateY: bind y
             }
      }
    }
}                                                   30
class Donut extends CustomNode {
  ...
    public override function create(): Node {
      Group{
             content: bind ShapeSubtract{
                   a: Circle{radius: raioExterno}
                   b: Circle{radius: raioInterno}
                   fill: bind fill
                   stroke: bind stroke
                   translateX: bind x
                   translateY: bind y
             }
      }
    }
}                                                   31
class Donut extends CustomNode {
  ...
    public override function create(): Node {
      Group{
             content: bind ShapeSubtract{
                   a: Circle{radius: raioExterno}
                   b: Circle{radius: raioInterno}
                   fill: bind fill
                   stroke: bind stroke
                   translateX: bind x
                   translateY: bind y
             }
      }
    }
}                                                   32
class Donut extends CustomNode {
  ...
    public override function create(): Node {
      Group{
             content: bind ShapeSubtract{
                   a: Circle{radius: raioExterno}
                   b: Circle{radius: raioInterno}
                   fill: bind fill
                   stroke: bind stroke
                   translateX: bind x
                   translateY: bind y
             }
      }
    }
}                                                   33
Donut{
  x: 100
  y: 100
  raioExterno: 80
  raioInterno: 50
  fill: Color.RED
  stroke: Color.BLACK
}

                        34
Donut{
  x: 100
  y: 100
  raioExterno: 80
  raioInterno: 50
  fill: Color.RED
  stroke: Color.BLACK
}

                        35
36
   Criar um projeto chamado Praticas
   Site:
     http://sites.google.com/site/joseraphaelmarques/
   Link lateral: eventos
   Baixar os 4 arquivos no pacote praticas




                                                     37
38
39
40
0   X


Y                       vel




                angle

        (x,y)




                              41
0   X
                              vel+acel

Y
                        vel


                angle

        (x,y)




                                         42
0   X


                               vel
Y


                        vel-acel
                angle

        (x,y)




                                     43
0   X


Y        vy              vel




                angle

        (x,y)           vx




                               44
0   X
                turn left

Y

                            turn right



        (x,y)




                                         45
   Criar um projeto chamado RaceFX
   Site:
     http://sites.google.com/site/joseraphaelmarques/
   Link lateral: RaceFX
   Link: Parte 1
   Baixar para o pacote racefx:
     bluecar.png
     redcar.png
     Game.fx
                                                     46
47
public def REDCAR = Image {
   url: "{__DIR__}redcar.png"
};
public def BLUECAR = Image {
   url: "{__DIR__}bluecar.png"
};
def RAD180 = Math.PI;
def RAD360 = 2*Math.PI;
def ACEL = 100;
def TURN = Math.PI;
def VMIN = -50;
def VMAX = 250;
def FRICTION = 50;


                                 48
public class Car extends CustomNode{
  //posicao
  public var x: Number;
  public var y: Number;
  public var angle: Number;
  public var vel: Number;
    public-init var image: Image;
    //controles
    public var left = false;
    public var right = false;
    public var up = false;
    public var down = false;
    ...
}

                                       49
public class Car extends CustomNode{
  ...
  public override function create(): Node {
      return ImageView {
            image: image
            translateX: bind x – 15
            translateY: bind y - 7.5
            rotate: bind -Math.toDegrees(angle);
      };
  }
  ...
}
                                                   50
public class Car extends CustomNode{
  ...
  function updateTurn(factor: Number):Void{
      if(left != right){//xor
               var t = if(left) TURN else –TURN;
               angle = (angle + t*factor) mod RAD360;
      }
  }
  ...
}




                                                        51
public class Car extends CustomNode{
    ...
    function updateAcel(factor: Number):Void{
        if(down){//freiando
                   vel = Math.max(VMIN, vel - ACEL*factor);
          }else if(up){//acelerando
                   vel = Math.min(VMAX, vel + ACEL*factor);
          }else{//desacelerando
                   if(vel > 0){
                            vel = Math.max(0, vel - FRICTION*factor);
                   }else{
                            vel = Math.min(0, vel + FRICTION*factor);
                   }
          }
    }
    ...
}

                                                                        52
public class Car extends CustomNode{
  ...
  function updateMove(factor: Number):Void{
      var vx = Math.cos(angle) * vel * factor;
      var vy = -Math.sin(angle) * vel * factor;
          var i = x + vx;
          var j = y + vy;
          x = i;
          y = j;
    }
    ...
}

                                                  53
public class Car extends CustomNode{
  ...
  public function update(time: Long):Void{
      var factor = time / 1000.0;
      if(factor == 0) return;
          updateTurn(factor);
          updateAcel(factor);
          if(vel != 0){
                   updateMove(factor);
          }
    }
    ...
}


                                             54
55
public class Game extends CustomNode{
  public-read var car1 = Car{};
  public-read var car2 = Car{};
    var lastTime: Long;
    function update():Void{}
    var timeline = Timeline {}
    public function reset():Void{}
    public function play(){}
    var bg = Rectangle{};
    init{}
    public override function create():Node{}
}

                                               56
public class Game extends CustomNode{
  ...
  public override function create():Node{
      Group{
           content: [
                bg,
                car1,
                car2,
           ]
      }
  }
  ...
}
                                            57
public class Game extends CustomNode{
  ...
  function checkKey(code: KeyCode, value: Boolean){
       if(code == KeyCode.VK_LEFT){
                car1.left = value;
       }else if ...
  }
    function onKeyPressed(e:KeyEvent):Void{
        checkKey(e.code, true);
    }
    function onKeyReleased(e:KeyEvent):Void{
        checkKey(e.code, false);
    }
    ...
}

                                                      58
59
var game = Game{};

Stage {
  title: "RaceFX"
  scene: Scene {
      width: 640
      height: 480
      content: game
  }
}
                      60
61
62

Más contenido relacionado

La actualidad más candente

Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory ManagementAlan Uthoff
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the raceVictor_Cr
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureMike Fogus
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Platonov Sergey
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.Mike Fogus
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...
ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...
ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...Tao Xie
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the raceVictor_Cr
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languagesJonas Follesø
 
The Macronomicon
The MacronomiconThe Macronomicon
The MacronomiconMike Fogus
 
Adventures In Data Compilation
Adventures In Data CompilationAdventures In Data Compilation
Adventures In Data CompilationNaughty Dog
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinDmitry Pranchuk
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
Creating Custom Charts With Ruby Vector Graphics
Creating Custom Charts With Ruby Vector GraphicsCreating Custom Charts With Ruby Vector Graphics
Creating Custom Charts With Ruby Vector GraphicsDavid Keener
 
When Bad Things Come In Good Packages
When Bad Things Come In Good PackagesWhen Bad Things Come In Good Packages
When Bad Things Come In Good PackagesSaumil Shah
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in DepthC4Media
 

La actualidad más candente (20)

Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
Lecture4
Lecture4Lecture4
Lecture4
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the race
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
 
Travel management
Travel managementTravel management
Travel management
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...
ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...
ACM Distinguished Program: Cooperative Testing and Analysis: Human-Tool, Tool...
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the race
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languages
 
The Macronomicon
The MacronomiconThe Macronomicon
The Macronomicon
 
Adventures In Data Compilation
Adventures In Data CompilationAdventures In Data Compilation
Adventures In Data Compilation
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
Creating Custom Charts With Ruby Vector Graphics
Creating Custom Charts With Ruby Vector GraphicsCreating Custom Charts With Ruby Vector Graphics
Creating Custom Charts With Ruby Vector Graphics
 
Why MacRuby Matters
Why MacRuby MattersWhy MacRuby Matters
Why MacRuby Matters
 
When Bad Things Come In Good Packages
When Bad Things Come In Good PackagesWhen Bad Things Come In Good Packages
When Bad Things Come In Good Packages
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 

Destacado

Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)Raphael Marques
 
JavaFX: A nova biblioteca gráfica da plataforma Java
JavaFX: A nova biblioteca gráfica da plataforma JavaJavaFX: A nova biblioteca gráfica da plataforma Java
JavaFX: A nova biblioteca gráfica da plataforma JavajesuinoPower
 
JavaFX: Desktop para desenvolvedores WEB
JavaFX: Desktop para desenvolvedores WEBJavaFX: Desktop para desenvolvedores WEB
JavaFX: Desktop para desenvolvedores WEBjesuinoPower
 
Como ingressar no mercado de Machine Learning
Como ingressar no mercado de Machine LearningComo ingressar no mercado de Machine Learning
Como ingressar no mercado de Machine LearningGabriel Cypriano Saca
 
Aprendizado de Máquinas com Azure Machine Learning e R
Aprendizado de Máquinas com Azure Machine Learning e RAprendizado de Máquinas com Azure Machine Learning e R
Aprendizado de Máquinas com Azure Machine Learning e RDiego Nogare
 
Introdução ao Machine Learning para Hackers
Introdução ao Machine Learning para HackersIntrodução ao Machine Learning para Hackers
Introdução ao Machine Learning para HackersGabriel Cypriano Saca
 
Criando aplicações java fx em minutos
Criando aplicações java fx em minutosCriando aplicações java fx em minutos
Criando aplicações java fx em minutosBruno Oliveira
 
Boas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SP
Boas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SPBoas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SP
Boas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SPjesuinoPower
 
Desenvolvimento rápido de aplicações com JEE e JavaFX
Desenvolvimento rápido de aplicações com JEE e JavaFXDesenvolvimento rápido de aplicações com JEE e JavaFX
Desenvolvimento rápido de aplicações com JEE e JavaFXjesuinoPower
 
Aplicações Práticas de Machine Learning
Aplicações Práticas de Machine LearningAplicações Práticas de Machine Learning
Aplicações Práticas de Machine LearningLuiz Costa
 

Destacado (16)

Introdução ao JavaFX
Introdução ao JavaFXIntrodução ao JavaFX
Introdução ao JavaFX
 
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
 
JavaFX 1.2
JavaFX 1.2JavaFX 1.2
JavaFX 1.2
 
JavaFX
JavaFXJavaFX
JavaFX
 
JavaFX: A nova biblioteca gráfica da plataforma Java
JavaFX: A nova biblioteca gráfica da plataforma JavaJavaFX: A nova biblioteca gráfica da plataforma Java
JavaFX: A nova biblioteca gráfica da plataforma Java
 
Classes Internas
Classes InternasClasses Internas
Classes Internas
 
Operadores Java
Operadores JavaOperadores Java
Operadores Java
 
JavaFX: Desktop para desenvolvedores WEB
JavaFX: Desktop para desenvolvedores WEBJavaFX: Desktop para desenvolvedores WEB
JavaFX: Desktop para desenvolvedores WEB
 
Como ingressar no mercado de Machine Learning
Como ingressar no mercado de Machine LearningComo ingressar no mercado de Machine Learning
Como ingressar no mercado de Machine Learning
 
Aprendizado de Máquinas com Azure Machine Learning e R
Aprendizado de Máquinas com Azure Machine Learning e RAprendizado de Máquinas com Azure Machine Learning e R
Aprendizado de Máquinas com Azure Machine Learning e R
 
Introdução ao Machine Learning para Hackers
Introdução ao Machine Learning para HackersIntrodução ao Machine Learning para Hackers
Introdução ao Machine Learning para Hackers
 
Machine Learning - Introdução e Aplicações
Machine Learning - Introdução e AplicaçõesMachine Learning - Introdução e Aplicações
Machine Learning - Introdução e Aplicações
 
Criando aplicações java fx em minutos
Criando aplicações java fx em minutosCriando aplicações java fx em minutos
Criando aplicações java fx em minutos
 
Boas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SP
Boas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SPBoas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SP
Boas práticas na criação de aplicações sérias com JavaFX - TDC 2014 SP
 
Desenvolvimento rápido de aplicações com JEE e JavaFX
Desenvolvimento rápido de aplicações com JEE e JavaFXDesenvolvimento rápido de aplicações com JEE e JavaFX
Desenvolvimento rápido de aplicações com JEE e JavaFX
 
Aplicações Práticas de Machine Learning
Aplicações Práticas de Machine LearningAplicações Práticas de Machine Learning
Aplicações Práticas de Machine Learning
 

Similar a Mini-curso JavaFX Aula2

TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013ericupnorth
 
Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22nikomatsakis
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mark Needham
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comShwetaAggarwal56
 

Similar a Mini-curso JavaFX Aula2 (20)

TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
alexnet.pdf
alexnet.pdfalexnet.pdf
alexnet.pdf
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Introduction to-java
Introduction to-javaIntroduction to-java
Introduction to-java
 

Más de Raphael Marques

Introdução a Informática - Arquitetura
Introdução a Informática - ArquiteturaIntrodução a Informática - Arquitetura
Introdução a Informática - ArquiteturaRaphael Marques
 
O que você produz além de código?
O que você produz além de código?O que você produz além de código?
O que você produz além de código?Raphael Marques
 
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)Raphael Marques
 
Slides de PDI 2009 - Raphael Update 5
Slides de PDI 2009 - Raphael Update 5Slides de PDI 2009 - Raphael Update 5
Slides de PDI 2009 - Raphael Update 5Raphael Marques
 
slides PDI 2007 leonardo
slides PDI 2007 leonardoslides PDI 2007 leonardo
slides PDI 2007 leonardoRaphael Marques
 
Slides PDI 2009 Raphael versao4
Slides PDI 2009 Raphael versao4Slides PDI 2009 Raphael versao4
Slides PDI 2009 Raphael versao4Raphael Marques
 

Más de Raphael Marques (11)

Sistemas numéricos
Sistemas numéricosSistemas numéricos
Sistemas numéricos
 
Windows explorer
Windows explorerWindows explorer
Windows explorer
 
Interface do windows
Interface do windowsInterface do windows
Interface do windows
 
Internet
InternetInternet
Internet
 
Introdução a Informática - Arquitetura
Introdução a Informática - ArquiteturaIntrodução a Informática - Arquitetura
Introdução a Informática - Arquitetura
 
O que você produz além de código?
O que você produz além de código?O que você produz além de código?
O que você produz além de código?
 
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
Aplicações desktop (GUI) e aplicações ricas para internet (RIA)
 
Slides de PDI 2009 - Raphael Update 5
Slides de PDI 2009 - Raphael Update 5Slides de PDI 2009 - Raphael Update 5
Slides de PDI 2009 - Raphael Update 5
 
slides PDI 2007 leonardo
slides PDI 2007 leonardoslides PDI 2007 leonardo
slides PDI 2007 leonardo
 
Slides PDI 2009 Raphael versao4
Slides PDI 2009 Raphael versao4Slides PDI 2009 Raphael versao4
Slides PDI 2009 Raphael versao4
 
Minicurso Java && Cl
Minicurso Java && ClMinicurso Java && Cl
Minicurso Java && Cl
 

Mini-curso JavaFX Aula2

  • 1. Raphael Marques Mestrando em Informática da UFPB jose.raphael.marques@gmail.com raphaelmarques.wordpress.com
  • 2. 2
  • 3. var seq1 : Integer[ ] = [1,2,3,4,5,6,7,8,9,10]; println(seq1); //[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] var seq2 = [1..10]; println(seq2); //[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] var seq3 = [1..10 step 2]; println(seq3); //[ 1, 3, 5, 7, 9 ] var seq4 = [10..1 step -2]; println(seq4); //[ 10, 8, 6, 4, 2 ] 3
  • 4. var seq1 = [1..3 step 0.5]; println(seq1); //[ 1.0, 1.5, 2.0, 2.5, 3.0 ] var seq2 = [1.5..3]; println(seq2); //[ 1.5, 2.5 ] var seq3 : (Integer[ ])[ ] = [1,2,3,4,5,6]; println(seq3); //[ [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ] ] var seq4 : (Integer[ ])[ ] = [ [1..3] , [4..6] ]; println(seg4); //[ [ 1, 2, 3 ], [ 4, 5, 6 ] ] 4
  • 5. var seq1 : Integer[] = 0; println(seq1); //[ 0 ] var seq2 = [1..5]; println(seq2); //[ 1, 2, 3, 4, 5 ] seq2[0] = 0; println(seq2); //[ 0, 2, 3, 4, 5 ] 5
  • 6. var seq1 = [1..5]; var seq2 = seq1; seq2[0] = 0; println(seq1); //[ 1, 2, 3, 4, 5 ] println(seq2); //[ 0, 2, 3, 4, 5 ] 6
  • 7. var uteis = ["seg","ter","qua","qui","sex"]; var fds = ["sab","dom"]; var semana = [uteis,fds]; var semana2 = [uteis,["sab","dom"]]; var semana3 = [uteis,"sab","dom"]; 7
  • 8. var n = [1..10]; var pares = n[i | i mod 2 == 0]; println(pares); //[ 2, 4, 6, 8, 10 ] println(sizeof pares); //5 8
  • 9. var n = [1..5]; //[ 1, 2, 3, 4, 5 ] insert 4 into n; //[ 1, 2, 3, 4, 5, 4 ] insert 7 before n[3]; //[ 1, 2, 3, 7, 4, 5, 4 ] insert 8 after n[3]; //[ 1, 2, 3, 7, 8, 4, 5, 4 ] delete 4 from n; //[ 1, 2, 3, 7, 8, 5 ] delete n[2] from n; //[ 1, 2, 7, 8, 5 ] delete n[2]; //[ 1, 2, 8, 5 ] delete n; //[ ] 9
  • 10. var n = [1..5]; //[ 1, 2, 3, 4, 5 ] n = reverse n; //[ 5, 4, 3, 2, 1 ] var n2 = [5..1 step -1]; //[ 5, 4, 3, 2, 1 ] println(n == n2); //true 10
  • 11. var n = [1..10]; //[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] n[0..4] //[ 1, 2, 3, 4, 5 ] n[0..<4] //[ 1, 2, 3, 4 ] n[5..] //[ 6, 7, 8, 9, 10 ] n[0..<] //[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] 11
  • 12. 12
  • 13. Tudo em JavaFX é uma expressão  loops, condicionais, blocos  Em alguns casos as expressões tem tipo Void.  while, classes  A ultima expressão de um bloco é o retorno dele. 13
  • 14. var x = { var a = 5; a * 2; }; println(x); //10 14
  • 15. var x = 10; var x = 10; var a : Number; var a = 0; var a = 0; if(x > 0){ var b = if(x > 0){ var b = a = 1; a = 1; a = 1; }else{ }else{ println(b);//1.0 a = 2; a = 2; } }; println(a); //1 println(a); //1 println(b);//1 15
  • 16. var x = 0; var x = 0; while(x < 10){ while(x < 10) x++; x++; } println(x); //10 println(x); //10 16
  • 17. for(i in [1..5]){ var a = for(i in [1..5]) print("[{i}]"); i*i; } println(a); //[1][2][3][4][5] //[ 1, 4, 9, 16, 25 ] var a = [1..5]; var b = for(i in [1,4,9,16,25]) for(i in a) Math.sqrt(i); print("[{i}]"); println(b); //[1][2][3][4][5] //[ 1.0, 2.0, 3.0, 4.0, 5.0 ] 17
  • 18. 18
  • 19. class Conta{ var nome: String; var numero: Integer; var saldo = 1000; init{ } function deposito(valor: Integer):Void{ saldo += valor; } override function toString(){ "Conta({nome},{numero},${saldo})"; } } 19
  • 20. var conta = Conta{ nome: "Raphael" numero: 123 }; println(conta); //Conta(Raphael,123,$1000) 20
  • 21. class MyClass extends Conta { } class MyClass extends Serializable { } class MyClass extends Conta, Serializable { } 21
  • 22. mixin class Terrestre{ function andar(){ println("andando"); } } mixin class Aquativo{ function nadar(){ println("nadando"); } } class Jacare extends Terrestre, Aquativo{ } var jacare = Jacare{}; jacare.andar(); jacare.nadar(); 22
  • 23. default  Visível apenas no script  package  Visível no mesmo pacote  protected  Visível no mesmo pacote ou subclasses.  public  Sem restrições 23
  • 24. public-read  Sem restrição para leitura  Só pode ser escrito dentro do script  Para permissão de escrita: ▪ package public-read ▪ protected public-read  public-init  Pode ser inicializado na criação do objeto, em outros casos é igual ao public-read 24
  • 25. arquivo MyClass.fx: public var x = 1; public class MyClass{ public var y = 2; } outro arquivo: MyClass.x = 0; var obj = MyClass{}; obj.y = 0; 25
  • 26. 26
  • 27. class Donut extends CustomNode { public var x = 0.0; public var y = 0.0; public var raioExterno = 10.0; public var raioInterno = 5.0; public var fill: Paint = Color.BLACK; public var stroke: Paint; ... } 27
  • 28. class Donut extends CustomNode { ... public override function create(): Node { Group{ content: bind ShapeSubtract{ a: Circle{radius: raioExterno} b: Circle{radius: raioInterno} fill: bind fill stroke: bind stroke translateX: bind x translateY: bind y } } } } 28
  • 29. class Donut extends CustomNode { ... public override function create(): Node { Group{ content: bind ShapeSubtract{ a: Circle{radius: raioExterno} b: Circle{radius: raioInterno} fill: bind fill stroke: bind stroke translateX: bind x translateY: bind y } } } } 29
  • 30. class Donut extends CustomNode { ... public override function create(): Node { Group{ content: bind ShapeSubtract{ a: Circle{radius: raioExterno} b: Circle{radius: raioInterno} fill: bind fill stroke: bind stroke translateX: bind x translateY: bind y } } } } 30
  • 31. class Donut extends CustomNode { ... public override function create(): Node { Group{ content: bind ShapeSubtract{ a: Circle{radius: raioExterno} b: Circle{radius: raioInterno} fill: bind fill stroke: bind stroke translateX: bind x translateY: bind y } } } } 31
  • 32. class Donut extends CustomNode { ... public override function create(): Node { Group{ content: bind ShapeSubtract{ a: Circle{radius: raioExterno} b: Circle{radius: raioInterno} fill: bind fill stroke: bind stroke translateX: bind x translateY: bind y } } } } 32
  • 33. class Donut extends CustomNode { ... public override function create(): Node { Group{ content: bind ShapeSubtract{ a: Circle{radius: raioExterno} b: Circle{radius: raioInterno} fill: bind fill stroke: bind stroke translateX: bind x translateY: bind y } } } } 33
  • 34. Donut{ x: 100 y: 100 raioExterno: 80 raioInterno: 50 fill: Color.RED stroke: Color.BLACK } 34
  • 35. Donut{ x: 100 y: 100 raioExterno: 80 raioInterno: 50 fill: Color.RED stroke: Color.BLACK } 35
  • 36. 36
  • 37. Criar um projeto chamado Praticas  Site:  http://sites.google.com/site/joseraphaelmarques/  Link lateral: eventos  Baixar os 4 arquivos no pacote praticas 37
  • 38. 38
  • 39. 39
  • 40. 40
  • 41. 0 X Y vel angle (x,y) 41
  • 42. 0 X vel+acel Y vel angle (x,y) 42
  • 43. 0 X vel Y vel-acel angle (x,y) 43
  • 44. 0 X Y vy vel angle (x,y) vx 44
  • 45. 0 X turn left Y turn right (x,y) 45
  • 46. Criar um projeto chamado RaceFX  Site:  http://sites.google.com/site/joseraphaelmarques/  Link lateral: RaceFX  Link: Parte 1  Baixar para o pacote racefx:  bluecar.png  redcar.png  Game.fx 46
  • 47. 47
  • 48. public def REDCAR = Image { url: "{__DIR__}redcar.png" }; public def BLUECAR = Image { url: "{__DIR__}bluecar.png" }; def RAD180 = Math.PI; def RAD360 = 2*Math.PI; def ACEL = 100; def TURN = Math.PI; def VMIN = -50; def VMAX = 250; def FRICTION = 50; 48
  • 49. public class Car extends CustomNode{ //posicao public var x: Number; public var y: Number; public var angle: Number; public var vel: Number; public-init var image: Image; //controles public var left = false; public var right = false; public var up = false; public var down = false; ... } 49
  • 50. public class Car extends CustomNode{ ... public override function create(): Node { return ImageView { image: image translateX: bind x – 15 translateY: bind y - 7.5 rotate: bind -Math.toDegrees(angle); }; } ... } 50
  • 51. public class Car extends CustomNode{ ... function updateTurn(factor: Number):Void{ if(left != right){//xor var t = if(left) TURN else –TURN; angle = (angle + t*factor) mod RAD360; } } ... } 51
  • 52. public class Car extends CustomNode{ ... function updateAcel(factor: Number):Void{ if(down){//freiando vel = Math.max(VMIN, vel - ACEL*factor); }else if(up){//acelerando vel = Math.min(VMAX, vel + ACEL*factor); }else{//desacelerando if(vel > 0){ vel = Math.max(0, vel - FRICTION*factor); }else{ vel = Math.min(0, vel + FRICTION*factor); } } } ... } 52
  • 53. public class Car extends CustomNode{ ... function updateMove(factor: Number):Void{ var vx = Math.cos(angle) * vel * factor; var vy = -Math.sin(angle) * vel * factor; var i = x + vx; var j = y + vy; x = i; y = j; } ... } 53
  • 54. public class Car extends CustomNode{ ... public function update(time: Long):Void{ var factor = time / 1000.0; if(factor == 0) return; updateTurn(factor); updateAcel(factor); if(vel != 0){ updateMove(factor); } } ... } 54
  • 55. 55
  • 56. public class Game extends CustomNode{ public-read var car1 = Car{}; public-read var car2 = Car{}; var lastTime: Long; function update():Void{} var timeline = Timeline {} public function reset():Void{} public function play(){} var bg = Rectangle{}; init{} public override function create():Node{} } 56
  • 57. public class Game extends CustomNode{ ... public override function create():Node{ Group{ content: [ bg, car1, car2, ] } } ... } 57
  • 58. public class Game extends CustomNode{ ... function checkKey(code: KeyCode, value: Boolean){ if(code == KeyCode.VK_LEFT){ car1.left = value; }else if ... } function onKeyPressed(e:KeyEvent):Void{ checkKey(e.code, true); } function onKeyReleased(e:KeyEvent):Void{ checkKey(e.code, false); } ... } 58
  • 59. 59
  • 60. var game = Game{}; Stage { title: "RaceFX" scene: Scene { width: 640 height: 480 content: game } } 60
  • 61. 61
  • 62. 62