Skip to content

Commit 47af2c0

Browse files
committed
Use Process.clock_time instead of Time.now
1 parent b4ecaae commit 47af2c0

File tree

8 files changed

+17
-18
lines changed

8 files changed

+17
-18
lines changed

contributed/tree.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# frozen_string_literal: true
33
require 'propane'
44

5+
TIME_FORMAT = 'Time after this iteration: %.2f'
6+
57
class Tree < Propane::App
68
# http://processing.org/learning/topics/tree.html
79
# by Joe Holt
@@ -16,12 +18,12 @@ def setup
1618
frame_rate 30
1719
@x = 0.0
1820
@dx = width / 100
19-
@start_time = Time.now
21+
@start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
2022
@frame_time = nil
2123
end
2224

2325
def draw
24-
t = Time.now
26+
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
2527
if @frame_time
2628
fps = 1.0 / (t - @frame_time)
2729
# printf "%0.1f fps\n", fps
@@ -46,7 +48,7 @@ def draw
4648

4749
@x += @dx
4850
if @x < 0
49-
puts "Time after this iteration: " + (Time.now - @start_time).to_s
51+
puts format(TIME_FORMAT, t - @start_time)
5052
end
5153
if @x > width || @x < 0
5254
@dx = - @dx

external_library/java/pixel_flow/sampling_poisson2d.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def newInstance(x, y, r, rcollision)
3737
rmax = 25
3838
roff = 0.5
3939
new_points = 100
40-
start = Time.now
40+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
4141
pds.setRandomSeed(rand(0..10_0000))
4242
pds.generatePoissonSampling2D(bounds, rmin, rmax, roff, new_points)
4343
@samples = pds.samples
44-
time = Time.now - start
44+
time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
4545
puts("poisson samples 2D generated")
4646
puts(" time: #{(time * 1000).floor}ms")
4747
puts(" count: #{samples.size}")

external_library/java/pixel_flow/sampling_poisson3d.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ def newInstance(x, y, z, r, rcollision)
5757
rmax = 50
5858
roff = 1
5959
new_points = 50
60-
start = Time.now
60+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
6161
pds.generatePoissonSampling(bounds, rmin, rmax, roff, new_points)
6262
@shp_samples_spheres = create_shape(GROUP)
6363
@shp_samples_points = create_shape(GROUP)
6464
@samples = pds.samples
6565
samples.each do |sample|
6666
add_shape(sample)
6767
end
68-
time = Time.now - start
69-
start = Time.now
68+
time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
69+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
7070
puts("poisson samples 3D generated")
7171
puts(" time: #{(time * 1_000).floor}ms")
7272
puts(" count: #{pds.samples.size}")
7373

74-
time = Time.now - start
74+
time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
7575
puts("PShapes created")
7676
puts(" time: #{(time * 1_000).floor}ms")
7777
puts(" count: #{samples.size}")

processing_app/library/vecmath/vec2d/circle_collision.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def setup
4242
end
4343

4444
def draw
45-
t = Time.now
45+
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
4646
fps = 1.0 / (t - @frame_time) if @frame_time
4747
@frame_time = t
4848
@frame_count += 1

processing_app/topics/filters/video_filtering/barrel_blur_chroma.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class BarrelBlurChroma < Propane::App
77
include_package 'processing.video'
88

99
attr_reader :movie, :my_shader
10-
1110
# How much barrel effect do we want?
1211
# Values between 0.5 and 3.0 work best, but feel free to try other values
1312
BARREL = 2.2

processing_app/topics/filters/video_filtering/droste.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ def settings
1616

1717
def setup
1818
sketch_title 'Droste'
19-
@origin = Time.now
19+
@origin = Process.clock_gettime(Process::CLOCK_MONOTONIC)
2020
@my_filter = load_shader(data_path('droste.glsl'))
2121
my_filter.set('sketchSize', width.to_f, height.to_f)
2222
start_capture(width, height)
2323
end
2424

2525
def time
26-
(Time.now - origin) * 0.5
26+
(Process.clock_gettime(Process::CLOCK_MONOTONIC) - origin) * 0.5
2727
end
2828

2929
def draw
3030
# Draw the image on the scene
3131
image(cam, 0, 0)
32-
3332
my_filter.set('globalTime', time)
3433
# Applies the shader to everything that has already been drawn
3534
return if mouse_pressed?

processing_app/topics/ruby_hook/subclass.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def update
3939
def post_initialize(_args)
4040
nil
4141
end
42-
4342
end
4443

4544
class SpinArm < Spin # inherit from (or "extend") class Spin
@@ -76,5 +75,4 @@ def display
7675
end
7776
end
7877

79-
8078
SubClassSketch.new

processing_app/topics/shaders/infinite_tiling.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env jruby
12
require 'propane'
23
#-------------------------------------------------------------
34
# Display endless moving background using a tile texture.
@@ -15,7 +16,7 @@ def setup
1516
texture_wrap(REPEAT)
1617
@tile_texture = load_image(data_path('penrose.jpg'))
1718
load_tile_shader
18-
@time0 = Time.now
19+
@time0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1920
end
2021

2122
def load_tile_shader
@@ -25,7 +26,7 @@ def load_tile_shader
2526
end
2627

2728
def draw
28-
mil = (Time.now - time0).to_f
29+
mil = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time0
2930
tile_shader.set('time', mil)
3031
shader(tile_shader)
3132
rect(0, 0, width, height)

0 commit comments

Comments
 (0)