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-
98SCRIBBLE = 0
109HATCHING = 1
1110attr_reader :xy
1211
1312def 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 )
2723end
2824
2925def 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
5044end
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-
6051def 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
7666end
7767
78-
7968def settings
8069 size ( 640 , 360 )
8170end
82-
0 commit comments