programming

Articles on or about Programming

Boolean algebra

Brief introduction to Boolean algebra (or propositional Logic)

When writing conditional statements, such as if (condition) { ... } else {... }, its helpful to have a basic understanding of the laws of logic (or more formally Boolean algebra) that connect conditional statements together. These can be described by the operation of just 3 connectives, They are

Array data structure

Javascript Array Object

An array is a data structure common to all modern programming languages. Arrays are temporary data structures, that is they only exist so long as the program is running. Once the program is terminated any data contained in an array is lost. To use the built in Array object you must first create an instance of it using the new keyword.

Javascrtipt - creating a TOC

Problem specification - Adding a Table of Contents.

The aim is to be able to show a complete novice to HTML, how to add a Table of Contents (TOC) to a page inside a pair of div tag (with id="toc") provided for this purpose. Initially the TOC should list all H3 headers. and each item in the TOC must include a hypertext link to the relevant (h3) paragraph. Then having established a procedure, to use javascript to achieve the same result automatically.

Extended javascript projects

Programming projects (or extended programming examples)

There is no single path to learning any programming language, Sure there are some basic concepts you need to get out of the way first, but after that you learn the bits that are relevant to the current problem.

Polygons and the artistsColour wheel

HTML5 canvas element - polygons and the artists colour wheel

When drawing a circle, the computer program actually draws a polygon, with so many sides it looks like a circle. By actually specifying the number of sides the program can be made to draw regular polygons. The example below shows an octagon. Only some minor changes have been made to the original circle program.

Canvas animation

Javascript animation - Bouncing ball

No tutorial about animation would be complete without a bouncing ball example. For animation to work you need to make use of the built in Javascript timer. The code for this animation is shown below.

Using global variables (i.e. variables specified outside a function) in this way is generally not a good idea; because of possible side effects. A future update of this page should fix this.

HTML 5 canvas - adding text

Canvas element - adding text

A previous example used the following three diagrams as part of a maths refresher. The original diagrams were (of course!) drawn using the canvas element. By placing the mouse over any canvas element on any HTML page, and right clicking on it, you can then save the resulting drawing just as you would for any other image.

HTML5 Canvas

Canvas element - circles and ellipses

Several new elements have been introduced with the release of hTML5. Perhaps the most significant, is the canvas element which now makes it possible to draw, add text and create animations using Javascript. It is also possible to manipulate images.

Objects

Javascript Objects

When considering Javascript objects, its worth remembering that javascript is not confined to HTML, It can be used to manipulate XML, which in turn can be used to mirror the table structures found in a database. In fact many websites and Content Management Systems use databases to store information to be displayed on the site and HTML has become a popular front end for such databases.

Javascript objects, in common with other object orientated programming languages, have both properties and methods.

Math object

Math Object

The Math object provides functions for basic mathematical operations.

Syndicate content