Skip to content

Silveira Neto Posts

JavaFX, getting resources of inside your JAR

br flagTradução: há uma versão em Português desse artigo.

For some classes like javafx.scene.image.Image is easy load an image from a external resource like:

ImageView {
    image: Image {
        url: "http://example.com/myPicture.png"
    }
}

or a resource inside your own Jar file with the __DIR__ constant:

ImageView {
    image: Image {
        url: "{__DIR__}/myPicture.png"
    }
}

But for other classes loading a internal resource (inside your own jarfile) is not so direct. For example, in the article Parsing a XML Sandwich with JavaFX I had to place the XML file in a temp directory. A more elegant way would be:

package handlexml;

import java.io.FileInputStream;
import javafx.data.pull.*;
import javafx.ext.swing.*;
import javafx.scene.Scene;
import javafx.stage.Stage;

class Resource{
    function getUrl(name:String){
        return this.getClass().getResource(name);
    }

    function getStream(name:String){
        return this.getClass().getResourceAsStream(name);
    }
}

var list = SwingList { width: 600, height: 300}

var myparser = PullParser {
    documentType: PullParser.XML;
    onEvent: function (e: Event) {
        var item = SwingListItem {text: "event {e}"};
        insert item into list.items;
    }
    input: Resource{}.getStream("my.xml");
}
myparser.parse();

Stage {
    title: "Map"
    scene: Scene {
        content: list
    }
}

With a simple XML file called my.xml inside your package.



   
   
   
   
   

fileplace

And we get the same result as before, but all files inside our Jars.

References:

My Free Tileset, version 9

More scenes and tiles for the free and open pixelart tileset. Also new monsters and characters but these will be showed in more details in another post.

Scientists discovery that they can’t keep a Gjelly (one of the new monsters) in cages.

lab incident

And also a little medieval scene. A naive princess got a Nhamnham monster as her pet.

cena princessa nhamnham

A new village scene, now with a pier, water, fence and new chars.

cena pier pixelart

There’s a plenty of new tiles. Now that we have a good basic tiles becomes easy to add more tiles.

free_tileset_version_9

Casa com os tiles livres

O Diogo_RBG, de Tocantins,  me enviou esse mapa que ele fez usando o conjunto de tiles que eu tenho postado regularmente no blog.

É uma bela casa, dois quartos, sala de estar, dois banheiros e sala de jantar conjugada com cozinha. 🙂

mapa do diogo

Aqui é ele em ação, funcionando, dentro da engine do The Mana World!

TMW

Eu aproveito pra divulgar o evento que ele participará falando de SDL, desenvolvimento de jogos e também mostrará esses tiles.

EDJA

Visitem também o blog dele e confiram seus excelentes tutoriais de como criar um MMORPG.

NhamNham

A work under progress. A first monster for a big set of monster I want to create. This one is called NhamNham.

nhamnham animoted

NhamNham lives in forests and swamps and can be quite aggressive atacking with his forehead horn.

nhamnham

Here in this picture they organized a attack to a village and are been repealed by soldiers.

nhamnham atacking

My Free Tileset, version 8

One more version of the my free tileset for game development. This little world is beautifully growing, now towards medieval themes. Now is already possible to imagine a typical day in a little rpg village:

tiny rpg village

And here the tileset, eighth version:

free tileset version 8

Changelog:

  • Medieval straw roof house and variations with and without signs, window, chimney and flowers.
  • Signs for weapons, potions and armor store and for hotel.
  • More vegetations.
  • A dirt road.

CEJUG Podcast #2

cejug podcast java
[audio:http://cejug.podomatic.com/enclosure/2009-03-17T08_20_43-07_00.mp3]

O Igo Coelho recebe neste episódio eu e  o Amaury Brasil,  falamos sobre o que é o CCT, PUJ e os temas do próximo encontro dia 23 de março de 2009 na UNIFOR. Apresentando o LWUIT com Daniel Valente e Introdução a programação em Java para a TV Digital com Amaury Brasil.

podcast

Fotos da gravação lá na Fortes.

Parabéns ao Igo Coelho mais uma vez pela iniciativa e a todos que contribuíram para fazer mais esse episódio do CEJUG Podcast acontecer. ;D

BumbaBot-1

I got a simple motor from a broken domestic printer. It’s a Mitsumi m355P-9T stepping motor. Any other common stepping motor should fits. You can find one in printers, multifunction machines, copy machines, FAX, and such.

bumbabot v01

With a flexible cap of water bottle with a hole we make a connection between the motor axis and other objects.

bumbabot v01

bumbabot v01

With super glue I attached to the cap a little handcraft clay ox statue.

bumbabot v01

It’s a representation from a Brazilian folkloric character Boi Bumbá. In some traditional parties in Brazil, someone dress a structure-costume and dances in circular patterns interacting with the public.

776513346_c31db6843b_m

2246467684_49164d3397_m
Photos by Marcus Guimarães.

Controlling a stepper motor is not difficult.  There’s a good documentation on how to that on the Arduino Stepper Motor Tutorial. Basically it’s about sending a logical signal for each coil in a circular order (that is also called full step).

full step

Animation from rogercom.com.

stepper motor diagram

You’ll probably also use a driver chip ULN2003A or similar to give to the motor more current than your Arduino can provide and also for protecting it from a power comming back from the motor. It’s a very easy find this tiny chip on electronics or automotive  stores or also from broken printers where you probably found your stepped motor.

Arduino Stepper Motor UNL2003A

With a simple program you can already controlling your motor.

// Simple stepped motor spin
// by Silveira Neto, 2009, under GPLv3 license
// http://silveiraneto.net/2009/03/16/bumbabot-1/
int coil1 = 8;
int coil2 = 9;
int coil3 = 10;
int coil4 = 11;
int step = 0;
int interval = 100;

void setup() {
  pinMode(coil1, OUTPUT);
  pinMode(coil2, OUTPUT);
  pinMode(coil3, OUTPUT);
  pinMode(coil4, OUTPUT);
}

void loop() {
  digitalWrite(coil1, step==0?HIGH:LOW);
  digitalWrite(coil2, step==1?HIGH:LOW);
  digitalWrite(coil3, step==2?HIGH:LOW);
  digitalWrite(coil4, step==3?HIGH:LOW);
  delay(interval);
  step = (step+1)%4;
}


Writing a little bit more generally code we can create function to step forward and step backward.

My motor needs 48 steps to run a complete turn. So 360º/48 steps give us 7,5º per step. Arduino has a simple Stepper Motor Library but it doesn’t worked with me and it’s also oriented to steps and I’d need something oriented to angles instead. So I wrote some routines to do that.

For this first version of BumbaBot I mapped angles with letters to easy the communication between the programs.

motor angle step control

Notice that it’s not the final version and there’s still some bugs!

// Stepped motor control by letters
// by Silveira Neto, 2009, under GPLv3 license
// http://silveiraneto.net/2009/03/16/bumbabot-1/

int coil1 = 8;
int coil2 = 9;
int coil3 = 10;
int coil4 = 11;

int delayTime = 50;
int steps = 48;
int step_counter = 0;

void setup(){
  pinMode(coil1, OUTPUT);
  pinMode(coil2, OUTPUT);
  pinMode(coil3, OUTPUT);
  pinMode(coil4, OUTPUT);
  Serial.begin(9600);
}

// tells motor to move a certain angle
void moveAngle(float angle){
  int i;
  int howmanysteps = angle/stepAngle();
  if(howmanysteps<0){
    howmanysteps = - howmanysteps;
  }
  if(angle>0){
    for(i = 0;i

In another post I wrote how create a Java program to talk with Arduino. We'll use this to send messages to Arduino to it moves. 

captura_de_tela-bumba01-netbeans-ide-65

[put final video here]

To be continued... :)

OGG com qualidade

Para o controle de qualidade quando encondando vídeos com o FFmpeg use o parâmetro -qscale seguido de um número. Os número podem ir de 1 (melhor qualidade) até 31 (pior qualidade), sendo que 13 já é uma qualidade bem ruim.

Convertendo pro exemplo um vídeo chamado exemplo.flv para um arquivo ogg com a melhor qualidade seria:

ffmpeg -i exemplo.flv -qscale 1 saida.ogg

Sem usar esse parâmetro os arquivos encodados em OGG ficam com uma qualidade mediana. Uma opção bem útil é usar a mesma qualidade do arquivo de entrada, já que não é possível melhorar a qualidade do vídeo mesmo. Para isso existe o parâmetro -sameq. No exemplo anterior bastaria:

ffmpeg -i exemplo.flv -sameq saida.ogg

Com isso eu tenho reduzido os vídeos da minha câmera para arquivos que só ocupam cerca de 1/5 do tamanho original e ainda assim mantém a mesma qualidade.