Skip to content

Commit 8bbbe22

Browse files
committed
dry up sketch
1 parent a2ba74a commit 8bbbe22

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

processing_app/library/vecmath/vec2d/circumcircle_sketch.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Here is a sketch that clearly demonstrates some of the most egregious parts of
44
# vanilla processing:-
55
# PVector is over complicated and overloads 2D and 3D functionality, cf Vec2D
6-
# JRubyArt and propane which behaves as 2D vector (cross product is a float) and
7-
# can be used in chain calculations.
6+
# JRubyArt and propane which behaves as a 2D vector (cross product is a float)
7+
# and can easily be used in chain calculations.
88
# The inverted Y axis in processing requires remapping to use in graphs etc.
9-
# The map method of processing can be used to this remapping, however in many
9+
# The map method of processing can be used to do this remapping, however in many
1010
# languages (python, ruby etc) map is a keyword with alternative usage.
1111
# For this reason in JRubyArt and propane we have replaced vanilla processing
1212
# map with map1d.
@@ -34,6 +34,7 @@ def setup
3434
@font = create_font('Arial', 16, true)
3535
@points = TPoints.new
3636
ellipse_mode RADIUS
37+
@renderer = AppRender.new(self)
3738
end
3839

3940
def draw
@@ -44,14 +45,7 @@ def draw
4445
center.display
4546
no_fill
4647
stroke 200
47-
triangle(
48-
points[0].screen_x,
49-
points[0].screen_y,
50-
points[1].screen_x,
51-
points[1].screen_y,
52-
points[2].screen_x,
53-
points[2].screen_y
54-
)
48+
render_triangle(points)
5549
ellipse(center.screen_x, center.screen_y, circle.radius, circle.radius)
5650
end
5751

@@ -63,14 +57,22 @@ def mouse_pressed
6357
@center = MathPoint.new(circle.center)
6458
end
6559

60+
def render_triangle(points)
61+
begin_shape
62+
points.each do |point|
63+
vertex(point.screen_x, point.screen_y)
64+
end
65+
end_shape(CLOSE)
66+
end
67+
6668
def key_pressed
6769
case key
6870
when ' '
6971
points.clear
7072
when 'c', 'C'
71-
points << MathPoint.new(Vec2D.new(0, 0))
72-
points << MathPoint.new(Vec2D.new(100, 100))
73-
points << MathPoint.new(Vec2D.new(300, 300))
73+
(0..400).step(200) do |i|
74+
points << MathPoint.new(Vec2D.new(i, i))
75+
end
7476
puts 'collinear points' if points.collinear?
7577
end
7678
end

0 commit comments

Comments
 (0)