Skip to content

Commit afe5d69

Browse files
author
monkstone
committed
first update in 4 years
1 parent 0b5beb0 commit afe5d69

21 files changed

+375
-418
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.*~
2+

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Learning Processing][] by Daniel Shiffman is an book that serves as a gentle introduction to
2+
the theory and practice of programming. It works by introducing code concepts
3+
over the course of 23 chapters, and creating a series of examples that build
4+
on them. Daniel Shiffman is a professor of the Interactive Telecommunications Program at New York University.
5+
6+
7+
8+
These samples have been ported over to [Ruby-Processing][]
9+
10+
[Learning Processing]:http://www.learningprocessing.com/
11+
[Ruby-Processing]:http://wiki.github.com/jashkenas/ruby-processing
12+
13+
http://natureofcode.com/

chapter_01/2_nofill.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
# Here we introduce a slightly more sophisticated version of a Ruby-Processing
22
# sketch. The code inside of the setup is run a single time, at the beginning.
3+
# Note: parentheses are mostly optional, add them if you think it makes your code clearer
34
def setup
45
size 200, 200
5-
smooth
6+
smooth 4
67
background 255
78
# In Ruby, methods and variables are under_scored instead of camelCased
89
no_fill
9-
stroke 0
10-
# You might notice that there are no parenthesis or semicolons.
11-
# That's because they're optional.
12-
ellipse 60, 60, 100, 100
13-
# This line works too:
14-
ellipse(60, 60, 100, 100);
10+
stroke 0
11+
ellipse 60, 60, 100, 100
1512
end
1613

1714
# And the code inside of draw, if there were any, would be drawn over and over.
1815
def draw
1916

20-
end
17+
end

chapter_01/3_rgb_color.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RGB color is specified by intensity of red, then green, then blue.
22

33
size 200, 200
4-
smooth
4+
smooth 4
55

66
background 255
77
no_stroke

chapter_01/4_alpha_transparency.rb

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,35 @@
22
# and demonstrates what's really going on behind the scenes when you make
33
# one of the simpler sketches, with just a setup method.
44

5-
# A sketch is a class that inherits from the Processing::App, which works
6-
# very much along the lines of a PApplet in Processing.
7-
class AlphaTransparency < Processing::App
85

9-
def setup
10-
background 0
11-
no_stroke
12-
13-
# No fourth argument means 100% opacity
14-
fill 0, 0, 255
15-
rect 0, 0, 100, 200
16-
17-
# 255 means 100% opacity
18-
fill 255, 0, 0, 255
19-
rect 0, 0, 200, 40
20-
21-
# 75% opacity
22-
fill 255, 0, 0, 191
23-
rect 0, 50, 200, 40
24-
25-
# 55% opacity
26-
fill 200, 0, 0, 127
27-
rect 0, 100, 200, 40
28-
29-
# 25% opacity
30-
fill 255, 0, 0, 63
31-
rect 0, 150, 200, 40
32-
end
6+
def setup
7+
size 200, 200
8+
background 0
9+
no_stroke
3310

34-
def draw
11+
# No fourth argument means 100% opacity
12+
fill 0, 0, 255
13+
rect 0, 0, 100, 200
3514

36-
end
15+
# 255 means 100% opacity
16+
fill 255, 0, 0, 255
17+
rect 0, 0, 200, 40
3718

19+
# 75% opacity
20+
fill 255, 0, 0, 191
21+
rect 0, 50, 200, 40
22+
23+
# 55% opacity
24+
fill 200, 0, 0, 127
25+
rect 0, 100, 200, 40
26+
27+
# 25% opacity
28+
fill 255, 0, 0, 63
29+
rect 0, 150, 200, 40
30+
end
31+
32+
def draw
33+
3834
end
35+
3936

40-
# After defining your sketch, you create one.
41-
# If you prefer, you may set the width, height, and title as you create it.
42-
AlphaTransparency.new :title => "Alpha Transparency", :width => 200, :height => 200

chapter_01/5_zoog.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
size 200, 200
22
background 255
3-
smooth
3+
smooth 4
44
ellipse_mode CENTER
55
rect_mode CENTER
66

@@ -21,4 +21,4 @@
2121
# Legs
2222
stroke 0
2323
line 90, 150, 80, 160
24-
line 110, 150, 120, 160
24+
line 110, 150, 120, 160

chapter_02/1_zoog_again.rb

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
1-
# Let's do Zoog again, as part of a complete sketch, showing the class for it,
2-
# with setup and draw methods, and sketch creation at the bottom.
3-
4-
5-
class ZoogAgain < Processing::App
6-
7-
def setup
8-
background 255
9-
smooth
10-
11-
# Set ellipses and rects to CENTER mode
12-
ellipse_mode CENTER
13-
rect_mode CENTER
14-
15-
# Draw Zoog's body
16-
stroke 0
17-
fill 150
18-
rect 100, 100, 20, 100
19-
20-
# Draw Zoog's head
21-
fill 255
22-
ellipse 100, 70, 60, 60
23-
24-
# Draw Zoog's eyes
25-
fill 0
26-
ellipse 81, 70, 16, 32
27-
ellipse 119, 70, 16, 32
28-
29-
# Draw Zoog's legs
30-
stroke 0
31-
line 90, 150, 80, 160
32-
line 110, 150, 120, 160
33-
end
34-
35-
def draw
36-
37-
end
1+
# with setup and draw methods.
2+
3+
def setup
4+
size 200, 200
5+
background 255
6+
smooth
387

8+
# Set ellipses and rects to CENTER mode
9+
ellipse_mode CENTER
10+
rect_mode CENTER
11+
12+
# Draw Zoog's body
13+
stroke 0
14+
fill 150
15+
rect 100, 100, 20, 100
16+
17+
# Draw Zoog's head
18+
fill 255
19+
ellipse 100, 70, 60, 60
20+
21+
# Draw Zoog's eyes
22+
fill 0
23+
ellipse 81, 70, 16, 32
24+
ellipse 119, 70, 16, 32
25+
26+
# Draw Zoog's legs
27+
stroke 0
28+
line 90, 150, 80, 160
29+
line 110, 150, 120, 160
30+
end
31+
32+
def draw
33+
3934
end
4035

41-
ZoogAgain.new :title => "Zoog Again", :width => 200, :height => 200
36+
37+
Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
1-
require 'ruby-processing'
21

3-
class ZoogAsDynamicSketch < Processing::App
42

5-
# Setup runs first one time.
6-
# In Ruby-Processing, you never need to call size(),
7-
# just set the width and height when you instantiate the sketch,
8-
# at the bottom.
9-
def setup
10-
11-
end
12-
13-
# Draw loops continuously until you close the sketch window.
14-
def draw
15-
# Draw a white background
16-
background 255
17-
18-
# Set CENTER mode
19-
ellipse_mode CENTER
20-
rect_mode CENTER
21-
22-
# Draw Zoog's body
23-
stroke 0
24-
fill 150
25-
rect 100, 100, 20, 100
26-
27-
# Draw Zoog's head
28-
fill 255
29-
ellipse 100, 70, 60, 60
30-
31-
# Draw Zoog's eyes
32-
fill 0
33-
ellipse 81, 70, 16, 32
34-
ellipse 119, 70, 16, 32
35-
36-
# Draw Zoog's legs
37-
stroke 0
38-
line 90, 150, 80, 160
39-
line 110, 150, 120, 160
40-
end
3+
# Setup runs first one time.
4+
# In Ruby-Processing, you never need to call size(),
5+
# just set the width and height when you instantiate the sketch,
6+
# at the bottom.
7+
def setup
8+
size 200, 200
9+
end
10+
11+
# Draw loops continuously until you close the sketch window.
12+
def draw
13+
# Draw a white background
14+
background 255
4115

16+
# Set CENTER mode
17+
ellipse_mode CENTER
18+
rect_mode CENTER
19+
20+
# Draw Zoog's body
21+
stroke 0
22+
fill 150
23+
rect 100, 100, 20, 100
24+
25+
# Draw Zoog's head
26+
fill 255
27+
ellipse 100, 70, 60, 60
28+
29+
# Draw Zoog's eyes
30+
fill 0
31+
ellipse 81, 70, 16, 32
32+
ellipse 119, 70, 16, 32
33+
34+
# Draw Zoog's legs
35+
stroke 0
36+
line 90, 150, 80, 160
37+
line 110, 150, 120, 160
4238
end
4339

44-
ZoogAsDynamicSketch.new :title => "Zoog As Dynamic Sketch", :width => 200, :height => 200
40+
Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
require 'ruby-processing'
2-
3-
class MouseXAndMouseY < Processing::App
4-
5-
def setup
1+
def setup
2+
size 200, 200
3+
end
64

7-
end
5+
def draw
6+
# Try moving background to setup and see the difference!
7+
background 255
88

9-
def draw
10-
# Try moving background to setup and see the difference!
11-
background 255
12-
13-
# Body
14-
stroke 0
15-
fill 175
16-
rect_mode CENTER
17-
18-
# mouse_x is a keyword that the sketch replaces with the
19-
# horizontal position of the mouse.
20-
# mouse_y gets the vertical position.
21-
rect mouse_x, mouse_y, 50, 50
22-
end
9+
# Body
10+
stroke 0
11+
fill 175
12+
rect_mode CENTER
2313

14+
# mouse_x is a keyword that the sketch replaces with the
15+
# horizontal position of the mouse.
16+
# mouse_y gets the vertical position.
17+
rect mouse_x, mouse_y, 50, 50
2418
end
2519

26-
MouseXAndMouseY.new :title => "Mouse X And Mouse Y", :width => 200, :height => 200

0 commit comments

Comments
 (0)