Tag Archives: javascript

WebGL – sound visualizer with Three.js .

First you need to create one html5 default webpage.
Also you need to add the three.js library to your file.
Add your MP3 file to your folder project.
I named my mp3 file with your_sound_file.mp3.
Because you used three.js javascript file you need to have this functions:init, animate, onError.
To used the audio file you need to have this functions: Play and Load.
The visualizer is make with NewLine function.
This function make one material with one line with green color: 0x00ff00.
If you take a look to the source code will see is simple.
… and result is this:
see the source code:
<!doctype html>
<script src=”js/three.min.js”></script>

var scene, camera, renderer, line;
var geometry, material, mesh, array;

function init() {

scene = new THREE.Scene();

camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;

renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );

document.body.appendChild( renderer.domElement );


function NewLine() {


var material = new THREE.LineBasicMaterial({
color: 0x00ff00

var geometry = new THREE.Geometry();

array = new Uint8Array(analyser.frequencyBinCount);

var Ypoints = array;
var xPoint = -2048;
for(var i=0;i<Ypoints.length;i++) {
geometry.vertices.push( new THREE.Vector3( xPoint, Ypoints[i], 0 ) );
xPoint = xPoint + 4;

line = new THREE.Line( geometry, material );
scene.add( line );

function animate() {

requestAnimationFrame( animate );
renderer.render( scene, camera );


window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();

function Play(buffer) {
var source = context.createBufferSource();
source.buffer = buffer;

analyser = context.createAnalyser();



function Load(url) {
var request = new XMLHttpRequest();
request.open(‘GET’, url, true);
request.responseType = ‘arraybuffer’;

request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {

}, onError);

function onError() {

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

JavaScript – clickable area example.

This example use a simple way to see the mouse position.
The area where you make click with the mouse.
You have two variables: mouseXPos, mouseYPos.
The function(e) take the mouse position and show the result.
<!DOCTYPE html>
<title>Title of the document</title>
<script src=”../js/jquery-2.2.0.js”></script>
<style type=”text/css”>
html, body { text-align: center; }
div {
background: grey;
cursor: pointer;
display: inline-block;
font-size: 3em;
margin: 2em auto;
padding: 2em;
p {
background: grey;
padding: 1em;
<script type=”text/javascript”>
window.mouseXPos = 0;
window.mouseYPos = 0;

$(function() {
$(document).on(‘click’, ‘#clickable_area’, function(e) {
mouseXPos = e.pageX;
mouseYPos = e.pageY;

$(‘p’).text(mouseXPos + ‘:’ + mouseYPos);
<div id= “clickable_area”>a click area</div>

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

Random circles with jQuery.

If you don’t understand all of my tutorials then you need to take a look of this tutorial.
You need a default html5 template. Into this html5 will add the css – Cascading Style Sheets, link to jQuery, and our javascript.
You need to include into project the jQuery. Download the jQuery from internet and put into same folder with your html5 file.

You need to put css for each html tag and will do that with:

Into body tag will put the window canvas and the javascript to draw into canvas.
First after body tag will come with:

The next step is to draw into canvas with javascript by using canvas into 2D – dimensions:

The basic issue is to fill the webpage with circles. All circles will be make random with this parameters: color, x, y, radius, orbit and speed.

All circles will be make like one array:

You need also to make all vars and this functions: r256, reset, resize, render.
When you used render function then you need to put also this function: requestAnimationFrame(render);
The r256 is one function for random up to 256. Is used most for colors ( red – green – blue ) range.
The reset function will make 160 circles.
The resize will resize the canvas with circles.
The render function will clean, fill and move all circles and then will make another frame for us with requestAnimationFrame function.
All variables and math functions is used for draw and show the canvas, circles, move and color stuff.
I don’t want to explain this steps because is very simple and also the goal is to understand the basic structure of the script.
Let’s see the full source code.

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

Rate this with jQuery.

The main index.html file come with this source code:

<!doctype html>
<meta charset=”utf-8″>
<title>Emoticons – rate this …</title>
<link href=”ratethis.css” rel=”stylesheet” type=”text/css” />
<script src=”jquery-2.2.0.js”></script>
<script src=”ratethis.js”></script>
<input type=”hidden” value=”amo” class=”rate_it”/>
$(‘.rate_it’).ratethis(); </script>

The ratethis.css come with this source code:

.ratethis  { display: none;padding-bottom:8px;padding-top:8px;padding-right: 8px;
padding-left: 0px;box-sizing: border-box;background: white;color: white;position: absolute;
width: auto;height: 65px;line-height: 25px;border-radius: 50px;transition: .25sease-in-out;color:black;
border: 1px solid #eee;
-webkit-box-shadow: 4px 4px 21px -9px rgba(0,0,0,0.75);
-moz-box-shadow: 4px 4px 21px -9px rgba(0,0,0,0.75);
box-shadow: 4px 4px 21px -9px rgba(0,0,0,0.75);}

.ratethis  div{margin-left: 8px;float: left;width: 48px; height: 48px; cursor: pointer; transition: all 0.2s ease;}
.selectorFace{margin-left: 8px;float: left;width: 48px; height: 48px; cursor: pointer; transition: all 0.2s ease;}
.ratethis  div:hover{ -webkit-transform:scale(1.25);-moz-transform:scale(1.25);-ms-transform:scale(1.25);-o-transform:scale(1.25);transform:scale(1.25);}

.molesto{ margin-left: 8px;float: left;width: 48px; height: 48px; background: url(test.png) 0 0; }
.asusta{background: url(test.png) 0 -48px; }
.divierte{background: url(test.png) 0 -96px; }
.gusta{background: url(test.png) 0 -144px; }
.amo{background: url(test.png) 0 -192px; }
.triste{background: url(test.png) 0 -240px; }
.asombro{background: url(test.png) 0 -288px; }
.alegre{background: url(test.png) 0 -336px; }

.MessageText{display:none;position:absolute;border:1px solid #333;background-color:#161616;
border-radius:5px;padding:3px;color:#fff;font-family: sans-serif;font-size: 12px;}

.IconoPequenio{width: 24px;height: 24px; background-size: 24px; background-repeat: no-repeat;}

The javascript file ratethis.js come with this source code:

$.fn.extend({ratethis: function(options) {

var ratethis=this;
var varSelect=”Selector”;
var icon_description=”–“;
defaults = { allicons:[
{“emocion”:”amo”,”TextIcon”:”I love him”},
{“emocion”:”molesto”,”TextIcon”:”It bothers me”},
{“emocion”:”asusta”,”TextIcon”:”It scares me”},
{“emocion”:”divierte”,”TextIcon”:”I enjoy”},
{“emocion”:”gusta”,”TextIcon”:”I like it”},
{“emocion”:”triste”,”TextIcon”:”It saddens me”},
{“emocion”:”asombro”,”TextIcon”:”It amazes me”},
{“emocion”:”alegre”,”TextIcon”:”I am glad”}
var options = $.extend({}, defaults, options);

$(ratethis).each(function( index ) {
var UnicoID = Date.now();
$(this).attr(“class”,$(ratethis).attr(“class”)+” “+UnicoID);
var FirstSelect=”alegre”;
FirstElement=FirstElement+'<div data_info=”‘+icon_description+'” ‘;
FirstElement=FirstElement+'”  class=”‘+varSelect;
FirstElement=FirstElement+’ selectorFace ‘+FirstSelect+'”></div>’;

$(document).ready(function() {
All_Icons='<div class=”ratethis”>’;
$.each(options.allicons, function(index,emo ){
All_Icons=All_Icons+'<div data_info=”‘+emo.TextIcon;
All_Icons=All_Icons+'” class=”‘+emo.emocion+'”></div>’;
$(‘.ratethis div’).hover(function(){
var title = $(this).attr(‘data_info’);
$(this).data(‘tipText’, title).removeAttr(‘data_info’);
$(‘<p class=”MessageText”></p>’).text(title).appendTo(‘body’).fadeIn(‘slow’);
},function() {
$(this).attr(‘data_info’, $(this).data(‘tipText’));
}).mousemove(function(e) {
var RatonX = e.pageX – 20;var RatonY = e.pageY – 60;
$(‘.MessageText’).css({ top: RatonY, left: RatonX })
$( ‘.’+varSelect ).hover(function(e) {
SelectEmoticon= $(this);
var RatonX = e.pageX – 20;var RatonY = e.pageY – 60;
$( “.ratethis” ).css({ top: RatonY, left: RatonX });
$( “.ratethis” ).show();
$( “.ratethis div” ).click(function() {

SelectEmoticon.attr(“class”,varSelect+” selectorFace  “+$(this).attr(‘class’));


$(document).mouseup(function (e){  $( “.ratethis” ).hide();});


You will need also one test.png image width / height = 48 x 384 with 8 emoticons.

All of this file and jquery-2.2.0.js will be into your folder project.

About how is made is one selection over icons with one id.

You will see also text for each emoticon and the result will be show on your project webpage.

NOTE: This example is a fork for code by oscaruhp.
I make some changes to see how you can used.
You can see all project on this:

# FaceMocion

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

Simple shadow text with CSS with webkit-filter.

This simple example will put one shadow to the text.

The source code is simple and the goal come with filter and webkit-filter: drop-shadow.

<!DOCTYPE html>
<title>Exemple text shadow.</title>
width: 300px;
height: 300px;
float: left;

-webkit-filter: drop-shadow(5px 5px 5px black);
filter: drop-shadow(5px 5px 5px black);

<div class=”element”>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer feugiat lectus placerat sem tincidunt consequat. Nullam euismod enim vel ante cursus accumsan. Fusce pulvinar rhoncus luctus.</div>

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