Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/Examples/ContinuousLines/ContinuousLines.rpde
Original file line number Diff line number Diff line change
@@ -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)

}
}
24 changes: 24 additions & 0 deletions examples/Examples/Patterns/Patterns.rpde
Original file line number Diff line number Diff line change
@@ -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)
}
26 changes: 26 additions & 0 deletions examples/Examples/Pulses/Pulses.rpde
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions examples/reference/mousePressedVar/.property.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
category: Input
subcategory: Mouse
description: "
The <b>mousePressedVar</b> 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 <b>mouseButton</b> 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
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/rprocessing/RLangPApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -485,6 +486,7 @@ protected void wrapKeyVariables() {
this.renjinEngine.put("key", pyKey);
}
this.renjinEngine.put("keyCode", keyCode);
this.renjinEngine.put("keyPressedVar", keyPressed);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/rprocessing/mode/RLangMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")};
}

/**
Expand Down