Skip to content

Commit e82ae4f

Browse files
committed
let's get this party started
1 parent 08bf620 commit e82ae4f

File tree

130 files changed

+4416
-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.

130 files changed

+4416
-1
lines changed

README

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
let's roll
1+
___ / ___________ _________________(_)_____________ _
2+
__ / _ _ \ __ `/_ ___/_ __ \_ /__ __ \_ __ `/
3+
_ /___/ __/ /_/ /_ / _ / / / / _ / / / /_/ /
4+
/_____/\___/\__,_/ /_/ /_/ /_//_/ /_/ /_/_\__, /
5+
/____/
6+
________ _____
7+
___ __ \________________________________________(_)_____________ _
8+
__ /_/ /_ ___/ __ \ ___/ _ \_ ___/_ ___/_ /__ __ \_ __ `/
9+
_ ____/_ / / /_/ / /__ / __/(__ )_(__ )_ / _ / / / /_/ /
10+
/_/ /_/ \____/\___/ \___//____/ /____/ /_/ /_/ /_/_\__, /
11+
/____/
12+
________________ ________ ______
13+
___ ____(_)_ /___ /_ ___ __ \___ ____ /______ __
14+
__ | /| / /_ /_ __/_ __ \ __ /_/ / / / /_ __ \_ / / /
15+
__ |/ |/ /_ / / /_ _ / / / _ _, _// /_/ /_ /_/ / /_/ /
16+
____/|__/ /_/ \__/ /_/ /_/ /_/ |_| \__,_/ /_.___/_\__, /
17+
/____/
18+
19+
20+
"Learning Processing" is a 2008 book that serves as a gentle introduction to
21+
the theory and practice of programming. It works by introducing code concepts
22+
over the course of 23 chapters, and creating a series of examples that build
23+
on them. The book was written by professor Daniel Shiffman of the ITP in
24+
New York City.
25+
26+
More information about the book can be found at:
27+
http://www.learningprocessing.com/
28+
29+
These samples have been ported over to Ruby-Processing, which can be found here:
30+
http://wiki.github.com/jashkenas/ruby-processing

chapter_01/1_stroke_and_fill.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This is the simplest form of a Ruby-Processing sketch. A simple sequence
2+
# of instructions that are run a single time to paint a picture.
3+
4+
# Stretch the canvas to 200 pixels wide by 200 pixels tall.
5+
size 200, 200
6+
7+
# Paint the background white.
8+
background 255
9+
10+
# Set the color of strokes to black.
11+
stroke 0
12+
13+
# Set the color of fills to middle gray.
14+
fill 150
15+
16+
# Draw a rectangle 50 pixels over and 50 pixels down from the top left corner,
17+
# with a width of 75 pixels and a height of 100.
18+
rect 50, 50, 75, 100

chapter_01/2_nofill.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Here we introduce a slightly more sophisticated version of a Ruby-Processing
2+
# sketch. The code inside of the setup is run a single time, at the beginning.
3+
def setup
4+
size 200, 200
5+
smooth
6+
background 255
7+
# In Ruby, methods and variables are under_scored instead of camelCased
8+
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);
15+
end
16+
17+
# And the code inside of draw, if there were any, would be drawn over and over.
18+
def draw
19+
20+
end

chapter_01/3_rgb_color.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RGB color is specified by intensity of red, then green, then blue.
2+
3+
size 200, 200
4+
smooth
5+
6+
background 255
7+
no_stroke
8+
9+
# Bright red
10+
fill 255, 0, 0
11+
ellipse 20, 20, 16, 16
12+
13+
# Dark red
14+
fill 127, 0, 0
15+
ellipse 40, 20, 16, 16
16+
17+
# Pink
18+
fill 255, 200, 200
19+
ellipse 60, 20, 16, 16

chapter_01/4_alpha_transparency.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This sketch introduces the fuller version of a Ruby-Processing sketch,
2+
# and demonstrates what's really going on behind the scenes when you make
3+
# one of the simpler sketches, with just a setup method.
4+
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
8+
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
33+
34+
def draw
35+
36+
end
37+
38+
end
39+
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
size 200, 200
2+
background 255
3+
smooth
4+
ellipse_mode CENTER
5+
rect_mode CENTER
6+
7+
# Body
8+
stroke 0
9+
fill 150
10+
rect 100, 100, 20, 100
11+
12+
# Head
13+
fill 255
14+
ellipse 100, 70, 60, 60
15+
16+
# Eyes
17+
fill 0
18+
ellipse 81, 70, 16, 32
19+
ellipse 119, 70, 16, 32
20+
21+
# Legs
22+
stroke 0
23+
line 90, 150, 80, 160
24+
line 110, 150, 120, 160

chapter_02/1_zoog_again.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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
38+
39+
end
40+
41+
ZoogAgain.new :title => "Zoog Again", :width => 200, :height => 200
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'ruby-processing'
2+
3+
class ZoogAsDynamicSketch < Processing::App
4+
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
41+
42+
end
43+
44+
ZoogAsDynamicSketch.new :title => "Zoog As Dynamic Sketch", :width => 200, :height => 200
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'ruby-processing'
2+
3+
class MouseXAndMouseY < Processing::App
4+
5+
def setup
6+
7+
end
8+
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
23+
24+
end
25+
26+
MouseXAndMouseY.new :title => "Mouse X And Mouse Y", :width => 200, :height => 200
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'ruby-processing'
2+
3+
class ZoogAsDynamicSketchWithVariation < Processing::App
4+
5+
def setup
6+
smooth
7+
end
8+
9+
def draw
10+
background 255 # Draw a white background
11+
12+
# Set ellipses and rects to CENTER mode
13+
ellipse_mode CENTER
14+
rect_mode CENTER
15+
16+
# Draw Zoog's body
17+
stroke 0
18+
fill 150
19+
# Zoog's body is drawn at the location (mouse_x, mouse_y)
20+
rect mouse_x, mouse_y, 20, 100
21+
22+
# Draw Zoog's head
23+
stroke 0
24+
fill 255
25+
# Zoog's head is drawn above the body at the location (mouse_x, mouse_y - 30)
26+
ellipse mouse_x, mouse_y - 30, 60, 60
27+
28+
# Draw Zoog's eyes
29+
fill 0
30+
ellipse 81, 70, 16, 32
31+
ellipse 119, 70, 16, 32
32+
33+
# Draw Zoog's legs
34+
stroke 0
35+
line 90, 150, 80, 160
36+
line 110, 150, 120, 160
37+
end
38+
39+
end
40+
41+
ZoogAsDynamicSketchWithVariation.new :title => "Zoog As Dynamic Sketch With Variation", :width => 200, :height => 200

0 commit comments

Comments
 (0)