JavaFX: Blending of 2 images

Blending of 2 images.

If you look at line 36, we are using the difference mode:


The DIFFERENCE mode is defined as: The darker of the color components from the two inputs are subtracted from the lighter ones to produce the resulting color.

package pepsichallenge;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BlendMode;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

 * Blend a coke can and a pepsi can to find the difference.
public class PepsiChallenge extends Application {

    public void start(Stage stage) {
        Image coke = new Image(

        Image pepsi = new Image(

        ImageView bottom = new ImageView(coke);
        ImageView top = new ImageView(pepsi);

        Group blend = new Group(

        HBox layout = new HBox(10);
                new ImageView(coke),
                new ImageView(pepsi)
        layout.setPadding(new Insets(10));
        stage.setScene(new Scene(layout));;

    public static void main(String[] args) {


JavaFX: Drawing a 3D sphere

Drawing a 3D sphere.

package draw3dsphere;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.Group;
import javafx.scene.layout.BorderPane;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Translate;

public class Draw3DSphere extends Application {

    public void start(Stage stage) throws Exception {
        // 3D parts
        Group root = new Group();

        Sphere sphere = new Sphere(20);
        PhongMaterial material = new PhongMaterial();

        PointLight light = new PointLight(Color.WHITE);
        // JavaFX axis: left-top-near is minus, right-bottom-far is plus
        light.getTransforms().addAll(new Translate(-100, -100, -100));

        PerspectiveCamera camera = new PerspectiveCamera(true);
        camera.getTransforms().addAll(new Translate(0, 0, -100));

        SubScene subscene = new SubScene(root, 800, 600);

        // 2D controls
        BorderPane pane = new BorderPane();

        Scene scene = new Scene(pane, 800, 800);

    public static void main(String[] args) throws Exception {


jQuery: A simple slider

This is a simple jQuery slider and notice how I have used the if else statement to determine the state of the slider.

<!DOCTYPE html>
            #hideme { 
        <script src=""></script>
        <p>Hover On Me!</p>
        <div id="hideme"><h3>Rock & Roll</h3></div>

            $(document.body).hover(function () {
                if ($("#hideme").is(":hidden")) {
                } else {



Try The Code


JavaFX: Line and bar chart

When it comes to setting up the bar or line chart, there are a few classes that we can use in JavaFX.  JavaFX provides the line and bar chart objects and in addition, it provides the numberAxis for the x-y axis and also XYChart for plotting the positions of line and bar.

package javafxapplication4;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class JavaFXApplication4 extends Application {

    public void start(Stage stage) {

        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();
        final CategoryAxis cXAxis = new CategoryAxis();

        //Declarations of the 2 types of charts
        final BarChart<String, Number> bc = new BarChart<>(cXAxis, yAxis);
        final LineChart<Number, Number> lc = new LineChart<>(xAxis, yAxis);

        //setting up the bar chart
        XYChart.Series series1 = new XYChart.Series();
        series1.getData().add(new XYChart.Data("A", 200));
        series1.getData().add(new XYChart.Data("B", 50));

        //setting up the line chart
        XYChart.Series series2 = new XYChart.Series();
        series2.getData().add(new XYChart.Data(10, 210));
        series2.getData().add(new XYChart.Data(3, 35));


        Pane pane = new Pane();

        Scene scene = new Scene(pane, 500, 400);
    public static void main(String[] args) {


Styling the Syntax Highlighter

I am using the Syntax Highlighter Evolved by Alex Gorbatchev and for those of you who are curious, this is how I styled the code block.

I have added a border and change the font size to 16px so that it could better fit into the post.

.syntaxhighlighter {
	background-color: white !important;
	border: 1px solid #DADAD9 !important;
	margin-bottom: 20px !important;

body .syntaxhighlighter .code {
	font-size: 16px !important;

body .syntaxhighlighter .gutter {
	font-size: 16px !important;

Checking the width of an image file

There was a plugin in WordPress that I used which allows an image to be uploaded.  This part of the code was done in Javascript and not in PHP.  When the image file is uploaded, I want it to prompt a message if the width of the image is smaller than 700px.

In Javascript, once the file is uploaded, it is put into a file object.  As with any other object, we could get other properties of this file object such as its name.  If the file object is file, we could get the name by using

Making use of file object property, this is how I get the full path of the image file and pass it to img.src to check its width.

var d = new Date();
var mth = d.getMonth() + 1;
var str1;
if (mth == 11) {
    str1 = '//localhost/wordpress/wp-content/uploads/2015/11/';
else if (mth == 12) {
    str1 = '//localhost/wordpress/wp-content/uploads/2015/12/';
var str2 = str1.concat(;

var img = new Image();
img.onload = function () {
    if (this.width < 700) {
        alert('The size of the photo is too small.');
img.src = str2;

Display a youtube link in WP post

In a WordPress post, you might have a custom field which is a Youtube link and as this youtube link is just part of the content, you might want to display it directly in the post.

This is called embedded content and in WordPress, it provides a function called wp_oembed_get:

<?php $embed_code = wp_oembed_get( $url, $args );   ?>

To display this youtube video in the post, you can save this field in wp_postmeta table with the meta_key in the table as youtube_link.

The code is as shown below and you could put it at the end of functions.php found in the WordPress theme.

iPhone Force Touch

“We believe that iPhone’s Force Touch sensor doesn’t directly detect the pressure applied by fingers,” Kuo said. “Instead, it monitors the contact area on which the finger touches the screen to decide how big the pressure is.”

Samsung could totally make use this technique to create its Force Touch technology in its Galaxy phones. By calculating the force using the number of pixels that are in touch with the fingers.

For example, for 100 pixels, it is a force level of 1 and for 1000 pixels, it is a force level of 10.

Call Of Candy

We all know that Activision is the publisher of Call Of Duty franchise and that in another 3 days, on 6th November, the world’s most popular first-person shooter Black Ops 3 will be released worldwide.

Other popular titles that are owned by Activision are Blizzard and World Of Warcraft.  Now there is a new one Candy Crush Saga that will be added to the list. In terms of popularity, Candy Crush Saga could trump them all.

However, we know that the popularity of Candy Crush Saga is declining and I wonder how Activision will revive this game.  Well, maybe call it Call Of Candy?

Apple watch is doing well after all

This could be a surprise to many who had thought Apple Watch would flop.  In fact in the first few weeks, Apple Watch was doing better than the first generation of iPad.  This is important to a lot of us as it means  we would probably have to figure out how to code in WatchOS.