Skip to content

Commit 5d28a79

Browse files
author
monkstone
committed
first commit
1 parent dfabaa5 commit 5d28a79

File tree

741 files changed

+52198
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

741 files changed

+52198
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Example-Sketches
22
================
33

4-
Many of the vanilla processing example sketches have been translated to ruby-processing
4+
Many of the vanilla processing example sketches have been translated to ruby-processing, and they are mainly written as 'bare' sketches (ie not class wrapped) in keeping with the original processing. When these sketches the get wrapped in a Sketch class. Should you prefer to write class wrapped sketches these will work equally well with ruby processing. Certain sketch must be run with JRuby-Complete (`load_image` and `shader` sketches), this is some java permissions thing with jruby.

samples/Rakefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
desc 'run contributed samples'
4+
task :default => [:contributed]
5+
6+
desc 'run contributed samples'
7+
task :contributed do
8+
sh "cd contributed && rake"
9+
end
10+
11+
desc 'shaders'
12+
task :shaders do
13+
sh "cd processing_app/topics/shaders && rake"
14+
end
15+
16+
desc 'vecmath'
17+
task :vecmath do
18+
sh "cd processing_app/library/vecmath/vec2d && rake"
19+
# sh "cd processing_app/library/vecmath/vec3d && rake"
20+
# sh "cd processing_app/library/vecmath/arc_ball && rake"
21+
end

samples/configRP5/configRP5.pde

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import java.io.File;
2+
3+
Button enter, nojruby;
4+
String processingRoot = "enter your processing root here"; // edit this line in the sketch
5+
String done = "Done";
6+
String OS = System.getProperty("os.name").toLowerCase();
7+
String home, suggestion, separator, root;
8+
PFont font;
9+
float rectX, rectX2, rectY; // Position of buttons
10+
float rectHeight = 30; // height of rect
11+
float rectWidth = 90; // width of rect
12+
int rectColor, rectColor2;
13+
int rectHighlight, rectHighlight2;
14+
int currentColor;
15+
int selectedColor;
16+
boolean acceptOver = false;
17+
boolean noJruby = false;
18+
boolean selected = false;
19+
boolean no_jruby = false;
20+
// The JSON object
21+
JSONObject json;
22+
23+
void setup() {
24+
size(600, 200);
25+
home = System.getProperty("user.home");
26+
File f = new File(home);
27+
json = new JSONObject();
28+
root = f.getParent();
29+
separator = System.getProperty("file.separator");
30+
font = createFont("Helvetica", 18);
31+
if (OS.contains("mac")) {
32+
suggestion = "/Applications/Processing.app/Contents/Resources/Java";
33+
} else {
34+
suggestion = home + separator + "processing-2.2.1";
35+
}
36+
rectColor = color(140);
37+
rectColor2 = color(140);
38+
rectHighlight = color(100);
39+
rectHighlight2 = color(100);
40+
selectedColor = color(0);
41+
rectX = rectWidth + 20;
42+
rectX2 = rectWidth + 150;
43+
rectY = height * 0.8 - rectHeight / 4;
44+
enter = new Button(rectX2, rectY, rectWidth, rectHeight, "enter");
45+
nojruby = new Button(rectX, rectY, rectWidth, rectHeight, "nojruby");
46+
}
47+
48+
void draw() {
49+
background(200);
50+
fill(0, 0, 200);
51+
text("Suggestion:", 35, 28);
52+
text(suggestion, 35, 56);
53+
textFont(font, 18);
54+
fill(255, 0, 0);
55+
// this adds a blinking cursor after your text, at the expense of redrawing everything every frame
56+
text(processingRoot + (frameCount / 10 % 2 == 0 ? "_" : ""), 35, 100);
57+
fill(0, 0, 200);
58+
text("Select nojruby to use jruby-complete by default", 35, 140);
59+
update(mouseX, mouseY);
60+
//background(200);
61+
62+
if (acceptOver) {
63+
enter.draw(rectHighlight);
64+
nojruby.draw(rectHighlight2);
65+
} else {
66+
enter.draw(rectColor);
67+
nojruby.draw(rectColor2);
68+
}
69+
}
70+
71+
void writeRoot() {
72+
rectColor = selectedColor;
73+
rectHighlight = selectedColor;
74+
json.setString("PROCESSING_ROOT", processingRoot);
75+
json.setBoolean("JRUBY", no_jruby);
76+
json.setInt("X_OFF", floor(displayWidth * 0.1));
77+
json.setInt("Y_OFF", floor(displayHeight * 0.1));
78+
79+
saveJSONObject(json, home + separator + ".rp5rc");
80+
processingRoot = done;
81+
}
82+
83+
84+
void keyReleased() {
85+
if (key != CODED) {
86+
switch (key) {
87+
case BACKSPACE:
88+
processingRoot = processingRoot.substring(0, max(0, processingRoot.length() - 1));
89+
break;
90+
case ENTER: // save the processing root to the config file
91+
case RETURN:
92+
writeRoot();
93+
break;
94+
case ESC:
95+
case DELETE:
96+
break;
97+
default:
98+
processingRoot += key;
99+
}
100+
}
101+
}
102+
103+
void update(float x, float y) {
104+
acceptOver = enter.overRect();
105+
noJruby = nojruby.overRect();
106+
}
107+
108+
109+
void mouseClicked() {
110+
update(mouseX, mouseY);
111+
if (acceptOver) {
112+
rectColor = selectedColor;
113+
rectHighlight = selectedColor;
114+
writeRoot();
115+
}
116+
if (noJruby) {
117+
rectColor2 = selectedColor;
118+
rectHighlight2 = selectedColor;
119+
no_jruby = true;
120+
}
121+
}
122+
123+
class Button {
124+
125+
float x, y, w, h;
126+
String text;
127+
128+
Button(float x, float y, float w, float h, String text) {
129+
this.x = x;
130+
this.y = y;
131+
this.w = w;
132+
this.h = h;
133+
this.text = text;
134+
}
135+
136+
void draw(int col) {
137+
fill(col);
138+
rect(x, y, w, h, 20, 20, 20, 20);
139+
fill(255);
140+
text(text, x + 8, y + 20);
141+
}
142+
143+
boolean overRect() {
144+
return (mouseX >= x && mouseX <= x + w
145+
&& mouseY >= y && mouseY <= y + h);
146+
}
147+
}

samples/contributed/Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to rp5 executable, and or opts as required
3+
4+
SAMPLES_DIR = './'
5+
6+
desc 'run demo'
7+
task default: [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each{ |sample| run_sample sample }
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob('*.rb').each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|rp5 run #{sample_name}", 'r') do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end

samples/contributed/animator.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# From the Processing Examples
2+
# Uses the "bare" style, where a Processing::App sketch is implicitly wrapped
3+
# around the code.
4+
# -- omygawshkenas
5+
6+
FRAME_COUNT = 12
7+
8+
def setup
9+
size 350, 350
10+
@frames = []
11+
@last_time = 0
12+
@current_frame = 0
13+
@draw = false
14+
@back_color = 204
15+
stroke_weight 4
16+
smooth
17+
background @back_color
18+
FRAME_COUNT.times { @frames << get }
19+
end
20+
21+
def draw
22+
time = millis
23+
if time > @last_time + 100
24+
next_frame
25+
@last_time = time
26+
end
27+
line(pmouse_x, pmouse_y, mouse_x, mouse_y) if @draw
28+
end
29+
30+
def mouse_pressed
31+
@draw = true
32+
end
33+
34+
def mouse_released
35+
@draw = false
36+
end
37+
38+
def key_pressed
39+
background @back_color
40+
@frames.size.times { |i| @frames[i] = get }
41+
end
42+
43+
def next_frame
44+
@frames[@current_frame] = get
45+
@current_frame += 1
46+
@current_frame = 0 if @current_frame >= @frames.size
47+
image(@frames[@current_frame], 0, 0)
48+
end

0 commit comments

Comments
 (0)