Skip to content

Commit 322b3cf

Browse files
committed
Playing with a little SVG sketch. Better typography
1 parent 5a6a2e5 commit 322b3cf

6 files changed

Lines changed: 86 additions & 64 deletions

File tree

lib/storying/app/app.coffee

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,8 @@ $(document).ready ->
1818
story_dropdown.change (element) ->
1919
window.location = $(element.srcElement).val() # Change paths on dropdown change
2020

21-
$('.story_content').after($('<div id="notepad"></div>'))
2221
$('.story_content').addClass template_name # FIXME- do in Ruby
2322

24-
Raphael.fn.arrow = (x1, y1, x2, y2, size) ->
25-
angle = Raphael.angle(x1, y1, x2, y2)
26-
a45 = Raphael.rad(angle-45)
27-
a45m = Raphael.rad(angle+45)
28-
a135 = Raphael.rad(angle-135)
29-
a135m = Raphael.rad(angle+135)
30-
x1a = x1 + Math.cos(a135) * size
31-
y1a = y1 + Math.sin(a135) * size
32-
x1b = x1 + Math.cos(a135m) * size
33-
y1b = y1 + Math.sin(a135m) * size
34-
x2a = x2 + Math.cos(a45) * size
35-
y2a = y2 + Math.sin(a45) * size
36-
x2b = x2 + Math.cos(a45m) * size
37-
y2b = y2 + Math.sin(a45m) * size
38-
@path(
39-
"M"+x1+" "+y1+"L"+x1a+" "+y1a+
40-
"M"+x1+" "+y1+"L"+x1b+" "+y1b+
41-
"M"+x1+" "+y1+"L"+x2+" "+y2+
42-
"M"+x2+" "+y2+"L"+x2a+" "+y2a+
43-
"M"+x2+" "+y2+"L"+x2b+" "+y2b
44-
)
45-
46-
paper = Raphael document.getElementById('notepad'), 320, 200
47-
circle = paper.circle 50, 40, 10
48-
diagonal = paper.path "M28 10L90 90"
49-
50-
diagonal2 = diagonal.clone
51-
# diagonal2.rotate 45
52-
# diagonal2.insertAfter diagonal
53-
# diagonal2.rotate 180
54-
55-
paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
56-
57-
5823
# # Tabs Activation
5924
# tabs.each (i) ->
6025
# # Get all tabs

lib/storying/app/sketch.coffee

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# via Paul Irish http://paulirish.com/2009/random-hex-color-code-snippets
2+
Raphael.fn.randomColor = ->
3+
'#' + Math.floor(Math.random() * 16777215).toString(16)
4+
5+
Raphael.fn.arrow = (x1, y1, x2, y2, size) ->
6+
angle = Raphael.angle(x1, y1, x2, y2)
7+
a45 = Raphael.rad(angle-45)
8+
a45m = Raphael.rad(angle+45)
9+
a135 = Raphael.rad(angle-135)
10+
a135m = Raphael.rad(angle+135)
11+
x1a = x1 + Math.cos(a135) * size
12+
y1a = y1 + Math.sin(a135) * size
13+
x1b = x1 + Math.cos(a135m) * size
14+
y1b = y1 + Math.sin(a135m) * size
15+
x2a = x2 + Math.cos(a45) * size
16+
y2a = y2 + Math.sin(a45) * size
17+
x2b = x2 + Math.cos(a45m) * size
18+
y2b = y2 + Math.sin(a45m) * size
19+
@path(
20+
"M"+x1+" "+y1+"L"+x1a+" "+y1a+
21+
"M"+x1+" "+y1+"L"+x1b+" "+y1b+
22+
"M"+x1+" "+y1+"L"+x2+" "+y2+
23+
"M"+x2+" "+y2+"L"+x2a+" "+y2a+
24+
"M"+x2+" "+y2+"L"+x2b+" "+y2b
25+
)
26+
27+
28+
Raphael.fn.randomCircle = ->
29+
radius = random(20)
30+
x = random(paper.width/2 - radius)
31+
y = random(paper.height/2 + radius)
32+
paper.circle(x, y, radius).attr({fill: paper.randomColor()})
33+
34+
random = (max) -> Math.floor(Math.random() * max)
35+
36+
paper = Raphael document.getElementById('notepad')
37+
diagonal = paper.path "M#{random(paper.width)} #{random(paper.height)}L#{random(paper.height)} #{random 90} z"
38+
circle = paper.randomCircle()
39+
40+
console.log('paper', paper.height, paper.width);

public/js/app.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function() {
22
$(document).ready(function() {
3-
var circle, diagonal, diagonal2, paper, story_dropdown, tabs, template_name;
3+
var story_dropdown, tabs, template_name;
44
tabs = $('ul.tabs') || [];
55
story_dropdown = $('select#story_template');
66
template_name = window.location.pathname.substr(1);
@@ -11,31 +11,6 @@
1111
story_dropdown.change(function(element) {
1212
return window.location = $(element.srcElement).val();
1313
});
14-
$('.story_content').after($('<div id="notepad"></div>'));
15-
$('.story_content').addClass(template_name);
16-
Raphael.fn.arrow = function(x1, y1, x2, y2, size) {
17-
var a135, a135m, a45, a45m, angle, x1a, x1b, x2a, x2b, y1a, y1b, y2a, y2b;
18-
angle = Raphael.angle(x1, y1, x2, y2);
19-
a45 = Raphael.rad(angle - 45);
20-
a45m = Raphael.rad(angle + 45);
21-
a135 = Raphael.rad(angle - 135);
22-
a135m = Raphael.rad(angle + 135);
23-
x1a = x1 + Math.cos(a135) * size;
24-
y1a = y1 + Math.sin(a135) * size;
25-
x1b = x1 + Math.cos(a135m) * size;
26-
y1b = y1 + Math.sin(a135m) * size;
27-
x2a = x2 + Math.cos(a45) * size;
28-
y2a = y2 + Math.sin(a45) * size;
29-
x2b = x2 + Math.cos(a45m) * size;
30-
y2b = y2 + Math.sin(a45m) * size;
31-
return this.path("M" + x1 + " " + y1 + "L" + x1a + " " + y1a + "M" + x1 + " " + y1 + "L" + x1b + " " + y1b + "M" + x1 + " " + y1 + "L" + x2 + " " + y2 + "M" + x2 + " " + y2 + "L" + x2a + " " + y2a + "M" + x2 + " " + y2 + "L" + x2b + " " + y2b);
32-
};
33-
paper = Raphael(document.getElementById('notepad'), 320, 200);
34-
circle = paper.circle(50, 40, 10);
35-
diagonal = paper.path("M28 10L90 90");
36-
diagonal2 = diagonal.clone;
37-
return paper.arrow(10, 10, 30, 30, 5).attr({
38-
fill: "#f00"
39-
});
14+
return $('.story_content').addClass(template_name);
4015
});
4116
}).call(this);

public/js/sketch.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(function() {
2+
var circle, diagonal, paper, random;
3+
Raphael.fn.randomColor = function() {
4+
return '#' + Math.floor(Math.random() * 16777215).toString(16);
5+
};
6+
Raphael.fn.arrow = function(x1, y1, x2, y2, size) {
7+
var a135, a135m, a45, a45m, angle, x1a, x1b, x2a, x2b, y1a, y1b, y2a, y2b;
8+
angle = Raphael.angle(x1, y1, x2, y2);
9+
a45 = Raphael.rad(angle - 45);
10+
a45m = Raphael.rad(angle + 45);
11+
a135 = Raphael.rad(angle - 135);
12+
a135m = Raphael.rad(angle + 135);
13+
x1a = x1 + Math.cos(a135) * size;
14+
y1a = y1 + Math.sin(a135) * size;
15+
x1b = x1 + Math.cos(a135m) * size;
16+
y1b = y1 + Math.sin(a135m) * size;
17+
x2a = x2 + Math.cos(a45) * size;
18+
y2a = y2 + Math.sin(a45) * size;
19+
x2b = x2 + Math.cos(a45m) * size;
20+
y2b = y2 + Math.sin(a45m) * size;
21+
return this.path("M" + x1 + " " + y1 + "L" + x1a + " " + y1a + "M" + x1 + " " + y1 + "L" + x1b + " " + y1b + "M" + x1 + " " + y1 + "L" + x2 + " " + y2 + "M" + x2 + " " + y2 + "L" + x2a + " " + y2a + "M" + x2 + " " + y2 + "L" + x2b + " " + y2b);
22+
};
23+
Raphael.fn.randomCircle = function() {
24+
var radius, x, y;
25+
radius = random(20);
26+
x = random(paper.width - radius);
27+
y = random(paper.height + radius);
28+
return paper.circle(x, y, radius).attr({
29+
fill: paper.randomColor()
30+
});
31+
};
32+
random = function(max) {
33+
return Math.floor(Math.random() * max);
34+
};
35+
paper = Raphael(document.getElementById('notepad'));
36+
diagonal = paper.path("M" + (random(paper.width)) + " " + (random(paper.height)) + "L" + (random(paper.height)) + " " + (random(90)) + " z");
37+
circle = paper.randomCircle();
38+
console.log('paper', paper.height, paper.width);
39+
}).call(this);

public/stylesheets/layout.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ hr.invisible {
2828
.inserted.highlighted { color: #ff69b4;}
2929

3030
#notepad {
31+
max-height: 260px;
3132
margin: 0 auto;
32-
height: 400px;
33-
width: 200px;
33+
padding: 0;
3434
}
3535

3636
/* #Media Queries

templates/layout.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
================================================== -->
1010
<meta charset="utf-8" />
1111
<title>Storying</title>
12+
1213
<meta name="description" content="">
1314
<meta name="author" content="">
1415
<!--[if lt IE 9]>
@@ -41,6 +42,7 @@
4142
<div class="five columns sidebar">
4243
<h1>Storying</h1>
4344
{{>app/story_selector}}
45+
<div id="notepad"></div>
4446
</div>
4547
<div class="eight columns content">
4648
<hr class="invisible">
@@ -52,6 +54,7 @@
5254
<script>window.jQuery || document.write("<script src='javascripts/jquery-1.5.1.min.js'>\x3C/script>")</script>
5355
<script src="js/raphael-min.js"></script>
5456
<script src="js/app.js"></script>
57+
// <script src="js/sketch.js"></script>
5558

5659
</body>
5760
</html>

0 commit comments

Comments
 (0)