-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeme-art-maker.html
More file actions
253 lines (237 loc) · 9.21 KB
/
meme-art-maker.html
File metadata and controls
253 lines (237 loc) · 9.21 KB
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
<!DOCTYPE HTML>
<html>
<style type="text/css">
html, body {background-color:#000000; color:#ffffff; font-family:sans-serif; margin:auto; width:800px;}
div.control {float:left; width:250px; margin-right:10px;}
input {margin-right:5px; margin-left:5px;}
svg {width:500px; height:500px; border-radius:10px; background:#ffffff; border:10px solid #ffffff; float:left;}
a {text-decoration:none; font-weight:bold; color:#0090ff;}
div.step, .code {border:1px solid white; border-radius:10px; padding:10px; margin-bottom:5px;}
.code {clear:both; width:740px; padding:10px;}
textarea {width:700px; margin:auto; margin-left:5px;}
.codehold {padding:10px; clear:both; margin:auto;}
strong {color:#ffff33;}
em {font-size:small; color:#0090ff;}
/*from github pages stylesheet*/
#forkme_banner {
display: block;
position: absolute;
top:0;
right: 10px;
z-index: 10;
padding: 10px 50px 10px 10px;
color: #fff;
background: url('images/blacktocat.png') #0090ff no-repeat 95% 50%;
font-weight: 700;
box-shadow: 0 0 10px rgba(0,0,0,.5);
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
}
</style>
<script type="text/javascript">
//meme words
var words = ["IMHO", "XOXO", "L8R", "LULZ", "MEH", "OMG"];
//function to make fakesmile work dynamically via http://jsfiddle.net/whyoz/c3wb5sbr/
function registerAnimation(anim) {
var targets = getTargets(anim);
var elAnimators = new Array();
for(var i=0; i<targets.length ;i++) {
var target = targets[i];
var animator = new Animator(anim, target, i);
animators.push(animator);
elAnimators[i] = animator;
}
anim.animators = elAnimators;
var id = anim.getAttribute("id");
if (id)
id2anim[id] = anim;
for(var i=0; i<elAnimators.length ;i++)
elAnimators[i].register();
}
//function to add a star to the picture
function addStar(){
//get the svg
var svg = document.getElementsByTagName('svg')[0];
//create a polygon
var newStar = document.createElementNS("http://www.w3.org/2000/svg", 'polygon');
//random x and y centre
var xcentre = Math.floor(Math.random()*(89-11+1)+11); var ycentre = Math.floor(Math.random()*(89-11+1)+11);
//call function to retrieve points of polygon in random location
var pointValue = getStarPoints(xcentre, ycentre);
newStar.setAttribute("points", pointValue);
//star style
var strokeColor = getRandomColor();//function to choose random color
newStar.style.stroke = strokeColor;
newStar.style.strokeWidth = "1";
newStar.style.fillOpacity = "0";
//create an animation on mouseover - change color to white and back
var anim = document.createElementNS("http://www.w3.org/2000/svg", 'animate');
anim.setAttribute("attributeName", "stroke");
anim.setAttribute("from", "#ffffff");
anim.setAttribute("to", strokeColor);
anim.setAttribute("dur", "1");
anim.setAttribute("begin", "mouseover");
//add animation to star
newStar.appendChild(anim);
//helper for fakesmile
registerAnimation(anim);
anim.beginElement();
//add star to svg
svg.appendChild(newStar);
//update code display
updateCode();
}
//function to add meme image to picture
function addMeme(){
//get the svg
var svg = document.getElementsByTagName('svg')[0];
//create an image element
var newMeme = document.createElementNS("http://www.w3.org/2000/svg", 'image');
//random x and y points
var x = Math.floor(Math.random()*71); var y = Math.floor(Math.random()*71);
newMeme.setAttributeNS(null, "x", x); newMeme.setAttributeNS(null, "y", y);
newMeme.setAttributeNS(null, "width", "30%"); newMeme.setAttributeNS(null, "height", "30%");
//pick an image at random - there are six stored in "memes" folder, named meme-1.jpg, meme-2.jpg and so on
var meme = Math.floor(Math.random()*6+1);
newMeme.setAttributeNS('http://www.w3.org/1999/xlink','href', 'http://hackaye.com/wp-content/uploads/2015/09/meme-'+meme+".jpg");
//create animation - shrink and regrow
var anim = document.createElementNS("http://www.w3.org/2000/svg", 'animate');
anim.setAttribute("attributeName", "width");
anim.setAttribute("from", "0");
anim.setAttribute("to", "30%");
anim.setAttribute("dur", "1");
anim.setAttribute("begin", "mouseover");
//add animation to image
newMeme.appendChild(anim);
//helper for fakesmile
registerAnimation(anim);
anim.beginElement();
//add image to svg
svg.appendChild(newMeme);
//update code display
updateCode();
}
//function to add meme word to svg
function addWord(){
//get the svg
var svg = document.getElementsByTagName('svg')[0];
//create text element
var newWord = document.createElementNS("http://www.w3.org/2000/svg", 'text');
//random x and y positions
var x = Math.floor(Math.random()*(95-10+1)+10); var y = Math.floor(Math.random()*(95-10+1)+10);
newWord.setAttribute("x", x); newWord.setAttribute("y", y);
//text style - impact font commonly used in memes
newWord.setAttribute("font-size", "10px");
newWord.setAttribute("text-anchor", "middle");
newWord.style.fill = "#ffffff";
newWord.style.fontFamily = "Impact";
newWord.style.textShadow = "3px 3px 0px #000000";
//pick random word from array
var wordNum = Math.floor(Math.random()*6);
var textNode = document.createTextNode(words[wordNum]);
newWord.appendChild(textNode);
//create animation to rotate the word
var anim = document.createElementNS("http://www.w3.org/2000/svg", 'animateTransform');
anim.setAttribute("attributeName", "transform");
anim.setAttribute("attributeType", "XML");
anim.setAttribute("type", "rotate");
anim.setAttribute("from", "0 "+x+ " "+y);
anim.setAttribute("to", "360 "+x+" "+y);
anim.setAttribute("dur", "1");
anim.setAttribute("begin", "mouseover");
//add animation to word
newWord.appendChild(anim);
//helper for fakesmile
registerAnimation(anim);
anim.beginElement();
//add word to svg
svg.appendChild(newWord);
//update code display
updateCode();
}
//function to retrieve a random hex color value
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
//function to retrieve star points for given centre coordinates
function getStarPoints(midX, midY) {
var pointString = ""; var points = 5; var inner = 5; var outer = 15;
var angle = Math.PI / points;
for (var i = 0; i < 2 * points; i++){
var r = (i & 1) == 0 ? outer : inner;
var currX = midX + Math.cos(i * angle) * r;
var currY = midY + Math.sin(i * angle) * r;
if (i == 0) pointString = currX + "," + currY;
else pointString += ", " + currX + "," + currY;
}
return pointString;
}
//code display
function updateCode(){
var txt = document.getElementsByTagName('textarea')[0];
var svg = document.getElementsByTagName('svg')[0];
txt.value = "";
var markup = (new XMLSerializer()).serializeToString(svg);
//remove internet explorer weirdness
var svgcode = markup.replace('xmlns:NS1=""', '');
markup = svgcode.replace('NS1:', '');
txt.value = markup;
}
</script>
<meta name="viewport" content="width=800" />
</head>
<body>
<a id="forkme_banner" href="https://github.com/hackaye/hackaye.github.io/blob/master/meme-art-maker.html">View on GitHub</a>
<h1>Hack Aye - Meme Art Maker</h1>
<p><strong>Make remixable art using this component and then remix the component.</strong></p>
<div class="control">
<div class="step">
<strong>1.</strong> Add meme images, text and shapes:<br/><br/>
<input type="button" value="picture" onclick="addMeme()"/> <input type="button" value="text" onclick="addWord()"/> <input type="button" value="star" onclick="addStar()"/>
<br/><br/>
<em>The generated image is an SVG with the elements randomly selected, coloured and placed.</em>
</div>
<div class="step">
<strong>2.</strong> Roll your mouse over the elements you added.<br/><br/>
<em>The SVG code includes interactive animation elements.</em>
</div>
<div class="step">
<strong>3.</strong> Scroll down to see the SVG code and save your picture.<br/><br/><em>You can also interact with the code by inspecting the elements using your browser's right-click menus or developer tools.</em>
</div>
</div>
<svg version="1.1"
baseProfile="full"
width="100%" height="100%"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg">
<script type="text/ecmascript" xlink:href="smil.user.js"></script>
<defs>
<linearGradient id="back" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stop-color="#ff0000"/>
<stop offset="30%" stop-color="#ffff00"/>
<stop offset="50%" stop-color="#00ff00"/>
<stop offset="70%" stop-color="#0000ff"/>
<stop offset="100%" stop-color="#ff0066"/>
</linearGradient>
</defs>
<rect x="0" y="0" width="100%" height="100%" fill="url(#back)"/>
</svg>
<div class="codehold">
<div class="code">
<p><strong>4.</strong> To save your artwork, copy the code below into a text editor, save the file with your chosen name and ".svg" as the extension, e.g. "picture.svg" - open it in a supporting web browser.</p>
<textarea rows="10" readonly="readonly" onclick="this.focus();this.select()">
</textarea>
<p><strong>5.</strong> Reuse and remix the code on this page via <a href="https://github.com/hackaye/hackaye.github.io/blob/master/meme-art-maker.html" target="_blank">GitHub</a>!</p>
</div></div>
<script type="text/javascript">
updateCode();
</script>
</body>
</html>