From c8de1761c54e74c931b9e1f6f009cf2a023b1ada Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Fri, 19 May 2017 20:38:06 +0800 Subject: [PATCH] coala: Add coala support Ref https://github.com/coala/coala-bears/issues/1750 Signed-off-by: Ce Gao --- .coafile | 13 +++ .../BasicOperations/BasicOperations.rpde | 23 ++---- examples/Basics/Draw/Draw.rpde | 16 ++-- .../ObjectOrientedProgramming.rpde | 57 +++++-------- examples/Basics/Settings/Settings.rpde | 18 ++-- examples/Basics/Setup/Setup.rpde | 4 +- .../ThreeDimensionalCube.rpde | 82 ++++++++----------- .../Basics/Trigonometry/trigonometry.rpde | 60 ++++++-------- 8 files changed, 124 insertions(+), 149 deletions(-) create mode 100644 .coafile diff --git a/.coafile b/.coafile new file mode 100644 index 0000000..1d2dfbf --- /dev/null +++ b/.coafile @@ -0,0 +1,13 @@ +[Default] +files = src/**/*.java, examples/**/*.rpde + +max_line_length = 80 + +[Java] +# https://github.com/coala/coala-bears/issues/1750 +bears = CheckstyleBear +indent_size = 4 + +[R] +bears = FormatRBear +files = examples/**/*.rpde diff --git a/examples/Basics/BasicOperations/BasicOperations.rpde b/examples/Basics/BasicOperations/BasicOperations.rpde index 501e881..bf7a2be 100644 --- a/examples/Basics/BasicOperations/BasicOperations.rpde +++ b/examples/Basics/BasicOperations/BasicOperations.rpde @@ -14,23 +14,18 @@ processing$bezierDetail(as.integer(12)) processing$bezier(85, 20, 10, 10, 90, 90, 15, 80) -# for (i in 1:16) { -# t = i / float(steps); -# x = processing$bezierPoint(85, 10, 90, 15, t); -# y = processing$bezierPoint(20, 10, 90, 80, t); -# tx = processing$bezierTangent(85, 10, 90, 15, t); -# ty = processing$bezierTangent(20, 10, 90, 80, t); -# a = atan2(ty, tx); -# a -= HALF_PI; -# line(x, y, cos(a)*8 + x, sin(a)*8 + y); -# } +# for (i in 1:16) { t = i / float(steps); x = processing$bezierPoint(85, 10, 90, +# 15, t); y = processing$bezierPoint(20, 10, 90, 80, t); tx = +# processing$bezierTangent(85, 10, 90, 15, t); ty = processing$bezierTangent(20, +# 10, 90, 80, t); a = atan2(ty, tx); a -= HALF_PI; line(x, y, cos(a)*8 + x, +# sin(a)*8 + y); } # bezierPoint for (i in 1:10) { - t = i / 10 - x = processing$bezierPoint(85, 10, 90, 15, t) - y = processing$bezierPoint(20, 10, 90, 80, t) - processing$ellipse(x, y, 5, 5) + t = i/10 + x = processing$bezierPoint(85, 10, 90, 15, t) + y = processing$bezierPoint(20, 10, 90, 80, t) + processing$ellipse(x, y, 5, 5) } processing$curve(5, 26, 73, 24, 73, 61, 15, 65) diff --git a/examples/Basics/Draw/Draw.rpde b/examples/Basics/Draw/Draw.rpde index cf7fcf9..4dd5229 100644 --- a/examples/Basics/Draw/Draw.rpde +++ b/examples/Basics/Draw/Draw.rpde @@ -1,10 +1,10 @@ -yPos <- 0.0; - +yPos <- 0 + draw <- function() { - processing$background(as.integer(204)) - yPos <- yPos - 1.0; - if (yPos < 0) { - yPos <- height; - } - processing$line(0, yPos, width, yPos) + processing$background(as.integer(204)) + yPos <- yPos - 1 + if (yPos < 0) { + yPos <- height + } + processing$line(0, yPos, width, yPos) } diff --git a/examples/Basics/ObjectOrientedProgramming/ObjectOrientedProgramming.rpde b/examples/Basics/ObjectOrientedProgramming/ObjectOrientedProgramming.rpde index 87e7d77..0216745 100644 --- a/examples/Basics/ObjectOrientedProgramming/ObjectOrientedProgramming.rpde +++ b/examples/Basics/ObjectOrientedProgramming/ObjectOrientedProgramming.rpde @@ -3,69 +3,52 @@ cols <- 10 rows <- 10 -Cell <- function(x, y, w, h, angle) -{ - me <- list( - x = x, - y = y, - w = w, - h = h, - angle = angle - ) - class(me) <- append(class(me),"Cell") +Cell <- function(x, y, w, h, angle) { + me <- list(x = x, y = y, w = w, h = h, angle = angle) + class(me) <- append(class(me), "Cell") return(me) } -oscillate <- function(cell) -{ - UseMethod("oscillate",cell) +oscillate <- function(cell) { + UseMethod("oscillate", cell) } -oscillate.Cell <- function(cell) -{ - # stdout$print("Calling the base oscillate function") +oscillate.Cell <- function(cell) { + # stdout$print('Calling the base oscillate function') cell$angle <- cell$angle + 0.2 return(cell) } -display <- function(cell) -{ - UseMethod("display",cell) +display <- function(cell) { + UseMethod("display", cell) } -display.Cell <- function(cell) -{ +display.Cell <- function(cell) { processing$stroke(255) processing$fill(127 + 127 * sin(cell$angle)) - processing$rect(cell$x,cell$y,cell$w,cell$h) + processing$rect(cell$x, cell$y, cell$w, cell$h) } grid <- list() settings <- function() { - stdout$print("Set width and height.") - processing$size(200,200) + stdout$print("Set width and height.") + processing$size(200, 200) } -setup <- function() -{ - for (i in 1:cols-1) - { - for (j in 1:rows-1) - { +setup <- function() { + for (i in 1:cols - 1) { + for (j in 1:rows - 1) { # There is no 0 in a list. - grid[[1 + i * cols + j]] = Cell(i*20, j*20, 20, 20, i + j) + grid[[1 + i * cols + j]] = Cell(i * 20, j * 20, 20, 20, i + j) } } } -draw <- function() -{ +draw <- function() { processing$background(0) - for (i in 1:cols-1) - { - for (j in 1:rows-1) - { + for (i in 1:cols - 1) { + for (j in 1:rows - 1) { oscillate(grid[[1 + i * cols + j]]) display(grid[[1 + i * cols + j]]) } diff --git a/examples/Basics/Settings/Settings.rpde b/examples/Basics/Settings/Settings.rpde index 13bfd17..3759980 100644 --- a/examples/Basics/Settings/Settings.rpde +++ b/examples/Basics/Settings/Settings.rpde @@ -1,15 +1,15 @@ -yPos <- 0.0; +yPos <- 0 settings <- function() { - stdout$print("Set width and height.") - processing$size(500, 500) + stdout$print("Set width and height.") + processing$size(500, 500) } draw <- function() { - processing$background(as.integer(204)) - yPos <- yPos - 1.0; - if (yPos < 0) { - yPos <- height; - } - processing$line(0, yPos, width, yPos) + processing$background(as.integer(204)) + yPos <- yPos - 1 + if (yPos < 0) { + yPos <- height + } + processing$line(0, yPos, width, yPos) } diff --git a/examples/Basics/Setup/Setup.rpde b/examples/Basics/Setup/Setup.rpde index 1243d2d..e591546 100644 --- a/examples/Basics/Setup/Setup.rpde +++ b/examples/Basics/Setup/Setup.rpde @@ -1,4 +1,4 @@ setup <- function() { - processing$line(11, 22, 33, 22) - stdout$print("Hello, Processing.R") + processing$line(11, 22, 33, 22) + stdout$print("Hello, Processing.R") } diff --git a/examples/Basics/ThreeDimensionalCube/ThreeDimensionalCube.rpde b/examples/Basics/ThreeDimensionalCube/ThreeDimensionalCube.rpde index 9181bd4..55832a1 100644 --- a/examples/Basics/ThreeDimensionalCube/ThreeDimensionalCube.rpde +++ b/examples/Basics/ThreeDimensionalCube/ThreeDimensionalCube.rpde @@ -1,53 +1,43 @@ PI <- 3.1415 -settings <- function() -{ - processing$size(500, 500, "processing.opengl.PGraphics3D") +settings <- function() { + processing$size(500, 500, "processing.opengl.PGraphics3D") } -setup <- function() -{ - processing$colorMode(as.integer(1), 1) - processing$frameRate(24) +setup <- function() { + processing$colorMode(as.integer(1), 1) + processing$frameRate(24) } -draw <- function() -{ - frames <- 24 * 3 - t <- processing$frameCount() / frames - - processing$background(1) - - processing$perspective(0.5, 1, 0.01, 100) - - processing$camera( - 0, 0, 25 + sin(PI * 2 * t) * 3, - 0, 0, 0, - 0, 1, 0 - ) - - processing$rotateX(-0.5 - 0.05 * sin(PI * 4 * t)) - processing$rotateY(-0.5 - 0.05 * cos(PI * 2 * t)) - - columns <- 8 - for (ix in 1:columns - 1) - { - x <- ix - 0.5 * columns + 0.5 - for (iy in 1:columns - 1) - { - y <- iy - 0.5 * columns + 0.5 - for (iz in 1:columns - 1) - { - z <- iz - 0.5 * columns + 0.5 - - d <- sqrt(x * x + y * y + z * z) - s <- abs(sin(d - t * 4 * PI)) - - processing$pushMatrix() - processing$translate(x, z, y) - processing$box(s) - processing$popMatrix() - } +draw <- function() { + frames <- 24 * 3 + t <- processing$frameCount()/frames + + processing$background(1) + + processing$perspective(0.5, 1, 0.01, 100) + + processing$camera(0, 0, 25 + sin(PI * 2 * t) * 3, 0, 0, 0, 0, 1, 0) + + processing$rotateX(-0.5 - 0.05 * sin(PI * 4 * t)) + processing$rotateY(-0.5 - 0.05 * cos(PI * 2 * t)) + + columns <- 8 + for (ix in 1:columns - 1) { + x <- ix - 0.5 * columns + 0.5 + for (iy in 1:columns - 1) { + y <- iy - 0.5 * columns + 0.5 + for (iz in 1:columns - 1) { + z <- iz - 0.5 * columns + 0.5 + + d <- sqrt(x * x + y * y + z * z) + s <- abs(sin(d - t * 4 * PI)) + + processing$pushMatrix() + processing$translate(x, z, y) + processing$box(s) + processing$popMatrix() + } + } } - } -} \ No newline at end of file +} diff --git a/examples/Basics/Trigonometry/trigonometry.rpde b/examples/Basics/Trigonometry/trigonometry.rpde index cfc8259..0b2f7f5 100644 --- a/examples/Basics/Trigonometry/trigonometry.rpde +++ b/examples/Basics/Trigonometry/trigonometry.rpde @@ -12,60 +12,54 @@ radius <- 50 frequency <- 2 frequency2 <- 2 -settings <- function() -{ +settings <- function() { processing$size(600, 200) } -draw <- function() -{ +draw <- function() { processing$background(127) processing$noStroke() processing$fill(255) - processing$ellipse(width/8, 75, radius*2, radius*2) + processing$ellipse(width/8, 75, radius * 2, radius * 2) # Rotates rectangle around circle - px <- width/8 + cos(processing$radians(angle))*(radius) - py <- 75 + sin(processing$radians(angle))*(radius) + px <- width/8 + cos(processing$radians(angle)) * (radius) + py <- 75 + sin(processing$radians(angle)) * (radius) processing$fill(0) - + processing$rect(px, py, 5, 5) processing$stroke(100) processing$line(width/8, 75, px, py) processing$stroke(200) - - # Keep reinitializing to 0, to avoid - # Flashing during redrawing + + # Keep reinitializing to 0, to avoid Flashing during redrawing angle2 <- 0 - + # Draw static curve - y <- sin(x) - for (i in 1:width - 1) - { - px2 <- width/8 + cos(processing$radians(angle2))*(radius) - py2 <- 75 + sin(processing$radians(angle2))*(radius) - processing$point(width/8+radius+i, py2) + for (i in 1:width - 1) { + px2 <- width/8 + cos(processing$radians(angle2)) * (radius) + py2 <- 75 + sin(processing$radians(angle2)) * (radius) + processing$point(width/8 + radius + i, py2) angle2 <- angle2 - frequency2 } - - # Send small ellipse along sine curve - # to illustrate relationship of circle to wave + + # Send small ellipse along sine curve to illustrate relationship of circle to + # wave processing$noStroke() - processing$ellipse(width/8+radius+x, py, 5, 5) + processing$ellipse(width/8 + radius + x, py, 5, 5) angle <- angle - frequency x <- x + 1 - - # When little ellipse reaches end of window, - # set the variables back to 0 - if (x >= width-60) { + + # When little ellipse reaches end of window, set the variables back to 0 + if (x >= width - 60) { x <- 0 angle <- 0 } - + # Draw dynamic line connecting circular path with wave processing$stroke(50) - processing$line(px, py, width/8+radius+x, py) - - # Output calculations to screen - # processing$text("y <- sin x", 35, 185) - # processing$text("px <- " + px, 105, 185) - # processing$text("py <- " + py, 215, 185) -} \ No newline at end of file + processing$line(px, py, width/8 + radius + x, py) + + # Output calculations to screen processing$text('y <- sin x', 35, 185) + # processing$text('px <- ' + px, 105, 185) processing$text('py <- ' + py, 215, + # 185) +}