Tag Archives: javascript

JavaScript – Processing.js 2D library – part 001.

This is part 001 from tutorials series about Processing.js.
The javascript library Processing help us to create one good interface with our javascript.
This library come with many features to show into canvas data and infos and also to create 2D and 3D interfaces.
I used to show this features one online editor named studio sketchpad and can be found here
Using this online editor can help you but if you want to use all features then you need to put the library into your html file.
In this tutorial I just use the online editor and later will come with another tutorials about how to set the library.
Make one account of this online editor if you want to save your work.
The development is simple and has some rules.
The script will have two functions setup – for settings and draw – basically will draw the canvas.

This will fill with functions, statements and all the commands available to Processing.js.
Take a look at page references.
On the bottom of the script can also make classes.
This will be created like this:

As can we see classes comes without void and args ().
Let’s how it’s works classes by using two : Ball and MovingBall.
If you want to make one class and then you need to used then use this steps:
– create the class Ball;
– add two functions: update and display;
– add also the possition of the class by using two float variables x,y ;
– because any class need to have one instance then you need one,so put this instance into the class and named like the class Ball;
– this instance will need to take the possition and then to used so you need also two variables: _x and _y;
– if you want to show it then also you need a display function with some 2D/3D primitives;
Also the classes can be created not just to show you the 2D/3D primitives.
Let’s see the source code of this class named Ball.

Let’s make another class named MovingBall.
This class will be like the Ball class and will be extended by Ball class.
This means the all content of Ball class can be used or not by MovingBall.

This MovingBall has the MovingBall extends the Ball with _x,_y and also used super to reference the superclass of a subclass. Take a look where is put the variables x,y and _x,_y into the Ball and MovingBall.
The Ball will get _x,_y possitions and will give it to x,y, also the MovingBall will follow the same rules.
Now I will add one function to MovingBall named drawline, see:

This will set the sets the color used to draw lines and borders around shapes with stroke function and will make one line from x,y to 0,0.
When will run this function will have one line.
Let’s see the MovingBall class:

The first step when you want to using this library is to know how to set the canvas and how to change it.
The size of this canvas can be done with this function: size.
For example : size(400,400) means 400 pixels x 400 pixels.
The background can be change it with background() function and sets the color used for the background.
The smooth function will draw all geometry with smooth (anti-aliased) edges.
Because we want to draw something then you need to fill the setup and draw functions.
Also into setup function will put the new created classes and will used into draw function to draw.
Let’s see the final source code:

You can see my example here:

Posted in All, HTML 5, javascript, Programming. Tagged with , , , , , , .

News: jQuery 3.0 Beta Released.

The team member of jQuery Core – Timmy Willison tell us in a blog post about Query 3.0 Beta Released.
Developers with jQuery 3.0 alpha had experimented with methods like an inline-display-none-remover (.show()) and inline-display-none-adder (.hide()) and removing inline display:none did not always show the element.
Fix the custom selectors like :visible make is up to 17 times faster now.
Link jQuery with :

…or get the beta version from npm:

Posted in news. Tagged with , , , , .

Make firefox addon with node.js and jpm – part 001.

Download the npm from nodejs official website.
Run the windows downloaded program and make your testing directory and run the npm:

The next step is to run the instalation of jpm with this:

Will see also the folders where is the new jpm.
To make your addons you need to login into your firefox dev account and take one generate API credentials.
Then run this commands and fill with data the new addon, like you can see in the next example:

I have this files into my folder free-tutorials.org_addons:

The my_user is my user and you will have the name of your user.
Use the next command to build an XPI.

Into this moment the addon is not signed. If you use about:config will see this:
npm_jpm_addon_signature
Use this link to submit the addon. You need to upload your XPI file and also to follow the steps from mozilla website.
When you done the you can see your addon.
My default example addon version 0.0.1 can be found here: free-tutorials.org addon.
The addon is not signed yet so will need to set xpinstall.signatures.required to false from about:config if you want to install it.
I will make another tutorial about how to do the signed process.

Posted in All, node.js, Programming, web, Windows 10. Tagged with , , , , , , , , , , , .

JavaScript – Pixi.js 2D library – part 001.

Today I will show you how to deal with Pixi.js.
Also it’s Winter holidays and Christmas traditions in Romania like: the Bear dance, the Masked carolers and the Goat.
This make me happy and I will use one image with: the Bear dance.
The Pixi.js library provide a fast lightweight 2D renderer.
First you need to download the javascript pixi.js from pixi github project.
I used two image files: datini.jpg, bur_effect.jpg and one png mask file named mask.png.
images001
The scrip is very simple:

The output is this:
pixi001_output
In case you want to see it live the try this link.

Posted in All, HTML 5, javascript, Programming. Tagged with , , , , .

GoJS with random function example.

This is a simple example with GoJS API.
If you want to use into website the you need to buy the API.
Also you can make a try with this example but will have this text:
test

<!DOCTYPE html>
<html>
<head>
<script src=”go-debug.js”></script>
<script id=”code” type=”text/javascript”>
function init(){
var $ = go.GraphObject.make;
var myDiagram =
$(go.Diagram, “myDiagram”,
{
initialContentAlignment: go.Spot.Center, // center Diagram contents
“undoManager.isEnabled”: true,// enable Ctrl-Z to undo and Ctrl-Y to redo
initialContentAlignment: go.Spot.Center,
allowZoom: true,

“grid.gridCellSize”: new go.Size(20, 20),

});

var myModel = $(go.Model);
// in our model data, each node is represented by a JavaScript object:
myModel.nodeDataArray = [
{ key: getRandomColor() },
];

myDiagram.model = myModel;
myPalette =
$(go.Palette, “myPalette”,  // must name or refer to the DIV HTML element
{
nodeTemplate: myDiagram.nodeTemplate,
model: new go.GraphLinksModel([  // specify the contents of the Palette
{ key: “Alpha” },
{ key: “Beta” },
{ key: “Gamma” },
{ key: “Delta” }
])
});
} //init

function getRandomColor() {
var letters = ‘0123456789ABCDEF’.split(”);
var color = ‘#’;
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}

</script>
</head>
<body onload=”init()”>
<div style=”width:100%; white-space:nowrap;”>
<span style=”display: inline-block; vertical-align: top; padding: 5px; width:80px”>
<div id=”myPalette” style=”border: solid 1px gray; height: 400px; background-color:#CCCCCC;”></div>
</span>

<span style=”display: inline-block; vertical-align: top; padding: 5px; width:80%”>
<div id=”myDiagram” style=”border: solid 1px gray; height: 400px; background-color:#CCCCCC;”></div>
</span>
</div>
</body>
</html>
The source code will make two areas with four text and the next area will have output of random javascript random function. See this image:
test2

Posted in All, javascript, Programming, web. Tagged with , , , , .