Skip to content

Commit 7c88019

Browse files
committed
Init
First upload and last if no changes or files are needed.
1 parent 396ee69 commit 7c88019

File tree

12 files changed

+385
-0
lines changed

12 files changed

+385
-0
lines changed

Binocular.png

97.6 KB
Loading

Can.png

51.9 KB
Loading

Disc.png

101 KB
Loading

Magic.png

145 KB
Loading

PaintNET/Transformation.pdn

243 KB
Binary file not shown.

arguments.js

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
NOTE:
3+
====================================================================================================
4+
5+
Parts of the code below could be optimized by using OOP, but due to simplicity and
6+
demonstration purpose, it is kept as it is.
7+
8+
9+
TIP:
10+
Mark a word with the mouse/keyboard to highlite every same word within the whole document(Notepad++)
11+
12+
====================================================================================================
13+
*/
14+
15+
16+
17+
18+
/*
19+
20+
===========
21+
ALL OBJECTS
22+
===========
23+
24+
*/
25+
26+
27+
var Disc =
28+
{
29+
30+
Name: "Disc",//Just needed once in "Reset()"
31+
isChecked: false,
32+
changeStyle: document.getElementById('disc').style,
33+
Reset: document.getElementById('disc-feature'),
34+
hasFeature: function()
35+
{
36+
37+
var Feature = document.getElementById('disc-feature').style
38+
39+
Feature.visibility = "visible";
40+
41+
}
42+
43+
}
44+
45+
46+
var Can =
47+
{
48+
49+
isChecked: false,
50+
changeStyle: document.getElementById('can').style,
51+
Reset: document.getElementById('can-feature'),
52+
hasFeature: function()
53+
{
54+
55+
var Feature = document.getElementById('can-feature').style
56+
57+
Feature.visibility = "visible";
58+
59+
}
60+
61+
}
62+
63+
64+
var Binocular =
65+
{
66+
67+
isChecked: false,
68+
changeStyle: document.getElementById('binocular').style,
69+
Reset: document.getElementById('binocular-feature'),
70+
hasFeature: function()
71+
{
72+
73+
var Feature = document.getElementById('binocular-feature').style
74+
75+
Feature.visibility = "visible";
76+
77+
}
78+
79+
}
80+
81+
82+
var Ingredients =
83+
{
84+
List: [Disc, Can, Binocular],
85+
}
86+
87+
88+
var Substance =
89+
{
90+
91+
isTransformed: false,
92+
hasIngredient: false,
93+
changeForm: document.getElementById('substance'),
94+
/*
95+
ATTENTION:
96+
Object "argument" is converted into an array.
97+
*/
98+
Transforming: function(ingredient)
99+
{
100+
101+
this.isTransformed = true;
102+
103+
//Saving the arguments into an array and cutting out the first parameter "ingredient"
104+
var args = [].slice.call(arguments, 1);
105+
106+
args[0]();
107+
108+
}
109+
110+
}
111+
112+
113+
114+
115+
/*
116+
117+
==========================
118+
CHECKING, TRANSFORM, RESET
119+
==========================
120+
121+
*/
122+
123+
//Purpose: Visualizing check or uncheck the ingredients
124+
function Checking(clicked)
125+
{
126+
var Ingredient = Ingredients.List[clicked];
127+
128+
//Change opacity
129+
if(Ingredient.isChecked === false)
130+
{
131+
Ingredient.isChecked = true;
132+
Ingredient.changeStyle.opacity = 0.5;
133+
134+
}
135+
else
136+
{
137+
Ingredient.isChecked = false;
138+
Ingredient.changeStyle.opacity = 1;
139+
140+
}
141+
142+
143+
}
144+
145+
146+
//Purpose: Shows the result of the fusion
147+
function Transform()
148+
{
149+
150+
var allIngredients = Ingredients.List.length;
151+
152+
//Checking if any ingredient is selected
153+
for(var ingredient = 0; ingredient < allIngredients; ingredient++)
154+
{
155+
156+
if(Ingredients.List[ingredient].isChecked && Substance.isTransformed === false)
157+
{
158+
//For later use
159+
Substance.hasIngredient = true;
160+
161+
}
162+
163+
}
164+
165+
166+
167+
//Not changing the substance form if no ingredient was chosen!
168+
if(Substance.hasIngredient === false)
169+
{
170+
alert("Please choose an ingredient!")
171+
}
172+
else
173+
{
174+
175+
//Changing the look of substance and activating all chosen ingredients features
176+
if(Substance.isTransformed === false)
177+
{
178+
for(var ingredient = 0; ingredient < allIngredients; ingredient++)
179+
{
180+
if(Ingredients.List[ingredient].isChecked)
181+
{
182+
//Object
183+
var selectedIngredient = Ingredients.List[ingredient];
184+
//Method
185+
var Feature = selectedIngredient.hasFeature;
186+
187+
/*
188+
ATTENTION:
189+
*/
190+
Substance.Transforming(selectedIngredient, Feature);
191+
192+
}
193+
194+
}
195+
196+
//Visualizing the new form in browser
197+
Substance.changeForm.src="transformation/TV.png";
198+
199+
}
200+
else
201+
{
202+
alert("Please RESET!");
203+
}
204+
205+
}
206+
207+
}//Transform
208+
209+
210+
211+
//Purpose: Resets all changes
212+
function Reset()
213+
{
214+
215+
Substance.hasIngredient = false;
216+
Substance.isTransformed = false;
217+
Substance.changeForm.src="Magic.png";
218+
219+
//Reseting all Ingredients
220+
for(var clicked = 0; clicked < Ingredients.List.length; clicked++)
221+
{
222+
223+
Ingredients.List[clicked].isChecked = false;
224+
Ingredients.List[clicked].changeStyle.opacity = 1;
225+
Ingredients.List[clicked].Reset.style.visibility = "hidden";
226+
227+
//Only for Audio
228+
if(Ingredients.List[clicked].Name === "Disc")
229+
{
230+
231+
Ingredients.List[clicked].Reset.currentTime = 0;
232+
Ingredients.List[clicked].Reset.pause();
233+
234+
}
235+
236+
}
237+
238+
}

index.html

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<!DOCTYPE HTML>
2+
3+
<html>
4+
5+
<head>
6+
7+
<title>TITLE</title>
8+
<meta charset = "UTF-8">
9+
10+
</head>
11+
12+
<!--
13+
NOTE:
14+
===============================================================================================
15+
16+
Because of simplicity & demonstration purposes, the "style" attribute is used within html tags.
17+
Nevertheless it is recommended to use CSS for styling.
18+
19+
===============================================================================================
20+
-->
21+
22+
23+
<body style="text-align:center; max-width:1600px; margin-left:auto; margin-right:auto;">
24+
25+
<h2>Ingredients</h2>
26+
27+
<section>
28+
29+
30+
<!--DISC-->
31+
<div style="display:inline;">
32+
33+
<img id="disc" style="width:15%;opacity:1;" src="Disc.png" onclick="Checking(0)">
34+
35+
</div>
36+
37+
38+
<!--CAN-->
39+
<div style="display:inline; margin-right:30px; margin-left:30px;">
40+
41+
<img id="can" style="width:10%;opacity:1;" src="Can.png" onclick="Checking(1)">
42+
43+
</div>
44+
45+
46+
<!--BINOCULAR-->
47+
<div style="display:inline;">
48+
49+
<img id="binocular" style="width:15%;opacity:1;" src="Binocular.png" onclick="Checking(2)">
50+
51+
</div>
52+
53+
<br>
54+
<br>
55+
<button type="button" onclick="Reset()">RESET</button>
56+
57+
</section>
58+
59+
60+
61+
<h2>Transforming Substance</h2>
62+
63+
<section style="position:relative;">
64+
65+
<!--This part should be a good example why css is useful!-->
66+
<div >
67+
68+
<img
69+
id="substance"
70+
71+
style=" width:25%;
72+
position:absolute;
73+
top:7%;
74+
z-index:2;"
75+
76+
src="Magic.png"
77+
onclick="Transform()">
78+
79+
80+
<img
81+
id="binocular-feature"
82+
83+
style=" width: 14%;
84+
position: absolute;
85+
right: 47%;
86+
top: 24%;
87+
z-index: 1;
88+
visibility:hidden;"
89+
90+
src="transformation/Sun.gif"
91+
onclick="Transform()">
92+
93+
94+
<img
95+
id="can-feature"
96+
style="width:25%; z-index:0; visibility:hidden;"
97+
src="transformation/Klecks.png"
98+
onclick="Transform()">
99+
100+
<br>
101+
<br>
102+
<br>
103+
<br>
104+
105+
<audio controls
106+
muted
107+
id="disc-feature"
108+
style="width:25%; visibility:hidden;"
109+
src="transformation/Chill.wav"
110+
type="audio/wav">
111+
112+
ERROR: Your browser doesn´t understand this tag :(!
113+
114+
</audio>
115+
116+
</div>
117+
118+
119+
</section>
120+
121+
122+
<br>
123+
<br>
124+
125+
<section>
126+
127+
<hr width="50%">
128+
129+
130+
<br>
131+
For more explanation please visit -
132+
<a href = "https://github.com/Incrementis/Javascript-save-arguments-into-a-variable-/wiki">
133+
Hoisting Wiki</a>
134+
135+
<br>
136+
<br>
137+
Music by <a href="https://opengameart.org/content/elevator-music">Alex McCulloch</a>
138+
139+
</sectioN>
140+
141+
142+
</body>
143+
144+
145+
<script language="javascript" type="text/javascript" src="arguments.js"></script>
146+
147+
</html>

transformation/Chill.wav

16.2 MB
Binary file not shown.

transformation/Klecks.png

200 KB
Loading

transformation/Sun.gif

21.6 KB
Loading

0 commit comments

Comments
 (0)