Last change
on this file since 1226 was
896,
checked in by Maciej Komosinski, 5 years ago
|
Replaced #defined macros for popular random-related operations with functions
|
-
Property svn:eol-style set to
native
|
File size:
1009 bytes
|
Rev | Line | |
---|
[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
[896] | 2 | // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. |
---|
[286] | 3 | // See LICENSE.txt for details. |
---|
[137] | 4 | |
---|
[135] | 5 | #include "nn_layout.h" |
---|
| 6 | #include "common/nonstd_math.h" |
---|
| 7 | #include <stdlib.h> |
---|
| 8 | |
---|
| 9 | static void randomlayout(NNLayoutState*); |
---|
| 10 | static void arraylayout(NNLayoutState*); |
---|
| 11 | |
---|
| 12 | extern void smartlayout(NNLayoutState*); |
---|
| 13 | |
---|
| 14 | struct NNLayoutFunction nn_layout_functions[] = |
---|
| 15 | { |
---|
| 16 | { "Random", randomlayout, }, |
---|
| 17 | { "Dumb array", arraylayout, }, |
---|
| 18 | { "Smart", smartlayout, }, |
---|
| 19 | { 0, } |
---|
| 20 | }; |
---|
| 21 | |
---|
| 22 | static void randomlayout(NNLayoutState*nn) |
---|
| 23 | { |
---|
| 24 | int i; |
---|
| 25 | int N = nn->GetElements(); |
---|
| 26 | for (i = 0; i < N; i++) |
---|
| 27 | { |
---|
[896] | 28 | nn->SetXYWH(i, rndUint(300), rndUint(300), 50, 50); |
---|
[135] | 29 | } |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | static void arraylayout(NNLayoutState*nn) |
---|
| 33 | { |
---|
| 34 | int e = 0, i, j; |
---|
| 35 | int N = nn->GetElements(); |
---|
| 36 | int a = ((int)(sqrt(double(N)) - 0.0001)) + 1; |
---|
| 37 | for (j = 0; j < a; j++) |
---|
| 38 | for (i = 0; i < a; i++) |
---|
| 39 | { |
---|
[789] | 40 | if (e >= N) return; |
---|
| 41 | nn->SetXYWH(e, 70 * i + ((i + j) & 3) * 4, 70 * j + ((2 + i + j) & 3) * 4, 50, 50); |
---|
| 42 | e++; |
---|
[135] | 43 | } |
---|
| 44 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.