Skip to content

Commit c941e60

Browse files
author
monkstone
committed
updated a few more add autorun Rakefiles
1 parent afe5d69 commit c941e60

27 files changed

+748
-721
lines changed

README

Lines changed: 0 additions & 30 deletions
This file was deleted.

chapter_01/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

chapter_03/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

chapter_04/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

chapter_05/01_conditionals.rb

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
require 'ruby-processing'
21

3-
class Conditionals < Processing::App
4-
5-
def setup
6-
# Variables
7-
@r, @g, @b = 150, 0, 0
8-
end
2+
def setup
3+
size 200, 200
4+
# Variables
5+
@r, @g, @b = 150, 0, 0
6+
end
97

10-
def draw
11-
#Draw stuff
12-
background @r, @g, @b
13-
stroke 255
14-
line width/2, 0, width/2, height
15-
16-
# The following checks use the "ternary operator" which is a compact way
17-
# of saying, "if this is true ? do this : otherwise this"
8+
def draw
9+
#Draw stuff
10+
background @r, @g, @b
11+
stroke 255
12+
line width / 2, 0, width / 2, height
13+
14+
# The following checks use the "ternary operator" which is a compact way
15+
# of saying, "if this is true ? do this : otherwise this"
1816

19-
# If the mouse is on the right side of the screen is equivalent to
20-
# "if mouse_x is greater than width divided by 2."
21-
(mouse_x > width/2) ? @r += 1 : @r -=1
17+
# If the mouse is on the right side of the screen is equivalent to
18+
# "if mouse_x is greater than width divided by 2."
19+
(mouse_x > width / 2) ? @r += 1 : @r -=1
2220

23-
# If r is greater than 255, set it back to 255.
24-
# If r is less than 0, set it back to 0.
25-
@r = 255 if @r > 255
26-
@r = 0 if @r < 0
27-
end
28-
29-
end
21+
# If r is greater than 255, set it back to 255.
22+
# If r is less than 0, set it back to 0.
23+
@r = 255 if @r > 255
24+
@r = 0 if @r < 0
25+
end
26+
3027

31-
Conditionals.new :title => "Conditionals", :width => 200, :height => 200

chapter_05/02_more_conditionals.rb

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
require 'ruby-processing'
21

3-
class MoreConditionals < Processing::App
4-
5-
def setup
6-
# Three variables for the background color.
7-
@r, @g, @b = 0, 0, 0
8-
end
2+
def setup
3+
size 200, 200
4+
# Three variables for the background color.
5+
@r, @g, @b = 0, 0, 0
6+
end
97

10-
def draw
11-
# Color the background and draw lines to divide the window in quadrants.
12-
background @r, @g, @b
13-
stroke 0
14-
line width/2, 0, width/2, height
15-
line 0, height/2, width, height/2
16-
17-
# The following checks use the "ternary operator" which is a compact way
18-
# of saying, "if this is true ? do this : otherwise this"
19-
20-
# If the mouse is on the right hand side of the window, increase red.
21-
# Otherwise, it is on the left hand side and decrease red.
22-
(mouse_x > width / 2) ? @r += 1 : @r -= 1
23-
24-
# If the mouse is on the bottom of the window, increase blue.
25-
# Otherwise, it is on the top and decrease blue.
26-
(mouse_y > height/2) ? @b += 1 : @b -= 1
27-
28-
# If the mouse is pressed. (for green)
29-
mouse_pressed? ? @g += 1 : @g -= 1
30-
31-
# Constrain all color values to between 0 and 255.
32-
@r = constrain(@r, 0, 255)
33-
@g = constrain(@g, 0, 255)
34-
@b = constrain(@b, 0, 255)
35-
end
8+
def draw
9+
size 200, 200
10+
# Color the background and draw lines to divide the window in quadrants.
11+
background @r, @g, @b
12+
stroke 0
13+
line width/2, 0, width/2, height
14+
line 0, height/2, width, height/2
15+
16+
# The following checks use the "ternary operator" which is a compact way
17+
# of saying, "if this is true ? do this : otherwise this"
18+
19+
# If the mouse is on the right hand side of the window, increase red.
20+
# Otherwise, it is on the left hand side and decrease red.
21+
(mouse_x > width / 2) ? @r += 1 : @r -= 1
22+
23+
# If the mouse is on the bottom of the window, increase blue.
24+
# Otherwise, it is on the top and decrease blue.
25+
(mouse_y > height/2) ? @b += 1 : @b -= 1
26+
27+
# If the mouse is pressed. (for green)
28+
mouse_pressed? ? @g += 1 : @g -= 1
29+
30+
# Constrain all color values to between 0 and 255.
31+
@r = constrain(@r, 0, 255)
32+
@g = constrain(@g, 0, 255)
33+
@b = constrain(@b, 0, 255)
3634
end
3735

38-
MoreConditionals.new :title => "More Conditionals", :width => 200, :height => 200

chapter_05/03_rollovers.rb

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
require 'ruby-processing'
21

3-
class Rollovers < Processing::App
42

5-
def setup
3+
def setup
4+
size 200, 200
5+
end
6+
7+
def draw
8+
background 255
9+
stroke 0
10+
line 100, 0, 100, 200
11+
line 0, 100, 200, 100
612

7-
end
13+
# Fill a black color
14+
no_stroke
15+
fill 0
816

9-
def draw
10-
background 255
11-
stroke 0
12-
line 100, 0, 100, 200
13-
line 0, 100, 200, 100
14-
15-
# Fill a black color
16-
no_stroke
17-
fill 0
18-
19-
# Depending on the mouse location, a different rectangle is displayed.
20-
if mouse_x < 100 && mouse_y < 100
21-
rect 0, 0, 100, 100
22-
elsif mouse_x > 100 && mouse_y < 100
23-
rect 100, 0, 100, 100
24-
elsif mouse_x < 100 && mouse_y > 100
25-
rect 0, 100, 100, 100
26-
elsif mouse_x > 100 && mouse_y > 100
27-
rect 100, 100, 100, 100
28-
end
29-
17+
# Depending on the mouse location, a different rectangle is displayed.
18+
if mouse_x < 100 && mouse_y < 100
19+
rect 0, 0, 100, 100
20+
elsif mouse_x > 100 && mouse_y < 100
21+
rect 100, 0, 100, 100
22+
elsif mouse_x < 100 && mouse_y > 100
23+
rect 0, 100, 100, 100
24+
elsif mouse_x > 100 && mouse_y > 100
25+
rect 100, 100, 100, 100
3026
end
3127

3228
end
3329

34-
Rollovers.new :title => "Rollovers", :width => 200, :height => 200
30+
Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
require 'ruby-processing'
21

3-
class HoldDownTheButton < Processing::App
2+
def setup
3+
size 200, 200
4+
@x, @y = 50, 50
5+
@w, @h = 100, 75
6+
end
47

5-
def setup
6-
@x, @y = 50, 50
7-
@w, @h = 100, 75
8+
def draw
9+
# The button is pressed if (mouse_x, mouse_y) is inside
10+
# the rectangle and mouse_pressed? is true.
11+
if mouse_x > @x && mouse_x < @x+@w && mouse_y > @y && mouse_y < @y+@h && mouse_pressed?
12+
button = true
13+
else
14+
button = false
815
end
916

10-
def draw
11-
# The button is pressed if (mouse_x, mouse_y) is inside
12-
# the rectangle and mouse_pressed? is true.
13-
if mouse_x > @x && mouse_x < @x+@w && mouse_y > @y && mouse_y < @y+@h && mouse_pressed?
14-
button = true
15-
else
16-
button = false
17-
end
18-
19-
if button
20-
background 255
21-
stroke 0
22-
else
23-
background 0
24-
stroke 255
25-
end
26-
27-
fill 175
28-
rect @x, @y, @w, @h
17+
if button
18+
background 255
19+
stroke 0
20+
else
21+
background 0
22+
stroke 255
2923
end
30-
24+
25+
fill 175
26+
rect @x, @y, @w, @h
3127
end
32-
33-
HoldDownTheButton.new :title => "Hold Down The Button", :width => 200, :height => 200
28+

0 commit comments

Comments
 (0)