Introduction to JavaScript using p5!

Creating an Ellipse 

To start programming with JavaScript, I used the text editor Sublime, although Brackets (another text editor) was recommended, I am already familiarised with using Sublime, having some previous experiences to using JavaScript in the past. Although my knowledge of JavaScript is limited, using p5.js has allowed me to learn and experiment with the creative aspects of programming in JavaScript for a web document. Using the tutorials provided by the class lecturer "The Coding Train", I was able to begin my study on the basic foundation level of programming in JavaScript.

In the image below is the JavaScript code I will be breaking down in steps to analyse; this is to better understand the process these set of instructions are executing; how they are effecting the web page graphically and functionally.

The "function setup()" block is used from initialisation, and it only runs once. By default, the canvas to which things are drawn into is sized 100x100, however a custom size can be set using "createCanvas();" function. Using this function draws a new canvas that allows users to manipulate the size of the canvas, increasing or decreasing the canvas scale. Lastly, "print("setup function");" simply displays the data which was called, in this case, the data called is written to the browser console. Individual elements within the function can be separated with "" or join with the addition operator +.  

The "function draw()" block runs in a continuous loop, this block is used for animation, or to typically "draw" into. Within the draw block is an if statement; if the mouse key is pressed, an ellipse with a fill value of 0 (black) will be drawn onto the canvas, else (or otherwise) draw an ellipse with the fill value of 255 (white). In this scenario, the cursor acts like a paint brush, printing ellipse's onto the canvas non-stop.

The "background();" function is used to alter the background colour of a canvas, it does this by using either a grey-scale integer value "background(#);", RGB integer values "background(#, #, #);",  or a hexadecimal RGB notation "background('#111111');", however, there are many other ways of defining a colour value within the background() function.
The "ellipse()" function normally uses 4 different values; positions left and right, with height and width. In this case, the position is determined by the position of the mouse cursor, and the height and width have been given the same value of 80 pixels. The "console.log();" function is often used for debugging code, it allows users to script log data to the JavaScript console.

Comments

Popular posts from this blog

Pure Data: GEM

Purr Data: GEM

The Enduring Ephemeral, or the Future Is a Memory