Class: Demo

Inherits:
Processing::App
  • Object
show all
Defined in:
lib/demo.rb,
lib/demo-rotated.rb

Instance Method Summary collapse

Instance Method Details

#drawObject



53
54
# File 'lib/demo.rb', line 53

def draw
end

#setupObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/demo.rb', line 11

def setup
	render_mode(P2D)
	no_loop
	background(0,0,0)
	color_mode(RGB, 1.0)
	stroke(1,1,0,1)
	@highlight_block = lambda do |original, mapped, s|
				s.in_basis do
					rect_mode(CENTER)
					stroke(1,0,0)
					fill(1,0,0)
					rect(original[:x], original[:y], 3, 3)
				end
			   end

	points = []
	200.times {|n|points << {:x => n, :y => random(300)}}

#		Long-winded way of setting up a coordinate system explicitly

#		@x_unit_vector = {:x => 1.0, :y => 0.0}
#		@y_unit_vector = {:x => 0.0, :y => 1.0}
#		x_range = ContinuousRange.new({:minimum => 0, :maximum => 200})
#		y_range = ContinuousRange.new({:minimum => 0, :maximum => 300})
#		@basis = CoordinateSystem.new(Axis.new(@x_unit_vector,x_range), Axis.new(@y_unit_vector,y_range), self, [[1,0],[0,1]])

#		Accomplish the above in a single line below...
	@basis = CoordinateSystem.standard({:minimum => 0, :maximum => 200}, {:minimum => 0, :maximum => 300}, self, {:x => "X-Axis", :y => "Y-Axis"})

	screen_transform = Transform.new({:x => 2, :y => -2}, {:x => 300, :y => 900})
	@screen = Screen.new(screen_transform, self, @basis)
	@screen.draw_axes(10,10, :gridlines => false)
	stroke(1,1,0,1)
	fill(1,1,0)
	rect_mode(CENTER)
	@screen.plot(points, :track => true) do |original, mapped, s|
		s.in_basis do
			rect(original[:x], original[:y], 3, 3)
		end
	end
end