Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C15342806 wks 1 #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Lab1/Lab1_Calc.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#calc {
position: relative;
width: 40%;
height: 70vh;
border: 2px solid black;
border-radius: 12px;
border-radius: 12px;
margin: 0px auto;
padding: 20px 20px 100px 20px;
background: #006bb3;
}

input[type=button] {
background: #008ae6;
width: 20%;
font-size: 20px;
font-weight: 900;
border-radius: 7px;
margin-left: 3%;
margin-top: 8%;
}

input[type=button]:hover {
background-color: #66c2ff;
color: white;
}

input[type = text] {
position: relative;
display: block;
width: 90%;
margin: 6px ;
font-size: 20px;
padding: 10px;
}
36 changes: 36 additions & 0 deletions Lab1/Lab1_part1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
h1 {
font: italic bolder 40px arial, serif;
}

header {
font: italic 20px arial, serif;
}

#content {
float: left;
margin-left: 10px;
border-style: solid;
width:55%;
height:60%;

}

#sidebar {
float: left;
margin-left: 10px;
border-style: solid;
width:15%;
height:20%;
}

footer {
position: fixed;
bottom: 25%;
margin-left: 10px;
}

ul {
list-style-type: none;
margin-left: 50;
padding: 0;
}
34 changes: 34 additions & 0 deletions Lab1/Lab1_part1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<header>
<link rel="stylesheet" type="text/css" href="Lab1_part1.css">
<h1>
Title
</h1>
</header>
<section id="content">
<header>
Article title
</header>
<section>
<p>Article para1 ...</p>
</section>
</section>
<aside id="sidebar">
<header>
Aside
</header>
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
</ul>
</aside>
<footer>
<address>
Kevin St, Dublin 8
</address>
</footer>


45 changes: 45 additions & 0 deletions Lab1/Lab1_part2_calculator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" type="text/css" href="Lab1_Calc.css">
</header>
<head>
<title>Calculator</title>
</head>

<body>
<div id = 'calc'>

<form name = "calculator">

<input type = "text" name = "result"/>
<br>

<input type = "button" value = " ( " />
<input type = "button" value = " ) " />
<input type = "button" value = " +- " />
<input type = "button" value = " / " />

<input type = "button" value = " 7 " />
<input type = "button" value = " 8 " />
<input type = "button" value = " 9 " />
<input type = "button" value = " * " />

<input type = "button" value = " 4 " />
<input type = "button" value = " 5 " />
<input type = "button" value = " 6 " />
<input type = "button" value = " - " />

<input type = "button" value = " 1 " />
<input type = "button" value = " 2 " />
<input type = "button" value = " 3 " />
<input type = "button" value = " + " />

<input type = "button" value = " 0 " />
<input type = "button" value = " . " />
<input type = "button" value = " c " />
<input type = "button" value = " = " />

</form>
</div>
</body>
10 changes: 10 additions & 0 deletions Lab1/Lab1_part3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Javascript Exercise</title>
</head>
<body id = "demo">
<script src="Lab1_part3.js"></script>
</body>
</html>

114 changes: 114 additions & 0 deletions Lab1/Lab1_part3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
var i = 0;
var j = 0;
var width = 101;
var height = 50;
var activity = [];
var pactivity = [];
var currentRow;

//This will generate either 1 or 2
function randnum()
{
return Math.floor(Math.random() * Math.floor(2));
}

//Checks opposite side if at edge and will wrap around if so
function edge(index)
{
if(index == -1)
{
index = width-1;
}
else if (index == width)
{
index = 0;
}

return index;
}

//This will generate the cell
function makecell()
{
var active;

var cell = document.createElement("div");
cell.style.width = "8px";
cell.style.height = "8px";
cell.style.border = "1px solid gray";
cell.style.display = "inline-block";
//cell.style.background = "white";

//This will generate a the first row if random
if(j == 0)
{
active = randnum();
if(active == 1)
{
cell.style.background = "white";
}
else
{
cell.style.background = " #7a00cc";

}
}
//This will use the rules to correctly colour the remaining cells in every row
else
{
//Rule implementation##
if( pactivity[edge(i-1)] == 1 && pactivity[i] == 0 && pactivity[edge(i+1)] == 1
|| pactivity[edge(i-1)] == 1 && pactivity[i] == 0 && pactivity[edge(i+1)] == 0
|| pactivity[edge(i-1)] == 0 && pactivity[i] == 1 && pactivity[edge(i+1)] == 1
|| pactivity[edge(i-1)] == 0 && pactivity[i] == 1 && pactivity[edge(i+1)] == 0
)
{
cell.style.background = "white";
active = 1;
}
else
{
cell.style.background = " #7a00cc";
active = 0;
}
}//end else

//This will add the colour of the current cell to the array
activity[i] = active;
i++;
return cell;
}

//This will add the cell to the row div
function insertcell()
{
cell = makecell();
currentRow.appendChild(cell);
}

//This will create a row div that will have cells added to it
function insertrow()
{
currentRow = document.createElement("div");
currentRow.style.height = "8px";

//This will copy the current cell activity to the old one to check against the rules for the next row
pactivity = activity.slice();
activity = [];

for(a=0 ; a < width; a++)
{
insertcell();
}

document.getElementById("demo").appendChild(currentRow);

//This will add to the row count so that no other row will be randomly generated and will reset the cell count
j++;
i = 0;
}

for(count = 0; count < height; count++)
{
insertrow();
}