-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
238 lines (208 loc) · 5.83 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<html>
<head>
<title>Game of Life</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<?php
require_once ("simulator.php");
require_once ("gamefield.php");
require_once ("src/epf/epfpluginmanager.php");
require_once ("help/logsaver.php");
require_once ("help/validation.php");
$handle = fopen("help/logfiles.txt", "w+");
fwrite($handle, "");
fclose($handle);
$handle = fopen("help/bool.txt", "w+");
fwrite($handle, "true");
fclose($handle);
$epfPManager = new epfPluginManager();
$epfPManager->loadPluginsOnDemand("output/","output_",".plugin.php","output_");
$output = $epfPManager->getPluginFor("gif");
$epfPManager->loadPluginsOnDemand("input/","input_",".plugin.php","input_");
$input = $epfPManager->getPluginFor("txt");
$logsaver= new LogSaver();
$validater= new Validation();
if(isset($_GET['selectForm'])) $selectForm = $_GET['selectForm'];
else $selectForm = "beacon";
if(isset($_GET['selectColor'])) $selectColor = $_GET['selectColor'];
else $selectColor = "White";
if(isset($_GET['selectBgColor'])) $selectBgColor = $_GET['selectBgColor'];
else $selectBgColor = "Black";
$x=40;
$y=20;
$sim=40;
if(isset($_GET['x']))
{
$x = $_GET['x'];
}
if(isset($_GET['y']))
{
$y = $_GET['y'];
}
if(isset($_GET['sim']))
{
$sim = $_GET['sim'];
}
if(isset($_GET['ms']))
{
$output->setMs($_GET['ms']);
}
else
{
$output->setMs(10);
}
?>
<h1>Game of Life</h1>
<form action="?" method="GET" id="form">
Form: <select name="selectForm" size="1" class="blub">
<?php
foreach (glob("form/*.txt") as $filename)
{
$tempA = explode("/",$filename);
$tempB = explode(".",$tempA[1]);
?><option value="<?php echo $tempB[0] ?>" <?php if($selectForm==$tempB[0]) echo "selected" ?>><?php echo $tempB[0] ?></option><?php
}
?>
</select><br />
<input name="name" type="text" size="30" maxlength="30" value="Name for Gif-Animation"/><br />
Breite x: <input name="x" type="text" size="3" maxlength="3" value="<?php echo $x ?>" /><br />
Höhe y: <input name="y" type="text" size="3" maxlength="3" value="<?php echo $y ?>" /><br />
Anzahl Simulationsprozesse:<br /><input name="sim" type="text" size="3" maxlength="3" value="<?php echo $sim ?>" /><br />
Zeit zwischen Prozessen in ms: <br /><input name="ms" type="text" size="3" maxlength="3" value="<?php echo $output->getMs() ?>" /><br />
Farbe der lebendigen Zellen:<br />
<select name="selectColor" size="1" class="blub">
<?php
$colorArray = file ("./color/colors.txt");
for($i=0;$i<count($colorArray);$i++)
{
$tempArray = explode(" ",$colorArray[$i]);
?><option value="<?php echo $tempArray[0] ?>" <?php if($selectColor==$tempArray[0]) echo "selected" ?>><?php echo $tempArray[0] ?></option><?php
}
?>
</select><br />
Hintergrundfarbe:<br />
<select name="selectBgColor" size="1" class="blub">
<?php
$colorArray = file ("./color/colors.txt");
for($i=0;$i<count($colorArray);$i++)
{
$tempArray = explode(" ",$colorArray[$i]);
?><option value="<?php echo $tempArray[0] ?>" <?php if($selectBgColor==$tempArray[0]) echo "selected" ?>><?php echo $tempArray[0] ?></option><?php
}
?>
</select><br />
<input type="checkbox" name="log" value="log"> Show logfiles<br>
<input type="submit" value="send" class="submitButton"/>
</form>
<?php
$filename="beacon";
$gifname;
if($selectForm!="beacon")
{
$filename=$selectForm;
}
if(isset($_GET['name']))
{
if( $_GET['name']=="Name for Gif-Animation")
{
$gifname="Animation";
}
else
{
$gifname = $gifname = $_GET['name'];
}
}
else $gifname = "animation";
if($selectColor!="White")
{
$output->setColor( $_GET['selectColor']);
}
if($selectBgColor!="Black")
{
$output->setBgColor( $_GET['selectBgColor']);
}
//Validation Process
$validationIntArray= array(
"repitations" => $sim,
"width" => $x,
"height" => $y
);
$cA=0;
foreach($validater->validateInt($validationIntArray) as $var => $value2)
{
$tempArray[$cA]=$value2;
$cA++;
}
$sim = $tempArray[0];
$x = $tempArray[1];
$y = $tempArray[2];
$gamefield = new Gamefield();
$simulator = new Simulator($gamefield);
$gamefield->setGamefield($y,$x);
//ReadInput
$input->setFilename($filename);
$input->readIntoGamefield($gamefield);
$tempBgColor =$output->getBgColor();
$tempLcColor =$output->getColor();
$md5 = md5($x.$y.$tempLcColor[0].$tempBgColor[0].$output->getMs().$sim.$filename);
$output->setName($md5);
$bool =false;
foreach (glob("gif/*.gif") as $filename)
{
$tempA = explode("/",$filename);
$tempB = explode(".",$tempA[1]);
if($tempB[0]==$md5)
{
$gifname=$md5;
$bool=true;
$logsaver->log($sim." simulation processes will generated ");
break;
}
else $bool=false;
}
if($bool==false)
{
$logsaver->log($sim." simulation processes will generated ");
for($i=0;$i<$sim;$i++)
{
if($output->comparison()==true)
{
$output->setCounter($i+1);
$output->outputGamefield($gamefield);
$simulator->simulation();
}
else break;
}
$output->finishOutput();
$gifname=$md5;
$bool=true;
}
/* if(file_exists($gifname.".gif"))
{
header('Content-type: application/gif');
header('Content-Disposition: attachment; filename="animated.gif"');
readfile('gif/'.$gifname.'gif');
}
*/
?>
<div id="imagecontainer">
<img src="gif/<?php echo $gifname ?>.gif" />
</div>
<?php
if(isset ($_GET['log']))
{
?>
<textarea name="logfile" cols="50" rows="10" id="logfile" readonly class="logfile"><?php
$txtArray = file ("help/logfiles.txt");
for($e=0;$e<count($txtArray);$e++)
{
echo $txtArray[$e];
}
?>
</textarea>
<?php
}
?>
</body>
</html>