# source:cpp/frams/canvas/nn_simple_layout.cpp

Last change on this file was 896, checked in by Maciej Komosinski, 4 years ago

Replaced #defined macros for popular random-related operations with functions

• Property svn:eol-style set to `native`
File size: 1009 bytes
Line
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
4
5#include "nn_layout.h"
6#include "common/nonstd_math.h"
7#include <stdlib.h>
8
9static void randomlayout(NNLayoutState*);
10static void arraylayout(NNLayoutState*);
11
12extern void smartlayout(NNLayoutState*);
13
14struct NNLayoutFunction nn_layout_functions[] =
15{
16        { "Random", randomlayout, },
17        { "Dumb array", arraylayout, },
18        { "Smart", smartlayout, },
19        { 0, }
20};
21
22static void randomlayout(NNLayoutState*nn)
23{
24        int i;
25        int N = nn->GetElements();
26        for (i = 0; i < N; i++)
27        {
28                nn->SetXYWH(i, rndUint(300), rndUint(300), 50, 50);
29        }
30}
31
32static 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                {
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++;
43                }
44}
Note: See TracBrowser for help on using the repository browser.