-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
352 lines (294 loc) · 11.1 KB
/
index.html
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<link href="http://fonts.googleapis.com/css?family=Arvo&subset=latin"
rel="stylesheet" type="text/css">
<link rel="icon" type="img/png" href="favicon.png">
<link rel="stylesheet" type="text/css" href="style.css" type="text/css">
<script src="processing-1.0.0.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"
type="text/javascript"></script>
<script type="text/javascript">
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
// returns random index within the array
Array.prototype.ri = function() {
return Math.floor(Math.random()*this.length);
};
// returns random item in the array
Array.prototype.rand = function() {
return this[Math.floor(Math.random()*this.length)];
};
var hash = "";
var style_opts = ["boogie","color_a","composition", "new_york_creater"];
var rotate_opts = [true, true, false, false];
var dimension_opts = [[480,480], [480,240],[240,480],[480,320],[320,480]];
var thickness_opts = [1,1,2,2,3,3];
var complexity_opts = [1,1,2,2,3,3];
var options = [style_opts, rotate_opts, dimension_opts, thickness_opts, complexity_opts];
var clicks = 0;
var db_enabled = true; // toggling is helpful when using cssedit
if (db_enabled && window.openDatabase) {
db = openDatabase('gallery', '1.0', 'Mondrian Automaton gallery', 10 * 1024 * 1024);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS images'
+'(id unique, title TEXT, src TEXT, rotate BOOLEAN, clicks INT)');
});
}
function hash_change() {
if (location.hash != hash) {
hash = location.hash;
$("header a").removeClass("current");
$("#main > div").not(location.hash).fadeOut(function() {
$(location.hash).fadeIn();
$(location.hash).trigger("generate");
$("a[href='"+hash+"']").addClass("current");
});
}
}
location.hash = location.hash ? location.hash : "#content";
setInterval("hash_change()", 100);
$(function() {
$("#gallery").bind("generate", function(e) {
if (db) {
$(this).children().remove();
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM images', [], function(tx, results) {
if (results.rows && results.rows.length) {
$("#gallery").append("<ul/>");
for(i=results.rows.length-1; i>=0; i--) {
var li = '<li><h3>'+unescape(results.rows.item(i).title)
+'<span class="clicks">'+results.rows.item(i).clicks+' clicks</span></h3>'
if (results.rows.item(i).title.toLowerCase() == "piet" ||
results.rows.item(i).title.toLowerCase() == "mondrian") {
li += '<img src="piet.jpg"';
} else {
li += '<img src="'+unescape(results.rows.item(i).src)+'"';
}
if (results.rows.item(i).rotate == "true") {
li += ' class="rotate"';
}
li += '>';
$("#gallery ul").append(li);
}
} else {
$("#gallery").append("<h2>Nothing in the Gallery yet.</h2>");
}
});
});
}
});
var hletters = $("h1 a").text().split("");
var colors = ["red", "yellow", "blue", "grey", "black"];
function colorify_title() {
$("h1 a").text("");
for (i = 0; i<hletters.length; i++) {
var color = colors[Math.floor(Math.random()*colors.length)];
$("h1 a").append('<span class="'+color+'">'+hletters[i]+'</span>');
}
}
colorify_title();
function generate_images() {
var style_clone = style_opts.slice(0);
var rotate_clone = rotate_opts.slice(0);
var dimension_clone = dimension_opts.slice(0);
var thickness_clone = thickness_opts.slice(0);
var complexity_clone = complexity_opts.slice(0);
var the_style = style_clone.rand();
var the_rotation = rotate_clone.rand();
var the_dimensions = dimension_clone.rand();
var the_thickness = thickness_clone.rand();
var the_complexity = complexity_clone.rand();
$("canvas").each(function() {
$(this).removeClass();
var my_id = $(this).attr("id");
the_style = style_clone.rand();
style_clone.remove(jQuery.inArray(the_style, style_clone));
the_rotation = rotate_clone.rand();
rotate_clone.remove(jQuery.inArray(the_rotation, rotate_clone));
the_dimensions = dimension_clone.rand();
dimension_clone.remove(jQuery.inArray(the_dimensions, dimension_clone));
the_thickness = thickness_clone.rand();
thickness_clone.remove(jQuery.inArray(the_thickness, thickness_clone));
the_complexity = complexity_clone.rand();
complexity_clone.remove(jQuery.inArray(the_complexity, complexity_clone));
$(this).data({"type": the_style,
"rotation": the_rotation,
"dimensions": the_dimensions,
"thickness": the_thickness,
"complexity": the_complexity});
if (the_rotation == true) {
$(this).addClass("rotate");
}
$(this).addClass("_"+the_dimensions[0]+"x"+the_dimensions[1]);
$.get(the_style+".pde", function(code) {
var canvas = document.getElementById(my_id);
$(document).data("width", $("#"+my_id).data("dimensions")[0]);
$(document).data("height", $("#"+my_id).data("dimensions")[1]);
$(document).data("thickness", $("#"+my_id).data("thickness"));
$(document).data("complexity", $("#"+my_id).data("complexity"));
new Processing(canvas, code);
});
});
}
// initial generation
generate_images();
$("canvas").click(function() {
clicks += 1;
style_opts.push($(this).data("type"));
rotate_opts.push($(this).data("rotation"));
dimension_opts.push($(this).data("dimensions"));
complexity_opts.push($(this).data("complexity"));
thickness_opts.push($(this).data("thickness"));
for (i in options) {
if (options[i].length > 20) {
/* we get rid of the 6th so as not to
remove the prepopulated values.
This way, there's always a SLIGHT
chance of getting a different style painting. */
options[i].remove(6);
}
}
generate_images();
return false;
});
$("#i").click(function() {
$("#info").toggle();
$(this).toggleClass("current");
return false;
});
$("#x").click(function() {
$("#info").hide();
$("#i").removeClass("current");
return false;
});
$("#images a").click(function() {
$(this).hide();
$("#image_src").removeClass();
var source = document.getElementById($(this).attr("href").slice(1)).toDataURL();
$("#image_src").attr("src", source);
if ($($(this).attr("href")).hasClass("rotate")) {
$("#image_src").addClass("rotate");
}
$("#upload").show();
return false;
});
$("h1 a").click(colorify_title);
function close_upload() {
$("#image_name").val("").removeClass("error");
$("#errors").text("").hide();
$("#upload").hide();
$("#images a").show();
}
$("#cancel").click(function() {
close_upload();
});
$("#upload form").submit(function() {
$("#image_name").removeClass("error");
$("#errors").text("").hide();
var the_title = escape($("#image_name").val().replace(/^\s+|\s+$/g, ''));
var the_src = escape($("#image_src").attr("src"));
var rotate = $("#image_src").hasClass("rotate") ? true : false;
if (the_title.length) {
if (the_title.length < 64) {
var index = 0;
if (db) {
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM images', [], function(tx, results) {
if (results.rows && results.rows.length) {
index = results.rows.length;
}
});
});
db.transaction(function(tx) {
tx.executeSql('INSERT INTO images (id, title, src, rotate, clicks) '
+'values (?, ?, ?, ?, ?)',
[index, the_title, the_src, rotate, clicks]);
});
}
close_upload();
location.hash = "#gallery";
} else {
$("#errors").text("Title too long, please shorten.").show();
$("#image_name").addClass("error");
}
} else {
$("#errors").text("No title entered.").show();
$("#image_name").addClass("error");
}
return false;
});
});
</script>
<title>Mondrian</title>
</head>
<body>
<div id="upload">
<form>
<h2>Add to the Gallery</h2>
<p id="errors"></p>
<input type="text" name="image_name" id="image_name" placeholder="Give it a title.">
<img id="image_src" src="#">
<input type="submit" id="submit" value="Submit">
<input type="button" id="cancel" value="Cancel">
</form>
</div>
<header>
<h1><a href="#content">Mondrian Automaton</a></h1>
<a href="#info" id="i">Info</a>
<a href="#gallery" id="gal">Gallery</a>
</header>
<details id="info">
<p>An experiment in websites as art for
<a href="http://courses.media.mit.edu/2010fall/mas110/">MAS.110</a>.
</p>
<p>
Mondrian-style images are generated with a little
help from <a href="http://processingjs.org/">processing.js</a>.
</p>
<p>
Icons from <a href="http://glyphish.com/">Glyphish</a>.
The typefaces are Distill and Arvo.
</p>
<p>
Created by <a href="http://www.tooepic.com">Ethan Sherbondy</a> and Turner Bohlen.
</p>
<p>
Play with the source on <a href="https://github.com/sherbondy/Mondrian-Automaton">GitHub</a>.
</p>
<a id="x" href="#">X</a>
</details>
<div id="main">
<div id="content">
<h2>Choose the image you prefer, and we’ll hone in on your tastes.</h2>
<h2>If you love one, add it to <a href="#gallery">your Gallery</a>.</h2>
<ol id="images">
<li>
<a href="#c1">Add to gallery</a>
<canvas id="c1"></canvas>
</li>
<li>
<a href="#c2">Add to gallery</a>
<canvas id="c2"></canvas>
</li>
<li>
<a href="#c3">Add to gallery</a>
<canvas id="c3"></canvas>
</li>
<li>
<a href="#c4">Add to gallery</a>
<canvas id="c4"></canvas>
</li>
</ol>
</div>
<div id="gallery">
<h2>The Gallery feature requires a browser that supports Web SQL.</h2>
</div>
</div>
</body>
</html>