Class: Circles

Inherits:
Propane::App
  • Object
show all
Defined in:
lib/circles.rb

Instance Method Summary collapse

Instance Method Details

#drawObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/circles.rb', line 20

def draw
  fill(0, 0, 0)
  no_stroke
  reset if (frame_count % 8_000).zero?
  @points.each do |point|
    # change direction sometimes
    point.direction Vec2D.random if rand > 0.96
    point.update
  end

  # set the style of the circle
  @dc = map1d(millis, 0..150_000, 0..360) # slowly changes hue
  stroke((@c + @dc) % 360, 50, 100, 5)
  no_fill

  ## verifies if there is a circle and draw it
  draw_circle @points unless @points.collinear?
end

#draw_circle(pts) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/circles.rb', line 39

def draw_circle(pts)
  circumcircle = Circumcircle.new(@points.positions)
  circumcircle.calculate
  center_point = circumcircle.center
  radius = circumcircle.radius
  ellipse(center_point.x, center_point.y, radius, radius)
end

#resetObject



47
48
49
50
51
52
# File 'lib/circles.rb', line 47

def reset
  @c = rand(360)
  @points = TrianglePoints.new
  3.times { @points << TPoint.new(Vec2D.new(rand(5..width - 5), rand(5..height - 5))) }
  background 0
end

#settingsObject



9
10
11
# File 'lib/circles.rb', line 9

def settings
  size(800, 600)
end

#setupObject



13
14
15
16
17
18
# File 'lib/circles.rb', line 13

def setup
  sketch_title 'Math Demo'
  color_mode(HSB, 360, 100, 100, 100)
  reset
  ellipse_mode(RADIUS)
end