Skip to content

Commit 5074dd2

Browse files
author
monkstone
committed
Mainly convert map to map1d
1 parent d2ae948 commit 5074dd2

File tree

27 files changed

+276
-360
lines changed

27 files changed

+276
-360
lines changed

samples/contributed/quadraticvertex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def draw
3636
@step_angle = TAU / (detail.to_i - 1)
3737
fill color('#ffffff')
3838
no_stroke
39-
@cr = map(mouse_x, 0, width, 20, 200)
39+
@cr = map1d(mouse_x, (0..width) , (20..200))
4040
begin_shape
4141
detail.to_i.times do |i|
4242
if (i == 0)

samples/external_library/java_processing/guido/slider.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load_library :guido
1+
load_library :Guido # warning should be lowercase lib author may correct this
22
import 'de.bezier.guido'
33

44
def setup
@@ -41,7 +41,7 @@ def mouseDragged(mx, my, dx, dy)
4141
@value_x = mx - @height / 2
4242
@value_x = @x if (@value_x < @x)
4343
@value_x = @x + @width - @height if (@value_x > @x + @width - @height)
44-
@value = map(@value_x, @x, @x + @width - @height, 0, 1)
44+
@value = map1d(@value_x, (@x..@x + @width - @height), (0..1))
4545
end
4646

4747
def draw

samples/processing_app/basics/arrays/array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup
1010
size 640, 360
1111
coswave = []
1212
0.upto(width) do |i|
13-
amount = map i, 0, width, 0, PI
13+
amount = map1d(i, (0..width), (0..PI))
1414
coswave[i] = cos(amount).abs
1515
end
1616
0.upto(width) do |i|
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
# Simple Linear Gradient
2-
#
1+
# Simple Linear Gradient
2+
#
33
# The lerp_color function is useful for interpolating
44
# between two colors.
55
#
6-
6+
77
Y_AXIS = 1
88
X_AXIS = 2
99

1010
def setup
11-
size 640, 360
11+
size 640, 360
1212
# Define colors
1313
b1 = color(255)
1414
b2 = color(0)
1515
c1 = color(204, 102, 0)
1616
c2 = color(0, 102, 153)
17-
1817
# Background
19-
set_gradient(0, 0, width/2, height, b1, b2, X_AXIS)
20-
set_gradient(width/2, 0, width/2, height, b2, b1, X_AXIS)
18+
set_gradient(0, 0, width / 2, height, b1, b2, X_AXIS)
19+
set_gradient(width / 2, 0, width / 2, height, b2, b1, X_AXIS)
2120
# Foreground
2221
set_gradient(50, 90, 540, 80, c1, c2, Y_AXIS)
2322
set_gradient(50, 190, 540, 80, c2, c1, X_AXIS)
2423
end
2524

26-
def set_gradient(x, y, w, h, c1, c2, axis )
25+
def set_gradient(x, y, w, h, c1, c2, axis)
2726
no_fill
2827
if (axis == Y_AXIS) # Top to bottom gradient
29-
(y ... y + h).each do |i|
30-
inter = map(i, y, y + h, 0, 1)
28+
(y...y + h).each do |i|
29+
inter = map1d(i, (y..y + h), (0..1.0))
3130
stroke lerp_color(c1, c2, inter)
3231
line(x, i, x + w, i)
3332
end
3433
elsif (axis == X_AXIS) # Left to right gradient
35-
(x ... x + w).each do |i|
36-
inter = map(i, x, x + w, 0, 1)
34+
(x...x + w).each do |i|
35+
inter = map1d(i, (x..x + w), (0..1))
3736
stroke lerp_color(c1, c2, inter)
3837
line(i, y, i, y + h)
3938
end
4039
end
4140
end
42-

samples/processing_app/basics/form/triangle_strip.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,26 @@
1010
attr_reader :x, :y, :outer_radius, :inner_radius
1111

1212
def setup
13-
size 640, 360
14-
@x = width/2
15-
@y = height/2
13+
size 640, 360
14+
@x = width / 2
15+
@y = height / 2
1616
@outer_radius = [width, height].min * 0.4
1717
@inner_radius = outer_radius * 0.6
1818
end
1919

2020
def draw
2121
background 204
22-
pts = map(mouse_x, 0, width, 6, 60).to_i
23-
angle = 0.0 # degrees
24-
step = 180.0/pts # degrees
25-
22+
pts = map1d(mouse_x, (0..width), (6..60)).to_i
23+
angle = 0.0 # degrees
24+
step = 180.0 / pts # degrees
2625
begin_shape TRIANGLE_STRIP
27-
(0..pts).each do
28-
px = x + cos(angle.radians)*outer_radius
29-
py = y + sin(angle.radians)*outer_radius
26+
(0..pts).each do
27+
px = x + cos(angle.radians) * outer_radius
28+
py = y + sin(angle.radians) * outer_radius
3029
angle += step
3130
vertex px, py
32-
33-
px = x + cos(angle.radians)*inner_radius
34-
py = y + sin(angle.radians)*inner_radius
31+
px = x + cos(angle.radians) * inner_radius
32+
py = y + sin(angle.radians) * inner_radius
3533
angle += step
3634
vertex px, py
3735
end

samples/processing_app/basics/image/pointillism.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
21
# Pointillism
3-
# by Daniel Shiffman.
4-
#
5-
# Mouse horizontal location controls size of dots.
2+
# by Daniel Shiffman.
3+
#
4+
# Mouse horizontal location controls size of dots.
65
# Creates a simple pointillist effect using ellipses colored
7-
# according to pixels in an image.
8-
6+
# according to pixels in an image.
97

108
def setup
119
size 400, 400
12-
@a = load_image "eames.jpg"
10+
@a = load_image 'eames.jpg'
1311
no_stroke
1412
background 255
1513
smooth
1614
end
1715

1816
def draw
19-
pointillize = map(mouse_x, 0, width, 2, 18)
17+
pointillize = map1d(mouse_x, (0..width), (2..18))
2018
x, y = rand(@a.width), rand(@a.height)
2119
pixel = @a.get(x, y)
2220
fill pixel, 126
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# Move the pointer left and right across the image to change
2-
# its position. This program overlays one image over another
3-
# by modifying the alpha value of the image with the tint() function.
4-
5-
2+
# its position. This program overlays one image over another
3+
# by modifying the alpha value of the image with the tint() function.
64

75
def setup
86
size 200, 200
9-
@a = load_image "construct.jpg"
10-
@b = load_image "wash.jpg"
11-
@offset = 0.0
7+
@a = load_image 'construct.jpg'
8+
@b = load_image 'wash.jpg'
9+
@offset = 0.0
1210
end
1311

1412
def draw
1513
image @a, 0, 0
16-
offset_target = map(mouse_x, 0, width, -@b.width/2 - width/2, 0)
14+
offset_target = map1d(mouse_x, (0..width), (-@b.width / 2 - width / 2..0))
1715
@offset += (offset_target - @offset) * 0.05
1816
tint 255, 153
1917
image @b, @offset, 20
2018
end
21-
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
# Click into the window to give it focus and press the letter keys
2-
# to create forms in time and space. Each key has a unique identifying
3-
# number called it's ASCII value. These numbers can be used to position
4-
# shapes in space.
5-
1+
# Click into the window to give it focus and press the letter keys
2+
# to create forms in time and space. Each key has a unique identifying
3+
# number called it's ASCII value. These numbers can be used to position
4+
# shapes in space.
65

76
def setup
87
size 640, 360
98
@num_chars = 26
10-
@key_scale = 200.0 / @num_chars-1.0
11-
@rect_width = width/4
9+
@key_scale = 200.0 / @num_chars - 1.0
10+
@rect_width = width / 4
1211
no_stroke
1312
background 0
1413
end
1514

1615
def draw
17-
if key_pressed? && ('A'..'z').include?(key)
18-
@key_index = key.ord - (key <= 'Z' ? 'A'.ord : 'a'.ord)
19-
fill millis % 255
20-
begin_rect = map(@key_index, 0, 25, 0, width - @rect_width)
21-
rect begin_rect, 0, @rect_width, height
22-
end
16+
return unless key_pressed? && ('A'..'z').include?(key)
17+
@key_index = key.ord - (key <= 'Z' ? 'A'.ord : 'a'.ord)
18+
fill millis % 255
19+
begin_rect = map1d(@key_index, (0..25), (0..width - @rect_width))
20+
rect begin_rect, 0, @rect_width, height
2321
end
24-
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Move the mouse left and right to shift the balance.
2-
# The "mouseX" variable is used to control both the
3-
# size and color of the rectangles.
1+
# Move the mouse left and right to shift the balance.
2+
# The "mouseX" variable is used to control both the
3+
# size and color of the rectangles.
44

55
def setup
66
size 640, 360
@@ -11,17 +11,13 @@ def setup
1111

1212
def draw
1313
background 0
14-
15-
x_dist_blocks = width/2
16-
block_size = map(mouse_x, 0, width, 10, x_dist_blocks - 10)
17-
14+
x_dist_blocks = width / 2
15+
block_size = map1d(mouse_x, (0..width), (10..x_dist_blocks - 10))
1816
left_color = -0.002 * mouse_x / 2 + 0.06
1917
fill 0.0, left_color + 0.4, left_color + 0.6
20-
rect(width/4, height / 2, block_size * 2, block_size * 2)
21-
18+
rect(width / 4, height / 2, block_size * 2, block_size * 2)
2219
block_size = x_dist_blocks - block_size
23-
24-
right_color = 0.002 * mouse_x/2 + 0.06
20+
right_color = 0.002 * mouse_x / 2 + 0.06
2521
fill(0.0, right_color + 0.2, right_color + 0.4)
2622
rect((width / 4) * 3, height / 2, block_size * 2, block_size * 2)
2723
end
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
1-
# Lights 2
2-
# by Simon Greenwold.
3-
#
4-
# Display a box with three different kinds of lights.
5-
6-
1+
# Lights 2
2+
# by Simon Greenwold.
3+
#
4+
# Display a box with three different kinds of lights.
75

86
def setup
9-
107
size 640, 360, P3D
11-
128
no_stroke
13-
149
end
1510

1611
def draw
17-
1812
background 0
19-
20-
translate width/2, height/2
21-
22-
point_light 150, 100, 0, #color
23-
200, -150, 0 #position
24-
25-
directional_light 0, 102, 255, #color
26-
1, 0, 0 #x-,y-,z-axis direction
27-
28-
spot_light 255, 255, 109, #color
29-
0, 40, 200, #position
30-
0,-0.5,-0.5, #direction
31-
PI/2, 2 #angle, concentration
32-
33-
rotate_y map( mouse_x, 0, width, 0, PI )
34-
rotate_x map( mouse_y, 0, height, 0, PI )
35-
13+
translate width / 2, height / 2
14+
point_light 150, 100, 0, # color
15+
200, -150, 0 # position
16+
directional_light 0, 102, 255, # color
17+
1, 0, 0 # x-,y-,z-axis direction
18+
19+
spot_light 255, 255, 109, # color
20+
0, 40, 200, # position
21+
0, -0.5, -0.5, # direction
22+
PI / 2, # angle
23+
2 # concentration
24+
rotate_y map1d(mouse_x, (0..width), (0..PI))
25+
rotate_x map1d(mouse_y, (0..height), (0..PI))
3626
box 150
37-
3827
end

0 commit comments

Comments
 (0)