Coding

 

 

Creating 2-D Animations on Canvas - interactive colour ball

In this tutorial, you will learn the following:

  • How to create any colour using the three primary colours - red, blue and green.
  • How to make 16-million colours using a value between 0 and 255 for each primary colour.
Finding a good book to master HTML5 can be very challenging: there are so many around - most with eye-catching titles and very complex substance.
Therefore, Vivax Solutions strongly recommends Core HTML5 Canvas for those who really want to delve into HTML5.
Please click the image to access Amazon:

Interactive Colour Ball

The animation allows you to use the three primary colours - red, gree and blue - to produce any other colour that you can think of.

In theory, it can produce 16-million colours, depending on the values of red, green and blue.


Red:        0   255

Green:  0   255

Blue:     0   255

 

The range element may not work with Mozilla Firefox.



The Code for Interactive Colour Ball

<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var radr;var radg;var radb;
function fun() {
// red value;
radr=eval(document.getElementById('redp').value);
// green value;
radg=eval(document.getElementById('greenp').value);
// blue value;
radb=eval(document.getElementById('bluep').value);
// rgb value for fillStyle
var col='rgb('+radr+','+radg+','+radb+')';
context.clearRect(0,0,400,300);
context.beginPath();
// colour circle
context.arc(200,150,100,0,2*Math.PI,false);
context.fillStyle=col;
context.fill();
}
</script>

 

All Canvas Animations

 

 

 

Recommended Reading

Amazon Best Seller

 

Everything is evolving; so is the layout of a text book. By uniquely presenting the rich contents of the book, the author has elevated positive user experience of reading a text book to a new level: the examples are easy to follow and rich in standard. Highly recommended for those who want to master JavaScript and JQuery.

Progressive Web Apps(PWA)


 

The significance of app stores is over; progressive web apps is the next big thing. They are just websites that makes the need of going through app stores and need of storing redundant. They work offline too. If you have a reasonable understanding of HTML, CSS and JavaScript, this is the book for you to learn in no time.

HTML5 Canvas Animations


 

David Geary, in this book, shows how to combine JavaScript and HTML5 Canvas to produce amazing animations; he has set aside a whole chapter to teach you the role of physics in animations. If you want an in-depth understanding about HTML5 Canvas animations, this is a must read.