MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / main

Function main

examples/graphics/field.cpp:20–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18const static float STEP = 0.18f;
19
20int main(int, char**) {
21 try {
22 af::info();
23 af::Window myWindow(1024, 1024, "2D Vector Field example: ArrayFire");
24
25 myWindow.grid(2, 2);
26
27 array dataRange = seq(MINIMUM, MAXIMUM, STEP);
28
29 array x = tile(dataRange, 1, dataRange.dims(0));
30 array y = tile(dataRange.T(), dataRange.dims(0), 1);
31 x.eval();
32 y.eval();
33
34 float scale = 2.0f;
35 do {
36 array points = join(1, flat(x), flat(y));
37
38 array saddle = join(1, flat(x), -1.0f * flat(y));
39
40 array bvals = sin(scale * (x * x + y * y));
41 array hbowl = join(1, constant(1., x.elements()), flat(bvals));
42 hbowl.eval();
43
44 // 2D points
45 myWindow(0, 0).vectorField(points, saddle, "Saddle point");
46 myWindow(0, 1).vectorField(
47 points, hbowl, "hilly bowl (in a loop with varying amplitude)");
48
49 // 2D coordinates
50 myWindow(1, 0).vectorField(2.0 * flat(x), flat(y), flat(x),
51 -flat(y), "Saddle point");
52 myWindow(1, 1).vectorField(
53 2.0 * flat(x), flat(y), constant(1., x.elements()), flat(bvals),
54 "hilly bowl (in a loop with varying amplitude)");
55
56 myWindow.show();
57
58 scale -= 0.0010f;
59 if (scale < -0.01f) { scale = 2.0f; }
60 } while (!myWindow.close());
61
62 } catch (af::exception& e) {
63 fprintf(stderr, "%s\n", e.what());
64 throw;
65 }
66 return 0;
67}

Callers

nothing calls this directly

Calls 15

infoFunction · 0.85
seqClass · 0.85
sinFunction · 0.85
constantFunction · 0.85
gridMethod · 0.80
TMethod · 0.80
vectorFieldMethod · 0.80
showMethod · 0.80
closeMethod · 0.80
tileFunction · 0.50
joinFunction · 0.50
flatFunction · 0.50

Tested by

no test coverage detected