WWW Dukelearntoprogram Com Course1 Doc
WWW Dukelearntoprogram Com Course1 Doc
HTML
HTML
Basic HTML
Lists
Tables Full list of HTML elements
Input
As a reminder, in most browsers you can right-click on a page and select View Source to see the HTML
CSS code used to render the page.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
<h1> being the largest heading and <h6> being larger heading
the smallest.
smaller heading
<b>bold</b>
<b> Apply bold formatting to text
bold
<em>emphasis</em>
<em> Apply emphasis to text
emphasis
HTML <img src="http://bit.ly/1QfkvVw"
Inserts an image. width="100px">
Basic HTML
Lists src is the link specifying the image to
Tables display (it is a required attribute)
Input <img> width (and height) specifies the size of
the image (it is an optional attribute)
CSS
Unlike most other tags, this start tag does not
CSS Properties and Values have a corresponding end tag.
Course Specific Functions
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
<li>HTML</li>
<li>CSS</li>
</ul>
HTML
CSS
<ol>
<li>HTML</li>
<li>CSS</li>
HTML
<ol> Ordered list, each item has a number. </ol>
Basic HTML
1. HTML
Lists
2. CSS
Tables
Input
CSS Tables
<th> Table header cell (a table cell with bold text). <table>
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
<tr>
<th>
heading
</th>
</tr>
<tr>
<td>
content
</td>
</tr>
HTML
</table>
Basic HTML heading
Lists content
Tables
Input
Input
CSS
Because the attributes used with input elements varies so much depending on the type of input you
CSS Properties and Values
want to use, we have provided several specific examples of using different types of input.
Course Specific Functions
Example Description
SimplePixel
SimpleImage
type is button
Printing
<input type = "button" value is text that appears
Standard JavaScript value = "change" on button
onclick is event handler,
Arithmetic Operations
onclick = "alert('clicked button')">
specifies to call alert
Comparing Two Numbers function when button is
Combining Comparisons clicked
Math Functions
Random Functions
type is color picker
Background Information
value is default color value
What is a Pixel?
<input type = "color" id lets us refer to input
Transparency: Alpha Channel value = "#001A57" element in JavaScript
Image Coordinate System id = "clr" onchange is event handler,
onchange = "docolor()"> specifies to call docolor
function when color is
changed
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
type is slider
<input type = "range" min is minimum value, max
min = "10" is maximum value
max = "100" value is default value
value = "10" id lets us refer to input
element in JavaScript
id = "sldr"
oninput is event handler,
oninput = "dosquare()"> specifies to call dosquare
function when slider is
HTML changed
Basic HTML
Lists
Tables <input type = "text" type is text
Input id = "finput"> id lets us refer to input
element in JavaScript
CSS
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System
CSS
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
This website challenges people to use CSS to make as many different stylized versions as possible
using the same HTML code.
Example
Property Use with Example
Values
Standard JavaScript
blue body {
Arithmetic Operations background- table, table cell, page
rgb(0,0,255) background-color: #00FF00;
Comparing Two Numbers color backgrounds
#0000FF }
Combining Comparisons
Math Functions
Random Functions
top th {
Background Information vertical-
middle table cells vertical-align: top;
align
What is a Pixel? bottom }
Transparency: Alpha Channel
Image Coordinate System
float left images
right img {
float: right;
}
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
img {
tables, table cells,
width 100px width: 80px;
images
}
td {
tables, table cells,
height 100px height: 10px;
HTML images
}
Basic HTML
Lists
Tables
table {
Input border- tables, table cells,
5px border-width: 2px;
width images
CSS }
CSS Properties and Values
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Course Specific JavaScript Functions
SimplePixel
HTML pix1 is a pixel at coordinate (100, 200) representing the color Duke blue, with RGBA values of
(0, 26, 87, 255)
Basic HTML pix2 is a pixel at coordinate (300, 400) representing the color white, with RGBA values of (255,
Lists 255, 255, 255)
Tables
Input Function name Description Example
CSS returns the pixel's x-coordinate within the
getX() pix1.getX() is 100
image
CSS Properties and Values
returns the pixel's y-coordinate within the
getY() pix1.getY() is 200
Course Specific Functions image
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
setBlue(newB) changes the value of the pixel's blue pix1.setBlue(255)
component to newB (if newB is not in the changes the color to (0,
range of 0-255 it is changed to be in that 26, 255, 255)
range)
changes the value of the pixel's alpha, or
pix1.setAlpha(100)
transparency, component to newA (if newA is
setAlpha(newA) changes the color to (0,
not in the range of 0-255 it is changed to be
26, 87, 100)
in that range)
pix2.setAllFrom(pix1)
HTML changes the value of all of the pixel's
changes the color of
setAllFrom(otherPixel) components (its red, green, blue, and alpha)
pix2 to (0, 26, 87, 255)
Basic HTML to match otherPixel's values
Lists
Tables
Input SimpleImage
CSS For these examples, assume the variable logo has the value of the image "devil.png" below. It is 100
pixels wide and 85 pixels tall.
CSS Properties and Values
SimplePixel
SimpleImage
Printing
Standard JavaScript
Function name Description Example
Arithmetic Operations
new SimpleImage("devil.png") is
Comparing Two Numbers
Combining Comparisons creates a
Math Functions SimpleImage to
new SimpleImage(filename)
Random Functions represent the
image in filename
Background Information
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
image are black
(0, 0, 0, 255)
var input =
creates a document.getElementById("fileLoader");
SimpleImage to var img = new SimpleImage(input); is
HTML represent the
new image selected by
Basic HTML SimpleImage(fileInputElement) the user using the
Lists fileInputElement
Tables
given from the
Input
web page assuming the user selected that image from their
CSS computer.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
the new
dimensions.
returns all the
pixels in the
image, starting in for (var pixel of logo.values()) {
the upper-left
corner and moving
values() // modify pixel
down to the lower-
right corner,
providing a way to }
HTML
access each pixel
Basic HTML in turn
Lists draws the image var canvas =
Tables to canvas, for
Input drawTo(canvas) document.getElementById("canvas");
drawing images on
logo.drawTo(canvas);
web pages
CSS
Standard JavaScript displays something in the small area at the debug(x) shows the value
debug(something)
bottom of the "See It" area of the page of the variable x
Arithmetic Operations
Comparing Two Numbers
Combining Comparisons Standard JavaScript
Math Functions
Random Functions
What is a Pixel?
Transparency: Alpha Channel Operator Description Example
Image Coordinate System + addition 4 + 5 is 9
- subtraction 9 - 5 is 4
* multiplication 3 * 5 is 15
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
6 / 3 is 2
/ division
6 / 4 is 1.5
% mod/remainder 5 % 3 is 2
SimplePixel
For these examples, assume the variable x has the value 5.
SimpleImage
Printing
Operator Description Example
Standard JavaScript
(x < 3 || x > 7) is false
|| returns true if at least one part of the comparison is true
Arithmetic Operations (x < 3 || x < 7) is true
Comparing Two Numbers
(x > 3 && x < 7) is true
Combining Comparisons && returns true only if both parts of the comparison are true
Math Functions (x > 3 && x > 7) is false
Random Functions ! reverses the boolean value of a comparison (! x == 5) is false
Background Information
Math Functions
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System Function name Description Example
Math.abs(-3.6) is 3.6
abs(x) returns absolute value of x
Math.abs(3.2) is 3.2
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
ceil(x) returns x, rounded upwards to the nearest integer Math.ceil(3.6) is 4
Math.ceil(3.2) is 4
Math.floor(3.6) is 3
floor(x) returns x, rounded downwards to the nearest integer
Math.floor(3.2) is 3
Math.round(3.6) is 4
round(x) returns x, rounded x to the nearest integer
Math.round(3.2) is 3
Basic HTML
Function name Description Example
Lists
Tables Math.random() might return 0.523
Input
random() returns a random number between 0 and 1
Math.random() might return 0.983
CSS
Background Information
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Each pixel has a color value. We need a way to represent colors so that we can tell the computer which
color to make each pixel. There are many color representations, but JavaScript uses a scheme called
the RGBA color model. Basically, it means that a color is represented by four numbers:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Image Coordinate System
Finally, it is important to be able to distinguish one pixel from another. We do this by referring to each
pixel's location on the screen or image. Each pixel gets an X and Y value, where (0,0) is the top left
corner of the screen. (This can take some getting used to as it's not the way a Cartesian Plane is drawn
in math class!)
The X value refers to how far right the pixel is, and the Y value refers to how far down the pixel is. For
my computer monitor, which is 1440 x 900, the top left corner is (0,0), the top right is (1439,0), the
bottom left is (0,899), the bottom right is (1439,899), and the middle is (720, 450).
HTML
Basic HTML
Lists
Tables
Input
CSS
SimplePixel
SimpleImage
Printing
Standard JavaScript
Arithmetic Operations
Comparing Two Numbers All of the discussion so far has been generic knowledge of a computer representation of images and
Combining Comparisons colors. In other words, the same information would probably apply if you were programming in a
Math Functions language other than JavaScript. The rest of this page gives you details that are specific to JavaScript
Random Functions and the problems you are asked to solve.
Background Information
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System
Material accessible from this webpage developed by the instructors at Duke University is licensed under a Creative Commons Attribution 4.0
International License.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
HTML
Basic HTML
Lists
Tables
Input
CSS
SimplePixel
SimpleImage
Printing
Standard JavaScript
Arithmetic Operations
Comparing Two Numbers
Combining Comparisons
Math Functions
Random Functions
Background Information
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD