source: cpp/frams/canvas/nn_simple_layout.cpp @ 213

Last change on this file since 213 was 197, checked in by Maciej Komosinski, 11 years ago

GDK used by developers since 1999, distributed on the web since 2002

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
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, (int)rnd0N(300), (int)rnd0N(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.