forked from syntagmatic/raffi
/
buffers.coffee
138 lines (122 loc) · 3.12 KB
/
buffers.coffee
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
buffers =
splatter: '''
n = 16
createAxis("100%","100%",40)
cube = (x) -> pow(x,3)
pos =-> 500 + cube (15 * (random()-0.5))
size =-> cube 4.5*random()
circles = set()
for i in [1..n]
circles.push circle(pos(),pos(),size())
.attr
fill: color = getColor()
opacity: 0.6
"stroke": "#333"
"stroke-width": 1
"stroke-opacity": 0
circles.mouseover ->
this.attr
"stroke-opacity": 1
opacity:0.85
cursor: "pointer"
circles.mouseout ->
this.anim
"stroke-opacity": 0
opacity:0.6
cursor: "pointer"
duration: 140
'''
spiral: '''
n = 100
createAxis("100%","100%",40)
posx = (x) -> 800 + 9*i*sin(pi/12*i)
posy = (x) -> 500 + 9*i*cos(pi/12*i)
size = (x) -> x/2 + 1
circles = set()
for i in [1..n]
circles.push circle(posx(i),posy(i),size(i))
.attr
fill: color = getColor()
opacity: 0.6
"stroke": "#333"
"stroke-width": 1
"stroke-opacity": 0
'''
chart: '''
values = []
dotsy = []
clr = []
c = path("M0,0").attr
fill: "none"
"stroke-width": 3
for i in [0..12]
values[i] = randomPath(30, i, dotsy)
clr[i] = Raphael.getColor()
c.attr({path: values[i], stroke: clr[i]})
'''
equation: '''
eq = (x) -> sin(x) # equation
min = 0 # minimum
max = 4*pi # maximum
inc = pi/24 # increment size
width = 600 # window width
zoom = 120 # amplitude multiplier
ox = 400 # x of origin
oy = 400 # y of origin
num = (max-min) / inc
points = []
point = (x,y) -> circle(x,y,1)
for i in [0..num]
x = (inc*i + min)
y = eq x
points.push point(x*(width/num/inc) + ox, y*zoom + oy)
'''
callbacks: '''
n=10
createAxis("100%","100%",40)
xx = yy = 50
ww = hh = 300
maxR = 30
commonAttr =
opacity: 0.6
"stroke-width": 0
"stroke-opacity": 0
randomAttr = ()->
"cx": random() * ww + xx
"cy": random() * hh + yy
"r" : (random() * 3 + 1) * maxR / 4
fill: color = getColor()
step = (cir,next)-> cir.animate(randomAttr(),(1+2*random())*1000,"<>",next)
getCallback = (cn)->(()->step(cn,getCallback(cn)))
for i in [0..n-1]
c = circle(xx,yy,0).attr(commonAttr)
step(c, getCallback(c))
'''
$(document).ready ->
flipper = (button, panel, showmsg, hidemsg) ->
$(button).toggle( ->
$(this).html hidemsg
$(panel).fadeIn()
, ->
$(this).html showmsg
$(panel).fadeOut()
)
flipper("#show",
"#code",
"Code",
"Hide Code")
flipper("#cons",
"#console",
"Console",
"Hide Console")
flipper("#tut",
"#tutorial",
"Tutorial",
"Hide Tutorial")
$("#buffers").change( ->
buffer = $(this).val()
$("#code").html buffers[buffer]
)
# When buffer selected on reload
buffer = $("#buffers").val()
$("#code").html buffers[buffer]