Skip to content

Commit bfbeffc

Browse files
committed
even fewer loc
1 parent aec50b2 commit bfbeffc

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

processing_app/library/vecmath/vec2d/library/verlet_chain/lib/verlet_ball.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ def render
3939

4040
def bounds_collision
4141
if x_bound.exclude? pos.x
42-
pos.x = constrain pos.x, x_bound.lower, x_bound.upper
43-
pos_old.x = pos.x
44-
pos.x = (pos.x <= radius)? pos.x + push.x : pos.x - push.x
42+
pos_old.x = constrain pos.x, x_bound.lower, x_bound.upper
43+
pos.x = (pos.x <= radius)? pos_old.x + push.x : pos_old.x - push.x
4544
end
4645
return unless y_bound.exclude? pos.y
47-
pos.y = constrain pos.y, y_bound.lower, y_bound.upper
48-
pos_old.y = pos.y
49-
pos.y = (pos.y <= radius)? pos.y + push.y : pos.y - push.y
46+
pos_old.y = constrain pos.y, y_bound.lower, y_bound.upper
47+
pos.y = (pos.y <= radius)? pos_old.y + push.y : pos_old.y - push.y
5048
end
5149
end
5250

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,60 @@
11
#
2-
# Scribble Plotter
3-
# by Ira Greenberg.
4-
#
2+
# Scribble Plotter
3+
# by Ira Greenberg.
4+
#
55
# Using 2-dimensional arrays, record end points
6-
# and replot scribbles between points.
6+
# and replot scribbles between points.
77
#
8-
98
SCRIBBLE = 0
109
HATCHING = 1
1110
attr_reader :xy
1211

1312
def setup
1413
sketch_title 'Scribble Plotter'
1514
background(0)
16-
17-
1815
# Record points
19-
# X positions
16+
# X positions
2017
x = [125, 475, 475, 125]
2118
# Y positions
2219
y = [100, 100, 260, 260]
23-
@xy = [x, y]
24-
20+
@xy = x.zip(y)
2521
# Call plotting function
2622
make_rect(xy)
2723
end
2824

2925
def make_rect(pts)
3026
stroke(255)
31-
3227
# Scribble variables, that get passed as arguments to the scribble function
3328
steps = 100
3429
scrib_val = 3.0
35-
(0 ... xy.length).each do |i|
30+
(0...xy.length).each do |i|
3631
# Plots vertices
3732
stroke_weight(5)
38-
point(pts[0][i], pts[1][i])
39-
33+
point(pts[i][0], pts[i][1])
4034
# Call scribble function
4135
stroke_weight(0.5)
42-
if (i > 0)
43-
scribble(pts[0][i], pts[1][i], pts[0][i-1], pts[1][i-1], steps, scrib_val, SCRIBBLE)
36+
if (i > 0)
37+
scribble(pts[i][0], pts[i][1], pts[i - 1][0], pts[i - 1][1], steps, scrib_val, SCRIBBLE)
4438
end
45-
if (i == pts[0].length-1)
39+
if (i == pts[0].length - 1)
4640
# Show some hatching between last 2 points
47-
scribble(pts[0][i], pts[1][i], pts[0][0], pts[1][0], steps, scrib_val*2, HATCHING)
41+
scribble(pts[i][0], pts[i][1], pts[0][0], pts[1][0], steps, scrib_val * 2, HATCHING)
4842
end
4943
end
5044
end
5145

52-
53-
# Scribble function plots lines between end points,
46+
# Scribble function plots lines between end points,
5447
# determined by steps and scrib_val arguments.
5548
# two styles are available: SCRIBBLE and HATCHING, which
5649
# are interestingly only dependent on parentheses
5750
# placement in the line function calls.
58-
59-
6051
def scribble(x1, y1, x2, y2, steps, scrib_val, style)
61-
6252
x_step = (x2-x1) / steps
6353
y_step = (y2-y1) / steps
64-
(0 ... steps).each do |i|
54+
(0...steps).each do |i|
6555
if(style == SCRIBBLE)
6656
if (i < steps-1)
67-
line(x1, y1, x1 += x_step+rand(-scrib_val..scrib_val), y1 += y_step + rand(-scrib_val..scrib_val))
57+
line(x1, y1, x1 += x_step+rand(-scrib_val..scrib_val), y1 += y_step + rand(-scrib_val..scrib_val))
6858
else
6959
# extra line needed to attach line back to point- not necessary in HATCHING style
7060
line(x1, y1, x2, y2)
@@ -75,8 +65,6 @@ def scribble(x1, y1, x2, y2, steps, scrib_val, style)
7565
end
7666
end
7767

78-
7968
def settings
8069
size(640, 360)
8170
end
82-

0 commit comments

Comments
 (0)