Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference: Add Color #203

Merged
merged 16 commits into from
Aug 8, 2017
2 changes: 2 additions & 0 deletions examples/reference/alpha/alpha1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/alpha_.png
7 changes: 7 additions & 0 deletions examples/reference/alpha/alpha1/alpha1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
noStroke()
c = color(0, 126, 255, 102)
fill(c)
rect(15, 15, 35, 70)
value = alpha(c) # Sets 'value' to 102
fill(value)
rect(50, 15, 35, 70)
2 changes: 2 additions & 0 deletions examples/reference/background/background1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/background_0.png
1 change: 1 addition & 0 deletions examples/reference/background/background1/background1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
background(51)
2 changes: 2 additions & 0 deletions examples/reference/background/background2/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/background_1.png
1 change: 1 addition & 0 deletions examples/reference/background/background2/background2.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
background(255, 204, 0)
2 changes: 2 additions & 0 deletions examples/reference/background/background3/background3.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
img = loadImage("laDefense.jpg")
background(img)
2 changes: 2 additions & 0 deletions examples/reference/blue/blue1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/blue_.png
8 changes: 8 additions & 0 deletions examples/reference/blue/blue1/blue1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
c = color(175, 100, 220) # Define color 'c'
fill(c) # Use color variable 'c' as fill color
rect(15, 20, 35, 60) # Draw left rectangle

blueValue = blue(c) # Get blue in 'c'
println(blueValue) # Prints '220.0'
fill(0, 0, blueValue) # Use 'blueValue' in new fill
rect(50, 20, 35, 60) # Draw right rectangle
2 changes: 2 additions & 0 deletions examples/reference/brightness/brightness1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/brightness_.png
8 changes: 8 additions & 0 deletions examples/reference/brightness/brightness1/brightness1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
noStroke()
colorMode(HSB, 255)
c = color(0, 126, 255)
fill(c)
rect(15, 20, 35, 60)
value = brightness(c) # Sets 'value' to 255
fill(value)
rect(50, 20, 35, 60)
25 changes: 25 additions & 0 deletions examples/reference/clear/clear1/clear1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pg <- NULL

settings <- function() {
size(200, 200)
}

setup <- function() {
pg <- createGraphics(100, 100)
}

draw <- function() {
background(204)
pg$beginDraw()
pg$stroke(0, 102, 153)
pg$line(0, 0, mouseX, mouseY)
pg$endDraw()
image(pg, 50, 50)
}

# Click to clear the PGraphics object
mousePressed <- function() {
pg$beginDraw()
pg$clear()
pg$endDraw()
}
2 changes: 2 additions & 0 deletions examples/reference/color/color1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/color_0.png
4 changes: 4 additions & 0 deletions examples/reference/color/color1/color1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
c = color(255, 204, 0) # Define color 'c'
fill(c) # Use color variable 'c' as fill color
noStroke() # Don't draw a stroke around shapes
rect(30, 20, 55, 55) # Draw rectangle
2 changes: 2 additions & 0 deletions examples/reference/color/color2/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/color_1.png
9 changes: 9 additions & 0 deletions examples/reference/color/color2/color2.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
c = color(255, 204, 0) # Define color 'c'
fill(c) # Use color variable 'c' as fill color
noStroke() # Don't draw a stroke around shapes
ellipse(25, 25, 80, 80) # Draw left circle

# Using only one value with color() generates a grayscale value.
c = color(65) # Update 'c' with grayscale value
fill(c) # Use updated 'c' as fill color
ellipse(75, 75, 80, 80) # Draw right circle
2 changes: 2 additions & 0 deletions examples/reference/color/color3/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/color_2.png
12 changes: 12 additions & 0 deletions examples/reference/color/color3/color3.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
noStroke() # Don't draw a stroke around shapes

# If no colorMode is specified, then the default of RGB with scale of 0-255 is
# used.
c = color(50, 55, 100) # Create a color for 'c'
fill(c) # Use color variable 'c' as fill color
rect(0, 10, 45, 80) # Draw left rect

colorMode(HSB, 100) # Use HSB with scale of 0-100
c = color(50, 55, 100) # Update 'c' with new color
fill(c) # Use updated 'c' as fill color
rect(55, 10, 45, 80) # Draw right rect
2 changes: 2 additions & 0 deletions examples/reference/colorMode/colorMode1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/colorMode_0.png
8 changes: 8 additions & 0 deletions examples/reference/colorMode/colorMode1/colorMode1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
noStroke()
colorMode(RGB, 100)
for (i in 0:100) {
for (j in 0:100) {
stroke(i, j, 0)
point(i, j)
}
}
2 changes: 2 additions & 0 deletions examples/reference/colorMode/colorMode2/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/colorMode_1.png
8 changes: 8 additions & 0 deletions examples/reference/colorMode/colorMode2/colorMode2.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
noStroke()
colorMode(HSB, 100)
for (i in 0:100) {
for (j in 0:100) {
stroke(i, j, 100)
point(i, j)
}
}
2 changes: 2 additions & 0 deletions examples/reference/colorMode/colorMode3/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/colorMode_2.png
15 changes: 15 additions & 0 deletions examples/reference/colorMode/colorMode3/colorMode3.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# If the color is defined here, it won't be affected by the colorMode() in
# setup(). Instead, just declare the variable here and assign the value after
# the colorMode() in setup() color bg = color(180, 50, 50); # No

bg <- NULL

setup <- function() {
size(100, 100)
colorMode(HSB, 360, 100, 100)
bg = color(180, 50, 50)
}

draw <- function() {
background(bg)
}
2 changes: 2 additions & 0 deletions examples/reference/fill/fill1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/fill_0.png
2 changes: 2 additions & 0 deletions examples/reference/fill/fill1/fill1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fill(153)
rect(30, 20, 55, 55)
2 changes: 2 additions & 0 deletions examples/reference/fill/fill2/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/fill_1.png
2 changes: 2 additions & 0 deletions examples/reference/fill/fill2/fill2.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fill(204, 102, 0)
rect(30, 20, 55, 55)
2 changes: 2 additions & 0 deletions examples/reference/green/green1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/green_.png
8 changes: 8 additions & 0 deletions examples/reference/green/green1/green1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
c = color(20, 75, 200) # Define color 'c'
fill(c) # Use color variable 'c' as fill color
rect(15, 20, 35, 60) # Draw left rectangle

greenValue = green(c) # Get green in 'c'
print(greenValue) # Print '75.0'
fill(0, greenValue, 0) # Use 'greenValue' in new fill
rect(50, 20, 35, 60) # Draw right rectangle
2 changes: 2 additions & 0 deletions examples/reference/hue/hue1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/hue_.png
8 changes: 8 additions & 0 deletions examples/reference/hue/hue1/hue1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
noStroke()
colorMode(HSB, 255)
c = color(0, 126, 255)
fill(c)
rect(15, 20, 35, 60)
value = hue(c) # Sets 'value' to '0'
fill(value)
rect(50, 20, 35, 60)
2 changes: 2 additions & 0 deletions examples/reference/lerpColor/lerpColor1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/lerpColor_.png
14 changes: 14 additions & 0 deletions examples/reference/lerpColor/lerpColor1/lerpColor1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
stroke(255)
background(51)
from = color(204, 102, 0)
to = color(0, 102, 153)
interA = lerpColor(from, to, 0.33)
interB = lerpColor(from, to, 0.66)
fill(from)
rect(10, 20, 20, 60)
fill(interA)
rect(30, 20, 20, 60)
fill(interB)
rect(50, 20, 20, 60)
fill(to)
rect(70, 20, 20, 60)
2 changes: 2 additions & 0 deletions examples/reference/noFill/noFill1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/noFill_.png
3 changes: 3 additions & 0 deletions examples/reference/noFill/noFill1/noFill1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rect(15, 10, 55, 55)
noFill()
rect(30, 20, 55, 55)
2 changes: 2 additions & 0 deletions examples/reference/noStroke/noStroke1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/noStroke_.png
2 changes: 2 additions & 0 deletions examples/reference/noStroke/noStroke1/noStroke1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
noStroke()
rect(30, 20, 55, 55)
2 changes: 2 additions & 0 deletions examples/reference/red/red1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/red_.png
8 changes: 8 additions & 0 deletions examples/reference/red/red1/red1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
c = color(255, 204, 0) # Define color 'c'
fill(c) # Use color variable 'c' as fill color
rect(15, 20, 35, 60) # Draw left rectangle

redValue = red(c) # Get red in 'c'
println(redValue) # Print '255.0'
fill(redValue, 0, 0) # Use 'redValue' in new fill
rect(50, 20, 35, 60) # Draw right rectangle
2 changes: 2 additions & 0 deletions examples/reference/saturation/saturation1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/saturation_.png
8 changes: 8 additions & 0 deletions examples/reference/saturation/saturation1/saturation1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
noStroke()
colorMode(HSB, 255)
c = color(0, 126, 255)
fill(c)
rect(15, 20, 35, 60)
value = saturation(c) # Sets 'value' to 126
fill(value)
rect(50, 20, 35, 60)
2 changes: 2 additions & 0 deletions examples/reference/stroke/stroke1/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/stroke_0.png
2 changes: 2 additions & 0 deletions examples/reference/stroke/stroke1/stroke1.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
stroke(153)
rect(30, 20, 55, 55)
2 changes: 2 additions & 0 deletions examples/reference/stroke/stroke2/.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
reference: https://processing.org/reference/images/stroke_1.png
2 changes: 2 additions & 0 deletions examples/reference/stroke/stroke2/stroke2.rpde
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
stroke(204, 102, 0)
rect(30, 20, 55, 55)
16 changes: 16 additions & 0 deletions src/rprocessing/applet/BuiltinApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PGraphics;

/**
* BuiltinApplet is the type to refactor the function calls.
Expand Down Expand Up @@ -83,6 +84,21 @@ public void noiseDetail(double lod, double falloff) {
super.noiseDetail((int) lod, (float) falloff);
}

public PGraphics createGraphics(double w, double h) {
this.logWarningsforCast();
return super.createGraphics((int) w, (int) h);
}

public PGraphics createGraphics(double w, double h, String renderer) {
this.logWarningsforCast();
return super.createGraphics((int) w, (int) h, renderer);
}

public PGraphics createGraphics(double w, double h, String renderer, String path) {
this.logWarningsforCast();
return super.createGraphics((int) w, (int) h, renderer, path);
}

public double getPI() {
return PI;
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/e2e/core/function/Alpha1Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Generated by hack/generate-e2e-test.py
package test.e2e.core.function;

import static org.junit.Assert.fail;
import org.junit.Test;
import test.e2e.core.E2eTestBase;

public class Alpha1Test extends E2eTestBase {

public Alpha1Test() {
coreCodeTemplate = "noStroke()\nc = color(0, 126, 255, 102)\nfill(c)\nrect(15, 15, 35, 70)\nvalue = alpha(c) # Sets 'value' to 102\nfill(value)\nrect(50, 15, 35, 70)\n\nsaveFrame(\"%s\")\nexit()\n";
referenceURI = "https://processing.org/reference/images/alpha_.png";
}

@Test
public void test() {
try {
defaultOperation();
} catch (Exception exception) {
System.err.println(exception);
fail("Should not have thrown any exception");
}
}
}
25 changes: 25 additions & 0 deletions src/test/e2e/core/function/Background1Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Generated by hack/generate-e2e-test.py
package test.e2e.core.function;

import static org.junit.Assert.fail;
import org.junit.Test;
import test.e2e.core.E2eTestBase;

public class Background1Test extends E2eTestBase {

public Background1Test() {
coreCodeTemplate = "background(51)\n\nsaveFrame(\"%s\")\nexit()\n";
referenceURI = "https://processing.org/reference/images/background_0.png";
}

@Test
public void test() {
try {
defaultOperation();
} catch (Exception exception) {
System.err.println(exception);
fail("Should not have thrown any exception");
}
}
}
25 changes: 25 additions & 0 deletions src/test/e2e/core/function/Background2Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Generated by hack/generate-e2e-test.py
package test.e2e.core.function;

import static org.junit.Assert.fail;
import org.junit.Test;
import test.e2e.core.E2eTestBase;

public class Background2Test extends E2eTestBase {

public Background2Test() {
coreCodeTemplate = "background(255, 204, 0)\n\nsaveFrame(\"%s\")\nexit()\n";
referenceURI = "https://processing.org/reference/images/background_1.png";
}

@Test
public void test() {
try {
defaultOperation();
} catch (Exception exception) {
System.err.println(exception);
fail("Should not have thrown any exception");
}
}
}
25 changes: 25 additions & 0 deletions src/test/e2e/core/function/Blue1Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Generated by hack/generate-e2e-test.py
package test.e2e.core.function;

import static org.junit.Assert.fail;
import org.junit.Test;
import test.e2e.core.E2eTestBase;

public class Blue1Test extends E2eTestBase {

public Blue1Test() {
coreCodeTemplate = "c = color(175, 100, 220) # Define color 'c'\nfill(c) # Use color variable 'c' as fill color\nrect(15, 20, 35, 60) # Draw left rectangle\n\nblueValue = blue(c) # Get blue in 'c'\nprintln(blueValue) # Prints '220.0'\nfill(0, 0, blueValue) # Use 'blueValue' in new fill\nrect(50, 20, 35, 60) # Draw right rectangle\n\nsaveFrame(\"%s\")\nexit()\n";
referenceURI = "https://processing.org/reference/images/blue_.png";
}

@Test
public void test() {
try {
defaultOperation();
} catch (Exception exception) {
System.err.println(exception);
fail("Should not have thrown any exception");
}
}
}
Loading