forked from edwin-de-jong/mnist-digits-as-stroke-sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotstrokes.R
51 lines (50 loc) · 1.42 KB
/
plotstrokes.R
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
plotstrokes <- function( data, title ){
mu1 = data[,1]
mu2 = -data[,2]
xvals = cumsum( mu1 )
yvals = cumsum( mu2 )
xvals = c( xvals, 0 )
yvals = c( yvals, 0 )
xrange = range( xvals )
yrange = range( yvals )
vals = c( xvals, yvals )
colors = c( 'blue', 'green', 'black', 'red', 'magenta' )
x = 0
y = 0
result = NULL
eod_found = F
strokenr = 1
colornr = (strokenr %% length( colors ) ) + 1
pointnr=0
for ( row in 1:dim( data )[1] )
{
dx = mu1[ row ]
dy = mu2[ row ]
if ( data[ row, 4 ])
{
eod_found = T
}
if ( row == 2 )
{
plot( c( x, x + dx ), c( y, y + dy ), t = 'l', col = colors[ colornr ], xlim = c( xrange[1] - 1, xrange[2] + 1 ), ylim = c( yrange[1] - 1, yrange[2] + 1),, main = title, xlab = '', ylab = '', xaxt = 'n', yaxt = 'n' )
}
else if ( row > 1 )
{
if ( data[ row - 1, 3 ])
{
strokenr = strokenr + 1
colornr = ( strokenr %% length( colors ) ) + 1
}
else{ #unless EOS was encountered
points( c( x, x + dx ), c( y, y + dy ), t = 'l', col = colors[ colornr ] )
}
}
if ( !data[row, 3] && row >= 2)
{
text( x, y, pointnr )
pointnr = pointnr + 1
}
x = x + dx
y = y + dy
}
}