Pular para o conteúdo principal

Postagens

Mostrando postagens de janeiro, 2017

Have fun creating JavaFX 2d games

After the  pong game , today I had a good time creating another small JavaFX game. This time, a little more playable game. I think JavaFX is the best plataform to create games nowadays. No external dependency is required to create a playable and rich game. To the game which code you can see below, I spent about 3 hours and I could continue adding features to it, but I just wanted to do something else. But why JavaFX is so great about creating games? Hardware acceleration  for rendering of graphics comes by default; It is available on Oracle Java JDK and also with OpenJFX project (no additional dependencies); It has a canvas that is equivalent to the HTML 5 canvas; It can play sound, video and has Java networking by default and a lot of Java platform benefits You can port JavaFX to a mobile using  Gluon / JavaFX Ports  (in fact, I  did this already  and I still have the stacker game running on my mobile); It has 3d capabilities; You can po...

Pong Game in JavaFX using 90 lines of code

A pong game implementation using 90 lines of Java code only. It is possible to write with less lines, but it would make the code unreadable. To run it: * Download the source and save it to a file called Pong.java * Using JDK 8, run: javac Pong.java  and then java Pong You can improve the game mainly by changing its AI - now basically the enemy follows the ball. See the code below.

Some visual effects and data visualization apps using JavaFX

In this post I am going to show some visual effects I have created with JavaFX which I have posted in my portuguese JavaFX blog . We see cool visual effects in JavaFX since its 1.x version. For example, I have this great book from Lucas Jordan : In this book Lucas Jordan explore known Graphics Computer algorithms using JavaFX Script. I missed a book like that for JavaFX 8 and the reason is that it is really fun to create visual effects... Fortunately I have seem Daniel Shiffman creating a lot of cool apps almost weekly! In my last post I talked about a class that help us to quickly create visual effects with JavaFX . Since then, I created a few, and in this post I will share it with you. The big Red Ball This is a quick sample showing how to write pixel by pixel of a canvas. Supershapes Create  super shapes using JavaFX Flowers The algorithm to create it was based on Daniel Shiffman implementation . Metaballs The metaballs effect us...

Escape the JavaFX maze using Genetic Algorithms

In Genetic Algorithms with Java post I presented a "escape the maze" example. In this post, I will share with you a JavaFX application used to control the genetic algorithm execution and visualize the directions after running the evolution. The JavaFX application can generate mazes with the number of blocks (walls), columns and rows you select. You can also change the evolution parameters, such as the population, the genes multiplier (it resolves to columns * rows * genes multiplier and it determines the number of genes - directions or steps) and you can also choose the number the generations before evolving. To be honest, I spent hours playing with it and you can play with it as well! You just need Java and Maven: First we must install DrawingFX :  http://fxapps.blogspot.com.br/2017/01/quick-visual-effects-apps-development.html To install DrawingFX, clone:  https://github.com/jesuino/drawing-fx then cd into it and run: mvn clean install Now let's clone genet...

Genetic algorithms with Java

One of the most fascinating topics in computer science world is Artificial Intelligence . A subset of Artificial intelligence are the algorithms that were created inspired in the nature. In this group, we have Genetic Algorithms  (GA). Genetic Algorithms  To find out more about this topic I recommend the following MIT lecture and the Nature of Code book and videos created by Daniel Shiffman. Genetic Algorithms using Java After I remembered the basics about it, I wanted to practice, so I tried my own implementation, but I would have to write a lot of code to do what certainly others already did. So I started looking for Genetic Algorithm libraries and found Jenetics , which is a modern library that uses Java 8 concepts and APIs, and there's also JGAP . I decided to use Jenetics because the User Guide was so clear and it has no other dependency, but Java 8. The only thing I missed for Jenetics are more small examples like the ones I will show i...

Quick visual effects apps development with JavaFX

Processing is a great programming language based on Java with versions for Javascript and for Python. If you don't know it, just watch a few Daniel Shiffman videos to quickly fall in love with this technology. I talked about processing and JavaFX in this post . JavaFX is great as well and it is available in the JDK 1.8 - which means that no external libraries is required to create JavaFX applications. In this article I will show you a class I have been using to approach JavaFX to the Processing programming style. This is not intended to have processing running on top of JavaFX. Processing is big and I would take a few days porting all methods and classes to a JavaFX app. The idea is quickly start drawing instead have to create stage, initializing, etc. Of course, the code is on github, so if you want to contribute a PR is more than welcome! So the idea is: Extend a class; Override setup method to define app title, frames, width, height; Override draw to animate things ...

Sentiments analysis using AFINN in a Java application

Happy and Sad by Michael Coghlan courtesy of Flickr Creative Commons licensed by CC BY-SA 2.0 We talked about sentiments in this blog using a REST API , but today I came across another great Daniel Shiffman video, this time about sentiments and AFINN : Loading AFINN in a Java application Using the TSV file provided by AFINN we can create applications that evaluates sentences sentiments. A simple use of this file is load it in a java.util.Map and use it to check a given sentence or any text contains the key words that help us to identify sentiment and then calculate a score. Let me explain better. Each word has a score associated to it: a positive value is a positive score, a negative value is a negative score. Take for example the words sad and happy : sad        -2 happy 3 Having this in mind we can now take a text, split into words, check every word score and sum them all. If the final score is negative, then the sentence can be considered a...