Skip to content

Commit 40b8ffc

Browse files
committed
Obj needed for signature
1 parent 2af6f6e commit 40b8ffc

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
load_library :PixelFlow
2+
3+
java_import 'com.thomasdiewald.pixelflow.java.DwPixelFlow'
4+
java_import 'com.thomasdiewald.pixelflow.java.fluid.DwFluid2D'
5+
#
6+
# PixelFlow | Copyright (C) 2016 Thomas Diewald - http://thomasdiewald.com
7+
# Modified for JrubyArt by Martin Prout
8+
# A Processing/Java library for high performance GPU-Computing (GLSL).
9+
# MIT License: https://opensource.org/licenses/MIT
10+
#
11+
12+
# Simple example that shows how to add Data (density, velocity) to the fluid.
13+
#
14+
# controls:
15+
#
16+
# LMB: add Density + Velocity
17+
# MMB: add Velocity
18+
# RMB: add Velocity
19+
20+
VIEWPORT_W = 1280
21+
VIEWPORT_H = 720
22+
VIEWPORT_X = 230
23+
VIEWPORT_Y = 0
24+
BACKGROUND_COLOR = 255
25+
26+
attr_reader :fluidgrid_scale, :fluid, :pg_fluid, :pg_obstacles, :context
27+
28+
def settings
29+
size(VIEWPORT_W, VIEWPORT_H, P2D)
30+
smooth(2)
31+
end
32+
33+
def setup
34+
surface.setLocation(VIEWPORT_X, VIEWPORT_Y)
35+
# main library context
36+
@context = DwPixelFlow.new(self)
37+
context.print
38+
context.printGL
39+
# fluid simulation
40+
@fluid = DwFluid2D.new(context, VIEWPORT_W, VIEWPORT_H, fluidgrid_scale)
41+
cb_fluid_data = lambda do |obj| # obj required for signature (but unused)
42+
if mouse_pressed?
43+
vscale = 15
44+
px = mouse_x
45+
py = height - mouse_y
46+
vx = (mouse_x - pmouse_x) * +vscale
47+
vy = (mouse_y - pmouse_y) * -vscale
48+
radius = 20
49+
intensity = 1.0
50+
temperature = 5.0
51+
fluid.add_velocity(px, py, radius, vx, vy)
52+
if mouse_button == LEFT
53+
fluid.add_temperature(px, py, radius, temperature)
54+
radius = 20
55+
fluid.add_density(px, py, radius, 0, 0, 0, intensity)
56+
radius = 16
57+
fluid.add_density(px, py, radius, 0, 0.4, 1, intensity)
58+
end
59+
end
60+
end
61+
@fluidgrid_scale = 1
62+
# set some simulation parameters
63+
fluid.param.dissipation_density = 0.98
64+
fluid.param.dissipation_velocity = 0.92
65+
fluid.param.dissipation_temperature = 0.69
66+
fluid.param.vorticity = 0.10
67+
# interface for adding data to the fluid simulation
68+
fluid.addCallback_FluiData(cb_fluid_data)
69+
# pgraphics for fluid
70+
@pg_fluid = create_graphics(VIEWPORT_W, VIEWPORT_H, P2D)
71+
pg_fluid.smooth(4)
72+
# pgraphics for obstacles
73+
@pg_obstacles = create_graphics(VIEWPORT_W, VIEWPORT_H, P2D)
74+
pg_obstacles.no_smooth
75+
pg_obstacles.begin_draw
76+
pg_obstacles.clear
77+
# rand obstacles
78+
pg_obstacles.rect_mode(CENTER)
79+
pg_obstacles.no_stroke
80+
pg_obstacles.fill(64)
81+
srand(0)
82+
80.times do
83+
px = rand(width)
84+
py = rand(height)
85+
sx = rand(15..60)
86+
sy = rand(15..60)
87+
pg_obstacles.rect(px, py, sx, sy)
88+
end
89+
# border-obstacle
90+
pg_obstacles.rect_mode(CORNER)
91+
pg_obstacles.stroke_weight(20)
92+
pg_obstacles.stroke(64)
93+
pg_obstacles.no_fill
94+
pg_obstacles.rect(0, 0, pg_obstacles.width, pg_obstacles.height)
95+
pg_obstacles.end_draw
96+
# add to the fluid-solver
97+
fluid.add_obstacles(pg_obstacles)
98+
frame_rate(60)
99+
end
100+
101+
def draw
102+
# update simulation
103+
fluid.update
104+
# clear render target
105+
pg_fluid.begin_draw
106+
pg_fluid.background(BACKGROUND_COLOR)
107+
pg_fluid.end_draw
108+
# render fluid stuff
109+
fluid.render_fluid_textures(pg_fluid, 0)
110+
# display
111+
image(pg_fluid, 0, 0)
112+
image(pg_obstacles, 0, 0)
113+
# info
114+
format_string = 'Fluid Minimal [size %d/%d] [frame %d] [fps: (%6.2f)]'
115+
surface.set_title(format(format_string, fluid.fluid_w, fluid.fluid_h, fluid.simulation_step, frame_rate))
116+
end

0 commit comments

Comments
 (0)