diff --git a/examples/Examples/ContinuousLines/ContinuousLines.rpde b/examples/Examples/ContinuousLines/ContinuousLines.rpde new file mode 100644 index 0000000..7dbc9f0 --- /dev/null +++ b/examples/Examples/ContinuousLines/ContinuousLines.rpde @@ -0,0 +1,15 @@ +settings <- function() { + size(640, 360) +} + +setup <- function() { + background(102) +} + +draw <- function() { + stroke(255) + if (mousePressedVar == TRUE) { + line(mouseX, mouseY, pmouseX, pmouseY) + + } +} diff --git a/examples/Demo/FiguresTransformation/FiguresTransformation.rpde b/examples/Examples/FiguresTransformation/FiguresTransformation.rpde similarity index 100% rename from examples/Demo/FiguresTransformation/FiguresTransformation.rpde rename to examples/Examples/FiguresTransformation/FiguresTransformation.rpde diff --git a/examples/Examples/Patterns/Patterns.rpde b/examples/Examples/Patterns/Patterns.rpde new file mode 100644 index 0000000..e70cc19 --- /dev/null +++ b/examples/Examples/Patterns/Patterns.rpde @@ -0,0 +1,24 @@ +settings <- function() { + size(640, 360) +} + +setup <- function() { + background(102) +} + +draw <- function() { + # Call the variableEllipse() method and send it the parameters for the current + # mouse position and the previous mouse position + variableEllipse(mouseX, mouseY, pmouseX, pmouseY) +} + + +# The simple method variableEllipse() was created specifically for this program. +# It calculates the speed of the mouse and draws a small ellipse if the mouse is +# moving slowly and draws a large ellipse if the mouse is moving quickly + +variableEllipse <- function(x, y, px, py) { + speed = abs(x - px) + abs(y - py) + stroke(speed) + ellipse(x, y, speed, speed) +} diff --git a/examples/Examples/Pulses/Pulses.rpde b/examples/Examples/Pulses/Pulses.rpde new file mode 100644 index 0000000..6e57262 --- /dev/null +++ b/examples/Examples/Pulses/Pulses.rpde @@ -0,0 +1,26 @@ +angle <- 0 + +settings <- function() { + size(640, 360) +} + +setup <- function() { + background(102) + noStroke() + fill(0, 102) +} + +draw <- function() { + if (mousePressedVar == TRUE) { + angle <- angle + 5 + val = cos(radians(angle)) * 12 + for (a in c(0, 75, 150, 225, 300)) { + xoff = cos(radians(a)) * val + yoff = sin(radians(a)) * val + fill(0) + ellipse(mouseX + xoff, mouseY + yoff, val, val) + } + fill(255) + ellipse(mouseX, mouseY, 2, 2) + } +} diff --git a/examples/reference/mouseButton/.property.yml b/examples/reference/mouseButtonVar/.property.yml similarity index 100% rename from examples/reference/mouseButton/.property.yml rename to examples/reference/mouseButtonVar/.property.yml diff --git a/examples/reference/mouseButton/mouseButton0/mouseButton0.rpde b/examples/reference/mouseButtonVar/mouseButtonVar0/mouseButtonVar0.rpde similarity index 77% rename from examples/reference/mouseButton/mouseButton0/mouseButton0.rpde rename to examples/reference/mouseButtonVar/mouseButtonVar0/mouseButtonVar0.rpde index cef0b95..21cb2df 100644 --- a/examples/reference/mouseButton/mouseButton0/mouseButton0.rpde +++ b/examples/reference/mouseButtonVar/mouseButtonVar0/mouseButtonVar0.rpde @@ -5,9 +5,9 @@ draw <- function() { } mousePressed <- function() { - if (mouseButton == LEFT) { + if (mouseButtonVar == LEFT) { fill(0) - } else if (mouseButton == RIGHT) { + } else if (mouseButtonVar == RIGHT) { fill(255) } else { fill(126) diff --git a/examples/reference/mouseButtonVar/mouseButtonVar1/mouseButtonVar1.rpde b/examples/reference/mouseButtonVar/mouseButtonVar1/mouseButtonVar1.rpde new file mode 100644 index 0000000..ce34c45 --- /dev/null +++ b/examples/reference/mouseButtonVar/mouseButtonVar1/mouseButtonVar1.rpde @@ -0,0 +1,12 @@ +# Click within the image and press the left and right mouse buttons to change the +# value of the rectangle +draw <- function() { + if (mousePressedVar && (mouseButtonVar == LEFT)) { + fill(0) + } else if (mousePressedVar && (mouseButtonVar == RIGHT)) { + fill(255) + } else { + fill(126) + } + rect(25, 25, 50, 50) +} diff --git a/examples/reference/mousePressedVar/.property.yml b/examples/reference/mousePressedVar/.property.yml new file mode 100644 index 0000000..98d7c25 --- /dev/null +++ b/examples/reference/mousePressedVar/.property.yml @@ -0,0 +1,17 @@ +category: Input +subcategory: Mouse +description: " +The mousePressedVar variable stores whether or not a mouse button is currently being pressed. The value is true when any mouse button is pressed, and false if no button is pressed. The mouseButton variable (see the related reference entry) can be used to determine which button has been pressed. +" +related: + - mouseX + - mouseY + - pmouseX + - pmouseY + - mousePressed + - mouseReleased + - mouseClicked + - mouseMoved + - mouseDragged + - mouseButtonVar + - mouseWheel diff --git a/examples/reference/mousePressed/mousePressed0/mousePressed0.rpde b/examples/reference/mousePressedVar/mousePressedVar1/mousePressedVar1.rpde similarity index 82% rename from examples/reference/mousePressed/mousePressed0/mousePressed0.rpde rename to examples/reference/mousePressedVar/mousePressedVar1/mousePressedVar1.rpde index 95df513..e89d3d2 100644 --- a/examples/reference/mousePressed/mousePressed0/mousePressed0.rpde +++ b/examples/reference/mousePressedVar/mousePressedVar1/mousePressedVar1.rpde @@ -1,7 +1,7 @@ # Click within the image to change the value of the rectangle draw <- function() { - if (mousePressed == TRUE) { + if (mousePressedVar == TRUE) { fill(0) } else { fill(255) diff --git a/src/rprocessing/RLangPApplet.java b/src/rprocessing/RLangPApplet.java index 74215e3..f172847 100644 --- a/src/rprocessing/RLangPApplet.java +++ b/src/rprocessing/RLangPApplet.java @@ -443,7 +443,8 @@ private void wrapMouseVariables() { this.renjinEngine.put("mouseY", mouseY); this.renjinEngine.put("pmouseX", pmouseX); this.renjinEngine.put("pmouseY", pmouseY); - this.renjinEngine.put("mouseButton", mouseButton); + this.renjinEngine.put("mouseButtonVar", mouseButton); + this.renjinEngine.put("mousePressedVar", mousePressed); } private void applyFunction(String name) { @@ -485,6 +486,7 @@ protected void wrapKeyVariables() { this.renjinEngine.put("key", pyKey); } this.renjinEngine.put("keyCode", keyCode); + this.renjinEngine.put("keyPressedVar", keyPressed); } /** diff --git a/src/rprocessing/mode/RLangMode.java b/src/rprocessing/mode/RLangMode.java index c9aea58..268f669 100644 --- a/src/rprocessing/mode/RLangMode.java +++ b/src/rprocessing/mode/RLangMode.java @@ -102,7 +102,7 @@ public String[] getExtensions() { public File[] getExampleCategoryFolders() { return new File[] {new File(examplesFolder, "Basics"), new File(examplesFolder, "Libraries"), new File(examplesFolder, "reference"), new File(examplesFolder, "R Packages"), - new File(examplesFolder, "Demo")}; + new File(examplesFolder, "Examples")}; } /**