Making Java Great Again Part 2

Language Building Blocks

Now that we got some important concepts let us take a look at the language itself.

Comments

Comments are used to document your code. Writing comments in your code while you are learning as well as developing is a very powerful habit to obtain. These comments can be used by other developers that might come along later to maintain or modify the code you wrote. Also comments can be extremely useful to you the author-many times to help you remind why you did something a certain way or why you didn’t do something.

Single Line, Multi Line & Doc comments

Single line comments begin with // and then your comment. The compiler will ignore anything written between // and the end of the line. Multi line comments begin with /* can span multiple lines but must end with */ and like the single line, everything written between the /* and */ will be ignored by the compiler. Doc comments begin with /** and can also span multiple lines but must end with */ The compiler ignores everything between the /** and */ then are used by Javadoc utility to generate HTML documentation for your program.

Identifiers & Data Types

Identifiers

An identifier is a sequence of characters used to name a variable, method class or package. A Java identifier must adhere to the following rules.

  • It cannot span multiple lines
  • It must only contain numbers, letters, underscores, dashes, and dollar signs.
  • It must start with a letter, underscore, dash or dollar sign.
  • It cannot contain any spaces

Before creating an identifier, research the Java reserved keywords; because you cannot use them as identifiers.

Data Types

Data types describes the internal representation of a piece of data and the operations that can be applied to the data. Java has two kinds of data types: primitive and developer defined. Research all the Java data types with any search engine like google.

Literals, Variables & Expressions

A literal is a sequence of characters that represent a data item in the program. Java has six data literals:

  • Boolean : Reserved words True and False are boolean literals
  • Character : A character literal is represented by a single character
  • Floating point number : A number with a decimal
  • Whole number : Pretty self explanatory….A whole number
  • Null : Research via google
  • String : a sequence of characters surrounded by double quotes
Variables

A variable is a named piece of memory where you can store the value of something. To store that value you must declare your variable like : data_type variable_name;

Expressions

An expression is a statement that can be evaluated to produce a result. The result of the expression can be used in your program. Expressions can be simple or complex but in the end they are all made up of the same components- operators and operands. If you are not familiar with the terms operators or operands, well then google it…=]

 

Making Java Great Again….Part 1

Java History

I have the pleasure to learn Java through an amazing instructor and with some great classmates. Java is a general-purpose programming language that is class based, object oriented and is designed to run with different operating systems. Java applications are usually compiled to bytecode that can run on any Java virtual machine regardless of the computers platforms-as long as there is the Java virtual machine installed. As of 2018, Java was one of the most popular programming languages in use according to GitHub.

Java was started by James Gosling, Mike Sheridan and Patrick Naughton in June of 1991. Java was originally designed for interactive televisions but became way too advanced for the digital cable television platforms at the time. The language was originally named Oak-which was named after an oak tree that was growing outside James Gosling’s office. Later the language was named Green and then finally named Java from Java coffee. The rest is history, Java was and still is so popular that another programming language that has no link with Java was named after it (JavaScript). Now that we have gone a little in the history of Java, let us begin to learn the actual language.

Getting your machine ready for Java programming

So first things first, Java wont run on a normal text editor like sublime or atom unless you have modified the text editor with certain plugins which we may or may not get into in further post, but for now we will download and use Netbeans but first we must install JDK or Java Development Kit. This contains the compiler (the program that converts instructions into a “machine-code” or “lower level” form so that it can be understood and executed by the computer. FYI make sure with macs you download the right netbeans version because I have experienced and also herd others downloading the newest version and it was not working, so be mindful of that.

Netbeans

Now that we have everything we need to start writing Java code, let us begin with the basics. Netbeans has many built-in features there to help the developer perfect his code. There is Syntax highlighting, which makes the code easier to read by applying different colors to certain elements, code completion and Intellisense which gives you hints and improves your coding speed by autocompleting certain code and gives you hints in many instances to write your code more efficient. When code is written wrong there is error highlighting and correction hints that try and help you solve the problem at hand. The debugger feature in my opinion is one of the most important of the bunch. This allows you to step through your code line by line while the program is running-which allows you to see how your code is executing and will help you uncover problems when you are not getting the desired outcome of your program.

Key Concepts

Computer

First will be to understand exactly what we are programming to….A computer. A computer is exactly was it sounds like- an electronic device that processes or computes data according to a set of instructions contained in a program.

Data & Information

Data and information are two words that very frequently are used interchangeably but actually have different meanings. Data is the facts and statistics collected from which information is then built from. Information is the analyzed data, and with the analysis of the data-it then has a meaning.

Programs & Programming

A program is a set of instructions that, when run on a computer, will solve a particular problem. Programming is the action of writing those instructions for the computer to solve the problems at hand. The computer only does what you tell it to do so this entails that you must be able to solve a problem on paper before you can be able to instruct the computer on how to solve it.

Models, Metaphors & Objects

We use models to set classes that will “model” the objects associating with creating, editing, and building a Java program and then we calculate the result. One of the most important metaphors that we use in Java is the Object. This metaphor is not used only in Java but used in all object oriented languages.  Objects represent a “object” which has its own properties such as weight, volume, color, & can also have actions that they can perform like walk, run, jump, fly etc.

Specifications, Syntax & Semantics

Specifications are a very important to the process of writing software. They tell us what problem we have to solve. With out that, we wouldn’t know what kind of program to write. They do not have to be pages and pages, as long as there is a problem stated and then any constraints around the problem to be aware of, that will do it. Syntax is important to actually compiling your code, but as you’ll learn; it is just as important to understand the meaning and purpose or “semantics” of the various language constructs and how and when to use them to solve a problem.

JavaScript [part1]

JavaScript is a programming language that has become in use for Front and Back end applications. It brings a page to “life” so to speak. It makes your page dynamic and interactive with your user. The difference between JavaScript or JS for short compared to HTML and CSS is that HTML & CSS are only markup languages and cannot perform any functions where in JS you use logic to make the page do what you need it to do.

You start by linking your JS page to your HTML similiar to the way you would for CSS but instead of using the <link> tag you would use the <script> tag. Normally you would like to put this <script> right above the ending </body> tag to help ensure your HTML and CSS code loads up on your page before the JavaScript does-this will eliminate headaches and problems in the future. It will look something like <script src=”yourfilename.js>.

There are different types of values you can use in JavaScript- Number, Boolean, String, undefined, and Null. For now we will focus on the first 3 since in my opinion they are more common.

Number values are exactly what you would think they are numbers. Whole numbers are integers and fractional numbers with decimals are referred to as floats. These number values can be used to perform arithmetic using mathematical operators such as addition, subtraction, multiplication and division-but the one where you rarely will learn in highschool is the modulo which looks like a percentage sign % but it actually performs division but it only returns the remainder of the operation. This might sound impracticable but is very useful especially when you want to find if a number is even or odd. If you “mod” a number by 2 and it returns a 0 that indicates the number is even, if it returns a 1 then your number is odd – 9 % 2 returns a 1 because its 4 remainder 1.  Speaking of highschool, remember (“Please Excuse My Dear Aunt Sally”) or PEMDAS -parenthesis, exponents, multiplication, division, addition, subtraction- The order in which mathematical operations are executed matters. Whatever expression is in the parenthesis will be executed first then exponents, multiplication etc. So keep this in mind while you are writing logic in js.

Boolean Values have only two possible values, True or False. Boolean value is can be thought of as a polygraph test-it is testing to see the truth in something.

A string value is a collection of characters wrapped in quotation marks. You can use either single quotes ‘ ‘ or double quotes ” ” to encapsulate your characters. You must stick with either or when you are wrapping up your characters-if you start with single quotes you must end with them as well. For example “this is valid” but “this is not valid’ or ‘this” . If you would like to write a sentence that contains quotes in it; you would need to use different style quotes for the entire string and for the characters that need quotes. For example ‘this is a string “using different style quotes” within the string’. You can add line breaks to string values using the /n character; the “n” after the backlash tells the computer you want to start a new line. This is known as escaping the character. You can also use the + operator and in strings case it will combine multiple string values into one string value. This is known as concatenation. 

Other operators besides the mathematical operators are comparison operators and logical operators. Comparison operators are used to compare two values and return a result of true or false. Less than (<), Greater than (>), Less than or equal to (<=), Greater than or equal to (>=), Equal to (==), Strictly equal to (===), Not equal to (!=), Not strictly equal to (!==+). The first five should be obvious. The (===) was added later to JS to fix some confusion with (==). There are some instances where (==) will return true when it is false and vice versa. The (!=) or not equal and the (!==) not strictly equal are used for checking if a value is not equal to another value. All comparisons produce Boolean values.

Logical operators are three- And (&&), or (||) , and Not( !). && is a binary operator which means it will operate on two operands or values to a return a result, so it will take two Boolean values (true or false) and will return a “true” only if both values are true.

true && true results a TRUE

true && false returns a FALSE

The Or operator or (||)- called pipes-will produce a true value if either of the values are true.

true || false returns a TRUE

false || false returns a FALSE

The Not operator (!) will flip a Boolean value that is true to false and vice versa.

!true = FALSE

!false= TRUE

CSS-Using Bootstrap

Bootstrap is the most popular CSS framework for developing responsive and website’s using the “mobile first” approach. Using a mobile first approach to developing your website is creating an online experience for a mobile device first before considering the desktop experience. This is a fairly new phenomenon due to the increase in online traffic from smart phones and other mobile devices. With this in mind Bootstrap comes in very handy when styling pages.

First you want to link the Bootstraps libraries in the HTML document you would like to style. (see pic below)bootStrap1

Then depending on what you are developing; indulge in all resources Bootstrap related to help get you there. For starters you can add a “jumbotron” which is used to display a heading for your page. You can easily style a navigation bar to your liking, add a carousel of pictures to your page or create a professional contact or feedback page that has everything you would need to get the most information from the user.

The best advice I can give to anyone who would like to start Bootstrap is use the internet for information. It is by far the best resource along with trial by fire to learn and understand the functionality that Bootstrap brings to your page.

CSS-Cascade Style Sheet

CSS or Cascade Style Sheet will be key in styling your website. This language will let you add colors, use different layouts and fonts. It also makes your website responsive to the device you are viewing it from, meaning it will adapt to larger screens as well as smaller screens. You can use CSS with html in 3 ways -inline styling, internal style sheet, and external style sheet.

Inline styling is using css to style directly in the line of code that is in your html document. You can do this with writing css syntax inside of the opening tag you want to style such as <body style=”background-color: red”>. The style=”background-color:red” is the inline style. Style is the css attribute that styles the html element.

Internal style sheet is using the <style></style> tags in the head tag of your html document and in those style tags; you put all your css styling. (see pic below).cssInt

For the semantic elements you can just write the name you want to style with curly brackets and then write your styling in those. Other ways of styling elements on page is using # for id’s which can only be applied once and . for classes which can be used many times. You would put them in a tag such as a <div> tag and call them using either class = or id=. (see pic below).cssClass

External style sheets is a separate page where you write your css styling and then link that page with your html document. The same way you would write code in an internal style sheet is the same way you would in an external style sheet minus using the <style></style> tags.

You would link the page using a <link> tag  like this <link rel=”stylesheet” type=”text/css” href=”whatever you name the file.css”> and make sure to place that inside of your head tag. Also make sure you save your external style sheet as a .css (see pic below)cssextern.png

There is way too many ways you can use css to style your page, so play around and have fun styling and learning as you go!

 

HTML-Hyper Text Markup Language

HTML is a language that is used to describe documents. The documents are transferred all across the internet as web pages. The web pages are organized by using HTML elements to describe there purpose. (see pic below)html1revpic

Here is the structure of the HTML documents, by using semantic elements and elements that have specific purposes like headers, paragraphs, lists, and tables of data. Other elements are for displaying an image or creating a hyperlink to navigate to a specific location. There are also elements that allow us to link to external resources like CSS styles or write code in a scripting language like JavaScript. (see pic below)

html2

(I will explain Cascade Style Sheets (CSS), and JavaScript in my future posts but for now lets stick to HTML.)

Think of the page format like a human body. You have your head, body and feet. The same is true for an HTML document. First declare your page an HTML document by typing on the first line of your code <!DOCTYPE HTML> and then open an <html> tag; so you can begin creating your “human”. Type your <head> tag right under your <html> tag and inside that tag put a <title> tag and the text you write in that tag will display inside of the tab in your web browser. (see pic below ex. “The Bay Area’s…”)title1.pngThen you create a <body> tag where most of the content will be placed. You put a <header> tag and that’s where you create the title of your page. Then you could use the <h1>tag to create a heading for the page. (The <h1> tag will have a more profound size and as you go down to <h6> the size will decrease.) The <p> tag is the paragraph tag you would put text in that you want the page to display.  There are a whole trove of tags that you can utilize to help you get the structure and look you want on your HTML page to have. Never forget to close your tags with a close tag, for example a closing tag to a <body> tag will be </body> for a <h1> tag its </h1> so that convention pretty much goes for all tags except for a few such as an anchor tag which is used as a single tag <a> and also an image tag <img>. With all this you are well on your way to creating a website. 

Do you Git it?

What is the purpose of Git?

Git is a revision control system. It is to manage projects as well as files as they change over time. It is a repository which is lets you have each version of your file in order and let it be accessible by others.

What is GitHub?

GitHub is the hosting service for Git- which is the tool that holds and manages files (repository).

Using Git bash-

Git bash is a shell for the Windows Command Line to manipulate Git’s repository. To start you want to find where you are in Git bash. To find your path so you need to type pwd which stands for print working directory and that tells you where you currently are. Below shows how it will look like. In this example my path ispwd.jpg

/c/Users/triplexLJ but I want to get to a folder named repo1 on my desktop so I would need to type cd which stands for change directory and then type  /desktop/repo1 then press enter. You can press pwd to make sure your in the right folder. pwd1

Now I want to add a file named uni.txt to my Github so I first type git add then add the name of the file “uni.txt” and press enter. (see pic below)gitadd.jpg

now you must type git commit -m “write a note that describes file” and press entergitcommit

once that is done you can type git push origin master which will push the file in the GitHub.

gitpush

Now you can check your GitHub account to make sure your file has been received.  There are many other actions that can be done in Git Bash and as I go through them I will post them!

Final Project- mini golf

Game plan-

My final project started out as an idea to make a mini golf game. I had an idea of how to approach this and here is real pseudo code (no pun intended) of what I wanted to do.IMG_0420

It sounded simple but when I started to code this it became very difficult to be able to make my “club” interact with the “ball” so I had to search how to interact using p5.js. I found a library called p5.play, which is  library for p5.js to create games which was very interesting to me. So I started to read about what a sprite is, because that is like the main element for the game. It has built in properties such as displace- which checks if sprite is  overlapping another sprite and then essentially collide the displaced sprite to the closet non-overlapping position. Velocity is also another built in function and that makes the speed of how the sprite or “ball” for this matter will change positions.  displace1

(see pic above) the stars in red are indicating the lines of code to where velocity, overlap, and displace are. when the sprite “club” hits (displace) the “ball” it will be hit with a velocity of 0.2 multipied by mouseY minus the clubs y position. This will let the “ball” move to an unknown non overlapping position. I created all the components to the game by using creatSprite then plugging in arguments. I made an if else statement to log the score of all the balls going in the hole (line 105 in pic above)restofcode.jpg

the other argument in the if else statement is make more than the amount the hole can carry, you will see a new image and text saying you win! will be in the middle of the screen. I was able to keep score going and make the flag move by make the getHole function, which removed the balls from the screen, kept score and had the flag going up every hole in 1. I also added the Boolean variable if keyIspressed to be able and press any key on keyboard to reload ball.

golfgamepic.jpg

(see pic above) This is how the game looks when its running. You drag that “club” with your mouse and hit the white “ball” until you get it inside the square “hole”. Once you do your points go up and so does the flag. (see pic below)midgame

and it will keep going up until you reach 100 and then the next ball you get in the whole..

tiger.jpg

you will see this (pic above) on your screen….YOU WON!

Challenges-

Some of the challenges I faced was first learning the new library I was using. It had different parameters to follow when making objects and functions. Also I was trying to make a start menu with rules and another button to get into the game but it was giving me problems every time I was trying to call functions from the startmenu.js page. I also encountered a problem when created a button function to reset the game. I tried many ways with null results.

If I had more time…

If I had more time I would have liked to made the hole move in  between the grass to make it more challenging, and get rid of that extra ball on the tee. I also would have liked to try and also make the flag change a different color every time you would get the ball in the hole. As well I would like to have that reset button actually work and reset the game. And finally I would like to figure out why if I do not click the screen before playing and I hit any key on the key board the game restarts.

Thank you all!

Vestibule Assesment 3/20/19

Vestibule Assessment 3/20/19;

 

  1. What is P5? How is it distinguished from Processing?

– P5 is a JavaScript library that is designed to help make coding beginner friendly and easier to write. P5.js  is different than Processing because Processing is its own language and P5.js is a library for the JavaScript language.

 

  1. What does IDE stand for? Describe its components.  

– IDE stands for Integrated Drive Electronics. Its components are an electronic interface that interacts between a computer motherboard’s data paths and the computer’s disk storage devices.

 

  1. How do you save a file in the P5 editor? What naming/saving convention might you use?

– In order to save a file on P5 editor you must first create an account by signing up which is free than going to the file drop bar click saving and using a name that describes what your doing in camel case, for ex. If your making shapes with color you might want to save as shapesColor.

 

  1. What is a library? How do you access and use a library with P5?

– A library are files of module code written and stored in object format. Using that module code helps you simplify commands or actions you would want to execute. The library has certain commands that when called can perform task using one or two lines of code instead of 4 or 5 lines of code. You access and use a library by downloading the files on to your computer, than linking the library path to your HTML document which is linked to your JavaScript file.

 

  1. What do the triangle and circular shapes across the top of the P5 editor represent?

– The triangle is the play function on the P5 editor which runs the code that you have written and the circular shape is the stop function.

 

  1. How do you add and name an additional or new tab in the P5 editor?

– You add and name an additional or new tab in the P5 editor by going to the to the left side right beside the sketch.js and click that arrow and there is an arrowing facing down if you click that it will give you options to do that.

  1. Describe the coordinate system in P5.

– The coordinate system in P5 is X axis of the “canvas” which is the screen you will be seeing the code that you write run-the X axis is going horizontal from left to right and the Y axis is going vertical from top to bottom.

 

  1. What is the general syntax and structure for a line of code? Use code to demonstrate your response

 

 createCanvas(400, 400);//this is general syntax for a line of code

 

  1. What is the general syntax and structure for a block of code? Use code to demonstrate your response.

function draw() { //whatever is in the curly brackets becomes a block of code

 background(220);

}

 

  1. Why are certain words in different colors in the P5 editor?

– Certain words are in different color in P5 editor because they are built in functions.

 

  1. What is a system or reserved word in P5? Give an example.

– A system or reserved word is a word that is saved for a specific action that cannot be used in code for anything else but perfroming its pre defined parameters.

 

  1. How does order matter in P5?  Give an example demonstrated with code.

function setup(){

createCanvas(400,400);

}

function draw() {

 //background(92,90,87)//if this comes first, when you run the code it will show background color constant

 if (mouseIsPressed) {

 background(92,90,87);//if you have the background color here, the color will only change if you click

   fill(0);

 }// So where you put each line of code will affect the outcome.

 

  1. What is the difference between mouseIsPressed and mousePressed()? Use code to demonstrate your response.

– function mousePressed() {// this will execute when mouse is pressed only one time

 background(bgSwitch);

 noStroke();

 fill(0, 0, 255);

 ellipse(width / 2, height / 2, diam, diam);

}

function draw() {

 background(0);

 stroke(255);

 strokeWeight(4);

 noFill();

 

 if (mouseX > 300 && mouseX < 400 && mouseY > 200 && mouseY < 300) {

   if (mouseIsPressed) {//this will execute its parameters every time the mouse is being pressed

     background(0, 255, 0);

   }

   fill(255, 0, 200);

 }

   rect(300, 200, 100, 100);

}

 

  1. What called function must always be first in setup()?

createCanvas();

 

  1. What is the difference between an inline comment and a block or multi-line comment? Use code to demonstrate your response.

function setup() {

 createCanvas(400, 400);//this is an inline comment

}

 

function draw() {

 background(220);

}/*This is block or multi

line comment */

 

  1. Does whitespace matter in P5? Capitalization? Use code to demonstrate your response.

function         setup() {//the whitespaces do not effect

 //the code but its conventions that you dont have unecessary white space

 createCanvas(400, 400);

}

function Draw() {//this capital D will prevent from running

 background (0);

}

 

  1. What is a variable? What is a data type? What is a value?

A variable is an element that holds a value. A data type is like instructions on what to do with data. A value is what is being defined by variable.

 

  1. What is the difference between a system variable and one that you define? Use code to demonstrate your response

let x = 10;//variable x I defined and has a value

//of 10

 

function setup() {

 createCanvas(400, 400);

}

 

function draw() {

 background(220);

 ellipse(x,200,50,50)//the ellipse is a system variable

 //that holds 4 parameters

}

 

  1. What is scope and how does it impact code? Use code to demonstrate your response.  

There is two type of scope, one is local and the other is global. Any variable declared outside any function (usually on the top of your code) is a global variable and any variable declared in a function is a local variable and can only be utilized within that function

let x = 400;//this is a global variable

 

function setup() {

 let j = 400;//this is a local variable

 createCanvas(j, x);//x can be used as value here

 //because its global and j can be used here because

 //its locally within the function it has been defined

 //in

 

}

 

function draw() {

 

 background(220);

 ellipse(x,j,50,50);//x works here as well as a value

 //but j does not because it is outside the function

 //it was defined in

 

}

  1. What does it mean to declare, initialize and use a variable? Use code to demonstrate your response.

 

// declaring a variable, no value given

let circX;

 

circX = 200;

let circY;

circY = 200;

// Variable declaration and initialization(giving a variable a value) can be done on one line.

let circStroke = 125;

let circR = 55;

let circG = 135;

let circB = 225;

let circSize = 75;

let canvBG = 125;

 

function setup() {

 createCanvas(400, 400);

}

 

function draw() {

 //and then we use the variables

 background(canvBG);

 stroke(circStroke);

 fill(circR, circG, circB);

 stroke(circStroke);

 ellipse(circX, circY, circSize, circSize);

 

21.What happens when a variable is attempted to be accessed outside of its scope?

You will get an error message in the console saying the variable is undefined.

  1. What happens when a variable is declared globally, but is not used?

Nothing happens

 

  1. What value does var nums; have?

No value

 

  1. What are operators in P5? Use code to demonstrate your response using at least one operator.

Operators are used to assign values, compare values, perform math.

 

let lite2 = {//****the equal sign will be the first operator in this code

     x1: 20,

     y1: 10,

     x2: 50,

     y2: 50,

     speed: 1,

     display: function() {//function 1

       stroke(244,241,66);

       strokeWeight(1);

       ellipse(this.x1, this.y1, this.x2, this.y2);

     },

     move: function() {//function 2

       this.x1 = this.x1 + this.speed; //

       this.y1 = this.y1 + this.speed;

       this.x2 = this.x2 + this.speed;

       this.y2 = this.y2 + this.speed;

   }

   }

 

  1. What is a boolean data type?

-A boolean data type is a variable with is often to test if a condition is true or false.

 

  1. List three examples of primitive data types.

– Boolean

– Number

– String

 

  1. Write a code example that increments a value by 5.

let x = 15;

function setup() {

 createCanvas(400, 400);

}

 

function draw() {

 background(220);

 ellipse(x+5,200,50,50)

}

 

  1. Describe the order of operations for: x = speed * 40;

– 40 is being multiplied by the value of speed to give you variable x

 

  1. Write a code example that decreases a value by one using shorthand.

let x = 15;

function setup() {

 createCanvas(400, 400);

}

 

function draw() {

 background(220);

 ellipse(x-1,200,50,50)

}

 

  1. What does the logical operator ! do?

– ! is the void logical operator that is to not return a value.

 

  1. What is an if statement? When should it be used? Use code to describe its syntax.

 

An if statement is used to place a conditional variable and as long as its true to perform a task.

if ((circX > width) || (circX < 0)) {//so this is saying if circX is less than width and greater than 0 then multiply variable speed by -1

  speed = speed * -1;  

 }

}

 

  1. How many if statements can you use? What is an alternative to the if statement?

You can use as many if statements and one alternative to if statements is if else statements or using boolean variable.

 

  1. What is the difference between else and else if? Use code to demonstrate your response.

 

function draw() {

 background(canvBG);

 stroke(circStroke);

 fill(circR, circG, circB, alph);

 stroke(circStroke);

 ellipse(circX, circY, circSize, circSize);

 ellipse(circX + 50, circY – 75, circSize, circSize);

 fill(circR, circG, circB, 135);

 

 stroke(recStroke);

 fill(recCol);

 rect(recX, recY, recSize, recSize);

 

 circX = circX + speed;

 recY = recY – speed;

 

 if (circX < width) {

 

   // circle size will increase by 0.5 through each loop if the condition is true.

   circSize += 0.5;

 

   // Else wil execute if condition is not true.

   //

 } else {

 

   //if (circX > width) {// Now if you put else and then another if statement it is like saying if the is true do this or else if this other thing is true do something else

     

   speed = speed * -1;

     

     circSize *= -1;

   }

 //}

}

 

  1. What is the difference between code with several consecutive if statements and code with several else if statements?

The difference is code with several consecutive if statements is not modular like else if statements are.

 

  1. What is a while loop? When should it be used? Use code to describe its syntax.

A while loop executes a block of code as long as the condition is true

 while (y <= width) {

   stroke(0);

   fill(255);

   rect(200, y, 50, 50);

   y = y + 50; }

36 What is a for loop? When should it be used? Use code to describe its syntax.

 

A for loop executes when the conditions are met and continue to be met it executes block code

 for (let y = mouseY; y <= width; y += 50) {

   stroke(255);

   fill(0);

   rect(300, y, 50, 50);

 }

 

  1. Write code that uses a nested for loop to draw a grid of squares across the x and y axis of a canvas.

 

function setup() {

 createCanvas(400, 400);

}

 

function draw() {

 background(220);

 strokeWeight(4);

 

 for (let i = 0; i <= width; i += 20) {

 for (let j = 0; j <= height; j += 20) {

   fill(244, 241, 66);

   rect(i, j, 20, 20);

   

 }

 }

}

 

  1. What is a function?

– A function is a set of instructions that goes with a variable.

  1. What is the difference between a function or method built into P5 and one that you define?

– The difference between a function or method built into P5 and one that you define is the function built in will have a specific parameters attached to it and the one you define you set the parameters.

 

  1. What does the keyword function mean?

The keyword function has a specific keyword to execute the function its attached to.

 

41.What does the keyword return mean?

Keyword return means to bring back a value from a function.

 

*42. Write code that uses the keyword return

 

  1. Write code that uses a defined function (by the user) and call or use it.

function display(){

 stroke(1);

 fill(244, 241, 66);

 rect(100,100,50,50);

}

 

function setup() {

 createCanvas(400, 400);

}

 

function draw() {

 background(220);

 display();

}

  1. What is the distinction between function and method?

-A method is usually a function in an object.

 

  1. What is the distinction between argument and parameter?

– An argument has real values and parameters are the names listed in the function definition

 

  1. What do the () in a function call or definition indicate?

– there is no arguments

 

  1. What will happen if you call an undefined function?

– you will get an error in your console log and code wont run

 

  1. What will happen if you define a function, but do not call or use it?

– Nothing happens if you never call or use it

 

*49. What concept are functions useful for?

– The concept of setting parameters to perform a task that

 

  1. What is an object?

– An object is an entity or container of specific information about it

 

*51. What data type is an object?

 

  1. What concept are objects, classes/constructors and arrays useful for?

– objects, classes/constructors and arrays are useful to handle, store or to create large amounts of data/variables.

 

  1. What is the difference between an object and a class/constructor function? Use code to demonstrate

your response.

let lighting = {// this is 1 object

 x: 400,

 y: 400,

 x1:200,

 y1: 100,

 r : 244,

 g : 241,

 b : 66

}

 

function Drops() {//this is a constructor and the difference here as oppose to an object is it has the

Capabilities to create Multiple objects

 

this.x = random(0, width);//random location

this.y = random(0, height);

this.display = function() {//to display them

 strokeWeight(9);

 stroke(0,0,255);

 point(this.x, this.y);//the actual shapes

 this.x = this.x – speed;//and the movement

 this.y = this.y – speed;

}

}

 

  1. What is dot syntax? Use code to demonstrate your response.

Dot syntax is  this.y = this.y – speed; which has the dot as the acessor for the variable its attached to.

 

  1. What is the keyword new used for?

– The keyword new is used for the constructor function

 

  1. What is a constructor? Where and when is it used? Use code to demonstrate your response.

– A constructor is like  template for creating multi objects without having to write verbose code. Its used in cases where you need many objects.

let drops = [];//created an empty array

// let fullMoonX = 100;//set variables

// let fullMoonY = 100;

// let diam = 100;

let speed = 1;

 

//mod.created a lighting object

let lighting = {

 x: 400,

 y: 400,

 x1:200,

 y1: 100,

 r : 244,

 g : 241,

 b : 66

}

//mod.created a moon object

let mooon = {

 x: 100,

 y: 100,

 diam: 100,

 }

 

function setup() {

 createCanvas(600, 600);

 

 

 // for (let i = 0; i < 400; i++){

 //   drops[i] = new Drops();

 // }

}

 

function draw() {

 background(255);

 for (let i = 0; i < 400; i++){//created an array to create the new drops

   drops[i] = new Drops();//initializing the constructor function

 }

 

 for (let i = 0; i < drops.length; i++) {//created an array to display the drops

   drops[i].display();

 }

 

 noStroke();

 fill(random(255));

 ellipse(mooon.x, mooon.y, mooon.diam, mooon.diam);//mod. by creating an ellipse object

 stroke(lighting.r, lighting.g, lighting.b);

 strokeWeight(2);

 //fill(lighting.r, lighting.g, lighting.b);

 line(lighting.x + 100, lighting.y + 100, lighting.x1, lighting.y1)

 //do not understand why line is not in yellow color

 //**figured out why! A line is not filled but shows color

 //with stroke

 //umbrellaX = umbrellaX + speed;

 }

 

function Drops() {//setting the parameters for the constructor function

 

this.x = random(0, width);//random location

this.y = random(0, height);

this.display = function() {//to display them

 strokeWeight(9);

 stroke(0,0,255);

 point(this.x, this.y);//the actual shapes

 this.x = this.x – speed;//and the movement

 this.y = this.y – speed;

}

}

 

  1. What is the this keyword used for?

– This keyword is used to describe the object the variable is attached to by dot syntax

 

  1. Organize original code to include the main program in one tab and a class or constructor in another.

Use in-line comments to walkthrough code.

//John Kontolios March 15, 2019

//constructor function

 

let drops = [];//created an empty array

// let fullMoonX = 100;//set variables

// let fullMoonY = 100;

// let diam = 100;

let speed = 1;

 

//mod.created a lighting object

let lighting = {

 x: 400,

 y: 400,

 x1:200,

 y1: 100,

 r : 244,

 g : 241,

 b : 66

}

//mod.created a moon object

let mooon = {

 x: 100,

 y: 100,

 diam: 100,

 }

 

function setup() {

 createCanvas(600, 600);

 

 

 // for (let i = 0; i < 400; i++){

 //   drops[i] = new Drops();

 // }

}

 

function draw() {

 background(255);

 for (let i = 0; i < 400; i++){//created an array to create the new drops

   drops[i] = new Drops();//initializing the constructor function

 }

 

 for (let i = 0; i < drops.length; i++) {//created an array to display the drops

   drops[i].display();

 }

 

 noStroke();

 fill(random(255));

 ellipse(mooon.x, mooon.y, mooon.diam, mooon.diam);//mod. by creating an ellipse object

 stroke(lighting.r, lighting.g, lighting.b);

 strokeWeight(2);

 //fill(lighting.r, lighting.g, lighting.b);

 line(lighting.x + 100, lighting.y + 100, lighting.x1, lighting.y1)

 //do not understand why line is not in yellow color

 //**figured out why! A line is not filled but shows color

 //with stroke

 //umbrellaX = umbrellaX + speed;

 }

 

function Drops() {//setting the parameters for the constructor function

 

this.x = random(0, width);//random location

this.y = random(0, height);

this.display = function() {//to display them

 strokeWeight(9);

 stroke(0,0,255);

 point(this.x, this.y);//the actual shapes

 this.x = this.x – speed;//and the movement

 this.y = this.y – speed;

}

}

.

 

  1. What is an array?

Is a list or container of values separated by commas in square brackets

 

  1. What notation is used to denote an array?

Square brackets

 

  1. How do data types impact arrays?

Depending on what data type it is it might need quotation marks

 

  1. What is an index?

Index is the first value of the array

 

  1. Write code that declares, initializes and accesses elements in an array. Use comments to

walkthrough code.

 

//Array to display text on canvas

//Code by John Kontolios, 2019

 

let fnmnln = [“John”, “Peter”, “Kontolios”];//created an array declared and initialized elements

 

function setup() {

 createCanvas(600, 400);

 background(0,255,0);

 

 for (let i = 0; i < 3; i++) {//use for loop to access the array’s index starting always from 0 to 2

   noStroke();

   fill(0);

   textSize(20);

   text(fnmnln[i], i * 20 + 150, i * 50 + 50);//use to print each string by space and location

 }

}

 

function draw() {//no need to draw

 //background(220);

}

 

  1. List two or three functions that can be called on an array. Describe how they manipulate the array.
  2. What is a class? How is it distinguished for a constructor function?
  3. What are the keywords let and const? How are they distinct from var?

 

  1. What is a local server and why would one be used?

A local server is a server running in your computers files and not the internet

  1. How can you install and run code using a local server?

You can download a text editor like sublime and use your computer as the local server

  1. What is Node?

It is an open source server enviroment

  1. What is NPM? Give an example of a module that can be downloaded and installed from NPM.

 

  1. List one text editor that can be used in lieu of an IDE. How can a P5 project be coded and run using

a text editor?

Sublime and you can link the libraries you want to use from p5js in a html file and have that file linked in your javascript file

 

  1. What does CLI stand for?

Command Line Input

 

  1. How can the current directory be identified using the command line?

By typing cd in the command line

 

  1. How can the contents of a directory (current) be viewed?

By typing pwd

  1. What command must be used to make a directory or folder using the CLI?

By typing cd”nameOfFolder” and press enter

 

  1. No question

 

  1. How can recent commands be viewed on the command line?

Up arrow key

 

*78. What shortcut keyboard combination can be used to automatically complete a path in the

commands line?

 

  1. What naming convention can be used to save an application or program?

Camel Case.

 

  1. What is GIT?

– Git is a distributed version control tool that is used to store different versions of a fie in a remote and local repository.

 

  1. How does GIT distinct from Github or Bitbucket?

– Github and bitbucket are tools that hold files in “cloud” or remote repository  

 

  1. What is the command to initialize a GIT repo?

Gitinit and enter

 

  1. What is the difference between staging and committing in GIT?

Staging you are preparing your “package” and committing is officially transferring it.

 

85.

Tech Meet-Full Stack Coding 27 E 28th st

Today March 17, 2019 I went to my first tech meetup in Manhattan called Full Stacking Coding. It was on 27E 28th street inside of the 8th floor of a weWorks building, hosted by a man named Adam. He was a very cool down to earth individual who went over basic HTML, CSS, and Javascript. He was using the node.js and not P5.js but it still looked relatively the same. I spent roughly 2 hours there and felt like I would want to continue to go to this meetup regularly. It surrounded me with like minded people with similar interests in coding, a nice spacious and somewhat quite working environment. I also spoke with Adam’s buddy who also runs the meetup name Sushen. He was giving me his insight on how it is to work at Mastercard’s back end data center. He was telling me that the most important thing to have when working as a developer is the critical thinking skills to think about how to solve a problem from the begininng till the end. He made my journey more realistic and I really enjoyed it. I took a picture with Sushen, another attendee and me =]IMG_0406