Skip to content

Commit 3ea1380

Browse files
committed
Add printWave example.
1 parent d3a6441 commit 3ea1380

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* ImageJ Plugins
3+
* Copyright (C) 2002-2016 Jarek Sacha
4+
* Author's email: jpsacha at gmail dot com
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2.1 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with this library; if not, write to the Free Software
18+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
*
20+
* Latest release available at https://github.com/ij-plugins
21+
*
22+
*/
23+
24+
import scala.math._
25+
26+
/*
27+
* Print a wave to the standard output
28+
*/
29+
val scale = 2
30+
for (x <- Range.Double(-Pi / 2, 3.5 * Pi, Pi / 5)) {
31+
// Prepare empty line
32+
val line = Array.fill(scale * 2 + 1) {
33+
" "
34+
}
35+
// Create marker at location `y`
36+
val y = round((sin(x) + 1) * scale).toInt
37+
line(y) = "*"
38+
// Print line as string
39+
println(line.mkString(" "))
40+
}

0 commit comments

Comments
 (0)