ejolson
Posts: 11324
Joined: Tue Mar 18, 2014 11:47 am

Re: Is my fear of C++ justified?

Sat May 27, 2023 6:13 pm

ejolson wrote:
Sat May 27, 2023 4:22 pm
How hard would it be to use ICU instead of uftcpp?

https://icu.unicode.org/
It seems like ICU is really difficult.

I downloaded Nemanja's utfcpp library and got a little further

Code: Select all

$ g++ -Iutfcpp/source -o u8scan u8scan.cpp
u8scan.cpp: In function 'int main()':
u8scan.cpp:18:28: error: 'std::ranges' has not been declared
   18 |     auto utf8_count = std::ranges::count_if(dir_it, [&](const auto &entry) {
      |                            ^~~~~~
make: *** [Makefile:2: u8scan] Error 1
Is there some magic I need to get ranges from std?
Last edited by ejolson on Sat May 27, 2023 6:47 pm, edited 1 time in total.

ejolson
Posts: 11324
Joined: Tue Mar 18, 2014 11:47 am

Re: Is my fear of C++ justified?

Sat May 27, 2023 6:18 pm

ejolson wrote:
Sat May 27, 2023 6:13 pm
Is there some magic I need to get ranges from std?
Duck Duck Go told me to add -std=gnu++20 and I got a little further.

Code: Select all

$ g++ -std=gnu++20 -Iutfcpp/source -o u8scan u8scan.cpp
/usr/bin/ld: /tmp/ccF3GgiR.o: in function `main':
u8scan.cpp:(.text+0x318): undefined reference to `fmt::v9::vprint(fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)'
/usr/bin/ld: u8scan.cpp:(.text+0x36c): undefined reference to `fmt::v9::vprint(fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)'
/usr/bin/ld: u8scan.cpp:(.text+0x3cc): undefined reference to `fmt::v9::vprint(fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)'
/usr/bin/ld: u8scan.cpp:(.text+0x4c0): undefined reference to `fmt::v9::vprint(_IO_FILE*, fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)'
/usr/bin/ld: u8scan.cpp:(.text+0x528): undefined reference to `fmt::v9::vprint(_IO_FILE*, fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2: u8scan] Error 1
It looks like need to add a library somewhere.
Last edited by ejolson on Sat May 27, 2023 6:48 pm, edited 1 time in total.

ejolson
Posts: 11324
Joined: Tue Mar 18, 2014 11:47 am

Re: Is my fear of C++ justified?

Sat May 27, 2023 6:28 pm

ejolson wrote:
Sat May 27, 2023 6:18 pm
It looks like need to add a library somewhere.
I now have a working binary

Code: Select all

$ cd c++
$ g++ -std=gnu++20 -O3 -Iutfcpp/source -march=native -mtune=native \
-o u8scan u8scan.cpp -lfmt
$ cd ..
and without any help from ChatGPT. Astonishingly, the output

Code: Select all

$ su
# mount -o offset=272629760 2023-05-03-raspios-bullseye-armhf.img rootfs
# cd rootfs
# ../c++/u8scan 
Fido's UTF-8 popularity statistics:

    Total files: 112362
    UTF-8 files: 39217
    UTF-8/total: 34.902369128353%
# cd ..
# umount rootfs
is the same as the Rust version.
Last edited by ejolson on Sat May 27, 2023 6:48 pm, edited 2 times in total.

ejolson
Posts: 11324
Joined: Tue Mar 18, 2014 11:47 am

Re: Is my fear of C++ justified?

Sat May 27, 2023 6:39 pm

ejolson wrote:
Sat May 27, 2023 6:28 pm
Astonishingly, the output

Code: Select all

$ su
# mount -o offset=272629760 2023-05-03-raspios-bullseye-armhf.img rootfs
# cd rootfs
# ../c++/u8scan 
Fido's UTF-8 popularity statistics:

    Total files: 112362
    UTF-8 files: 39217
    UTF-8/total: 34.902369128353%
# cd ..
# umount rootfs
is the same as the Rust version.
The speed between the two seems similar.

The size of the executable files compares as

Code: Select all

$ ls -l c++/u8scan
-rwxr-xr-x 1 ejolson users 79688 May 27 18:26 c++/u8scan
$ ls -l target/release/u8scan
-rwxr-xr-x 2 ejolson users 561440 May 26 03:24 target/release/u8scan
$ strip c++/u8scan
$ strip target/release/u8scan
$ ls -l c++/u8scan
-rwxr-xr-x 1 ejolson users 67888 May 27 18:35 c++/u8scan
$ ls -l target/release/u8scan
-rwxr-xr-x 2 ejolson users 395480 May 27 18:35 target/release/u8scan
Both Rust and C++ produced ELF pie 64-bit ARM binaries on the Pi 4B.

tttapa
Posts: 138
Joined: Mon Apr 06, 2020 2:52 pm

Re: Is my fear of C++ justified?

Sat May 27, 2023 6:49 pm

ejolson wrote:
Sat May 27, 2023 4:22 pm
How hard would it be to use ICU instead of uftcpp?
A lot harder than it should be. The ICU C/C++ API is unnecessarily cumbersome to use (this is not just my opinion, they state so themselves in the documentation).
Specifically for this application: their iterator classes are not actually C++ iterators, so they do not compose with the standard library functions and other algorithms, requiring ugly glue code or manual iteration.
They also require the entire input string to be in memory, so you would either need to load it in a buffer yourself, or resort to something like mmap, complicating matters beyond what would be appropriate for a “simple example of a nontrivial program” aimed at beginners.
ejolson wrote:
Sat May 27, 2023 6:18 pm
It looks like need to add a library somewhere.
Indeed, here's a minimum viable Conan+CMake project:

CMakeLists.txt

Code: Select all

cmake_minimum_required(VERSION 3.20)
project(utf8)

find_package(utf8cpp REQUIRED)
find_package(fmt REQUIRED)

add_executable(main "main.cpp")
target_compile_options(main PRIVATE -Wall -Wextra) # Bare minimum
target_compile_features(main PRIVATE cxx_std_20)
target_link_libraries(main PRIVATE fmt::fmt utf8cpp)
conanfile.txt

Code: Select all

[requires]
utfcpp/3.2.3
fmt/10.0.0
[generators]
CMakeDeps
CMakeToolchain
main.cpp

Code: Select all

#include <algorithm>
#include <filesystem>
#include <fstream>
namespace fs = std::filesystem;
#include <fmt/core.h> // https://github.com/fmtlib/fmt
#include <utf8.h>     // https://github.com/nemtrif/utfcpp

bool contains_valid_utf8(const fs::path &path) {
    std::ifstream file{path, std::ios::binary};
    if (!file)
        return false;
    return utf8::is_valid(std::istreambuf_iterator(file), {});
}

int main() try {
    std::ptrdiff_t total = 0;
    fs::recursive_directory_iterator dir_it{fs::current_path()};
    auto utf8_count = std::ranges::count_if(dir_it, [&](const auto &entry) {
        if (!entry.is_regular_file())
            return false;
        ++total;
        return contains_valid_utf8(entry.path());
    });
    auto ratio = static_cast<double>(utf8_count) / static_cast<double>(total);
    fmt::print("Fido's UTF-8 popularity statistics:\n\n");
    fmt::print("\tTotal files: {}\n\tUTF-8 files: {}\n", total, utf8_count);
    fmt::print("\tUTF-8/total: {}%\n", 100.0 * ratio);
} catch (std::exception &e) {
    fmt::print(stderr, "Uncaught exception: {}\n", e.what());
    return 1;
} catch (...) {
    fmt::print(stderr, "Uncaught error\n");
    return 1;
}
Then you can just build it using the standard Conan and CMake workflows:

Code: Select all

conan install . --output-folder=build --build=missing 
cmake -S. -Bbuild --toolchain=build/conan_toolchain.cmake -G "Ninja Multi-Config"
cmake --build build --config Release -j
./build/Release/main

ejolson
Posts: 11324
Joined: Tue Mar 18, 2014 11:47 am

Re: Is my fear of C++ justified?

Sat May 27, 2023 6:59 pm

tttapa wrote:
Sat May 27, 2023 6:49 pm
ejolson wrote:
Sat May 27, 2023 4:22 pm
How hard would it be to use ICU instead of uftcpp?
A lot harder than it should be. The ICU C/C++ API is unnecessarily cumbersome to use (this is not just my opinion, they state so themselves in the documentation).
Specifically for this application: their iterator classes are not actually C++ iterators, so they do not compose with the standard library functions and other algorithms, requiring ugly glue code or manual iteration.
They also require the entire input string to be in memory, so you would either need to load it in a buffer yourself, or resort to something like mmap, complicating matters beyond what would be appropriate for a “simple example of a nontrivial program” aimed at beginners.
I considered using mmap with Rust but an easier way appeared. I guess that's the same with C++.

Since the fmt library was already provided by my distribution, only the UTF-8 decoder needed to be downloaded from a second source. Somehow, I prefer solutions that don't require an additional trust relationship with yet another person on Github.

I'm not sure Rust is much better as Cargo downloaded two crates to my machine.

If the C++ crowd called their package manager Peppa_Pig rather than Conan, then people might not be as fearful.
Last edited by ejolson on Sat May 27, 2023 7:09 pm, edited 1 time in total.

tttapa
Posts: 138
Joined: Mon Apr 06, 2020 2:52 pm

Re: Is my fear of C++ justified?

Sat May 27, 2023 7:09 pm

ejolson wrote:
Sat May 27, 2023 6:59 pm
Somehow, I prefer solutions that don't require an additional trust relationship with yet another person on Github.

I'm not sure Rust is much better as Cargo downloaded two crates to my machine.
Indeed, the utf8_read crate used in the Rust version is also from just a person on GitHub: https://github.com/atthecodeface/utf8-read-rs
It has only 3 stars and a single contributor on GitHub. While not a very meaningful metric for actual software quality, I would feel slightly more at ease with the C++ version, which has over 1200 stars and 17 contributors.

Conan makes getting C/C++ dependencies quite easy, although it doesn't nearly cover all packages.

dsyleixa123
Posts: 2176
Joined: Mon Jun 11, 2018 11:22 am

Re: Is my fear of C++ justified?

Sun May 28, 2023 7:27 am

is all that utf8 chatter still related to the topic "Is my fear of C++ justified" ?
IMO the mods should more strictly clean that up or split it right from the beginning... :?
hobby programming retiree, ♂, GER
"A programming language that needs left side whitespace or tabs for code block structuring and nesting is ridiculous."

ame
Posts: 7805
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Is my fear of C++ justified?

Sun May 28, 2023 8:19 am

Upon reflection, perhaps a fear of C++ is a genuine worry. I'd be hesitant to even mention it now, or Rust for that matter.
Oh no, not again.

Heater
Posts: 19599
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is my fear of C++ justified?

Sun May 28, 2023 8:23 am

Well this thread is about "fear of C++". One of the fears of using C++ is having to deal with unicode and utf-8. C++ does not have utf-8 type strings or characters. So a look at alternatives for that is topical.
Slava Ukrayini.

dsyleixa123
Posts: 2176
Joined: Mon Jun 11, 2018 11:22 am

Re: Is my fear of C++ justified?

Sun May 28, 2023 10:12 am

Heater wrote:
Sun May 28, 2023 8:23 am
Well this thread is about "fear of C++". One of the fears of using C++ is having to deal with unicode and utf-8. C++ does not have utf-8 type strings or characters. So a look at alternatives for that is topical.
:P

This is not fear, but at most specific concern, and then just the hint
"C++ does not have utf-8 type strings or characters, so if that's crucial, look for alternatives"
would have been sufficient - and that's it.
hobby programming retiree, ♂, GER
"A programming language that needs left side whitespace or tabs for code block structuring and nesting is ridiculous."

Heater
Posts: 19599
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is my fear of C++ justified?

Sun May 28, 2023 11:12 am

Yes but is it not helpful to also suggest an actual alternative or two having said "look for alternatives", we like to be helpful right?

Anyway, I brought it up as an answer to a specific question here.

Perhaps we should have a new thread "Is my fear of Rust justified?" ? I have a bunch of things to say about some misconceptions of Rust that have been stated here, but I was resisting doing so because it goes very off topic.
Slava Ukrayini.

User avatar
bensimmo
Posts: 6290
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is my fear of C++ justified?

Sun May 28, 2023 11:29 am

Stick it in the 'General programming...' as it is advice for beginners, probably.
It might be QI.

Heater
Posts: 19599
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is my fear of C++ justified?

Sun May 28, 2023 11:51 am

Sounds like a plane. I guess "Other Programming Languages" would be a good place.
Slava Ukrayini.

ejolson
Posts: 11324
Joined: Tue Mar 18, 2014 11:47 am

Re: Is my fear of C++ justified?

Sun May 28, 2023 2:47 pm

Heater wrote:
Sun May 28, 2023 11:12 am
Perhaps we should have a new thread "Is my fear of Rust justified?" ? I have a bunch of things to say about some misconceptions of Rust that have been stated here, but I was resisting doing so because it goes very off topic.
Thank you for the Rust help.

As you can probably tell, the Rust code I posted is the first time I did anything more rusty than compile someone else's Rust program. Given the person making the original post wrote
Abmvk wrote:
Tue May 23, 2023 9:59 pm
dbrion06 wrote:
Tue May 23, 2023 1:28 pm
w/r OP: if .s.he is afraid of C++, and wants to learn new programming languages, Fortran seems ideal (R and C syntax are very similar; pythonn syntax is different; I guess .s.he will find Fortran syntax exotic enough to have fun)
(he) I am diving into Rust now. I am having fun already, but I am at the very basic stuff
solving a small problem in both C++ and Rust seemed on topic as the only way I know to learn a new language is to actually use it.

Finding a motivating problem that is at the same approachable and interesting enough is a difficulty many people have with skills-based subjects that require doing to learn.

In the context of computer programming it used to be that modifying a game written in Basic or creating a new one was a compelling task for a young person. These days the quality of professionally produced games and the closed nature of gaming consoles make writing games less fun for a beginner.

One idea behind physical computing is that interacting with the physical world is intrinsically interesting and equally approachable with a Raspberry Pi. The fact that the Pi is actually running the same Linux operating system used to provide web services, for scientific computation, machine learning, training AI and everything else further makes physical computing with a Pi a way to build skills in all those other things.

I view the task of parsing UTF-8 files in this thread as a means to clarify any fear of C++ or Rust by actually writing some code. For me becoming more familiar by doing something with each language has actually removed a certain amount of fear in both cases. My hope is the OP was able to follow along and is also making progress.

The point is there is no need to have programming anxiety in any language because such fears can be dispelled by tackling a motivating problem and in ones own time solving it.

Abmvk
Posts: 189
Joined: Sat Feb 04, 2023 10:07 pm
Location: Netherlands

Re: Is my fear of C++ justified?

Sun May 28, 2023 8:38 pm

Heater wrote:
Sun May 21, 2023 4:58 pm
GUI's aside if you are up to learning a language more sophisticated than C but without the mess that is C++ I recommend looking at Rust:
I have to thank you Heater! I installed Rust and I am doing my first baby-steps. Until now, I love it.

Ofc, I didn’t do much more than the

“Who are you?”
“Hello {}, welcome to Rust”

but even so, I like it :D

User avatar
bensimmo
Posts: 6290
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is my fear of C++ justified?

Mon May 29, 2023 8:09 am

These days the quality of professionally produced games and the closed nature of gaming consoles make writing games less fun for a beginner.
I'm not sure on that, I'm currently providing three courses at college that all have 'and game design' in their title, from Level 1 to Level3 (UK)

They all enjoy it, but it isn't mass text now, it is a Scratch game, they all love that. Then a bit of C# knowledge and onto making games in Unity with C#, and can include graphics design, sound and animation if they so wish. Or just what they are given.

So now there is a wider audience than before and they still find it fun. Especially as these are the sort of people, mostly, that wouldn't have looked at BBC Basic or similar.

dsyleixa123
Posts: 2176
Joined: Mon Jun 11, 2018 11:22 am

Re: Is my fear of C++ justified?

Tue Jun 06, 2023 9:20 pm

@ Abmvk:
Just back to topic and to show again:
Don't be afraid of C++ with Qt creator GUI IDE !
Admittedly my layouts aren't optimal yet, and the Qt API is often rather bulky, but it's great for your own interactive graphic apps with GUI widgets for controls and dashboards!
Regarding your own programmings of Conway's Game of Life which you once reported on: I also extended and improved my GUI interface e.g. of my GoL Half-Adder - and honestly I wouldn't expect it to be any easier with Rust...! :geek:
https://github.com/dsyleixa/RaspberryPi ... 26B__.jpeg
https://github.com/dsyleixa/RaspberryPi ... /GoL_HA_v1


Give it a try! 8-)
hobby programming retiree, ♂, GER
"A programming language that needs left side whitespace or tabs for code block structuring and nesting is ridiculous."

jalih
Posts: 260
Joined: Mon Apr 15, 2019 3:54 pm

Re: Is my fear of C++ justified?

Wed Jun 07, 2023 9:27 am

dsyleixa123 wrote:
Tue Jun 06, 2023 9:20 pm
- and honestly I wouldn't expect it to be any easier with Rust...! :geek:
Maybe Heater could show us how using Slint compares to QT? I personally think it looks quite good!

Heater
Posts: 19599
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is my fear of C++ justified?

Wed Jun 07, 2023 4:39 pm

jalih wrote:
Wed Jun 07, 2023 9:27 am
dsyleixa123 wrote:
Tue Jun 06, 2023 9:20 pm
- and honestly I wouldn't expect it to be any easier with Rust...! :geek:
Maybe Heater could show us how using Slint compares to QT? I personally think it looks quite good!
Sadly not. It's a long time since I created any GUI code outside of browser. With Qt as it happens, which eased the pain quite a bit.

I could be tempted to give some Rust graphical stuff a try, use for fun, if there is a rainy weekend with nothing to do.
Slava Ukrayini.

dsyleixa123
Posts: 2176
Joined: Mon Jun 11, 2018 11:22 am

Re: Is my fear of C++ justified?

Wed Jun 07, 2023 4:50 pm

I could be tempted to give some Rust graphical stuff a try
my point was actually not just graphics but GUI control widgets like push-buttons, sliders, labels, check-boxes, radiobuttons, pop-up windows, drop-down menus, and text fields etc. to enter values a.s.o., to d+d, c+p, rearrange it on a GUI form, and let the GUI API generate the events code text then automatically
https://github.com/dsyleixa/RaspberryPi ... nshot.jpeg
Last edited by dsyleixa123 on Wed Jun 07, 2023 5:09 pm, edited 1 time in total.
hobby programming retiree, ♂, GER
"A programming language that needs left side whitespace or tabs for code block structuring and nesting is ridiculous."

jalih
Posts: 260
Joined: Mon Apr 15, 2019 3:54 pm

Re: Is my fear of C++ justified?

Wed Jun 07, 2023 5:09 pm

dsyleixa123 wrote:
Wed Jun 07, 2023 4:50 pm
I could be tempted to give some Rust graphical stuff a try
my point was actually not just graphics but GUI control widgets like buttons, sliders, labels, check-boxes, radiobuttons, pop-up windows, drop-down menus, and text fields etc. to enter values a.s.o.
https://github.com/dsyleixa/RaspberryPi ... nshot.jpeg
I am tempted to try writing a 8th GUI version of the "Game Of Life" using it's builtin Nuklear gui support. It could be fun to compare visual looks.

dsyleixa123
Posts: 2176
Joined: Mon Jun 11, 2018 11:22 am

Re: Is my fear of C++ justified?

Wed Jun 07, 2023 5:12 pm

and not just GoL display + runtime controls of course, but e.g. also GUI dashboards for GPIO control and displays.
Not to forget the GUI designer/creator IDE to d+d and arrange the widgets from a menu bar to the form, just using the mouse and mouse buttons, automatic widget code generation by the GUI IDE, and then build all and start it without makefiles just by clicking on a "run" symbol.
https://github.com/dsyleixa/RaspberryPi ... nshot.jpeg
hobby programming retiree, ♂, GER
"A programming language that needs left side whitespace or tabs for code block structuring and nesting is ridiculous."

Abmvk
Posts: 189
Joined: Sat Feb 04, 2023 10:07 pm
Location: Netherlands

Re: Is my fear of C++ justified?

Wed Jun 07, 2023 9:04 pm

dsyleixa123 wrote:
Tue Jun 06, 2023 9:20 pm
@ Abmvk:
Just back to topic and to show again:
Don't be afraid of C++ with Qt creator GUI IDE !
Admittedly my layouts aren't optimal yet, and the Qt API is often rather bulky, but it's great for your own interactive graphic apps with GUI widgets for controls and dashboards!
Regarding your own programmings of Conway's Game of Life which you once reported on: I also extended and improved my GUI interface e.g. of my GoL Half-Adder - and honestly I wouldn't expect it to be any easier with Rust...! :geek:
https://github.com/dsyleixa/RaspberryPi ... 26B__.jpeg
https://github.com/dsyleixa/RaspberryPi ... /GoL_HA_v1


Give it a try! 8-)
:mrgreen: you are very convincing

jalih
Posts: 260
Joined: Mon Apr 15, 2019 3:54 pm

Re: Is my fear of C++ justified?

Thu Jun 08, 2023 9:40 am

Okay, you got me into it... ;D

Currently it's only a graphical display of "Game Of Life" written in 8th programming language, but I will add some controls soon. It took only a few minutes to get something visible on screen. I chose to store cells into map instead of a 2d array. That way only cells that are alive need to be stored. I use grid layout to handle all positioning for drawing.

Code: Select all


needs nk/gui

24 font:system font:new "font1" font:atlas! drop

64 constant ROWS
64 constant COLS

var population

: create-cell  \ m a  -- m
  dup "%d:%d" s:strfmt m:_! ; 

: neighbors?  \ a -- m
  >r m:new
  [
    [-1,-1],[0,-1],[1,-1],
    [-1,0],[1,0],
    [-1,1],[0,1],[1,1]
  ] ( r@ ' n:+ a:2map ) a:map rdrop 
  ' create-cell a:each! drop ;

: count-alive-neighbors  \ m a -- m n
  neighbors? m:keys nip m:@ ( null? not nip ) a:filter a:len nip ;

: evolve \ m -- m
  m:new m:new rot m:vals
  (  
    dup>r count-alive-neighbors dup 2 n:= swap 3 n:= or if
      over r@ create-cell drop  
    then
    
    r> neighbors?
    (
      4 pick rot m:exists? !if
        swap dup>r create-cell drop
        r@ count-alive-neighbors 3 n:= if  
          over r> create-cell drop
        else
          rdrop
        then
      else
        2drop
      then
    ) m:each drop
  ) a:each! 2drop nip ;

: populate-random  \ m -- m
  ( >r
    ( rand-pcg 100 n:mod 20 n:> !if
        r@ 2 a:close create-cell  
      else
        drop
      then 
    ) 0 COLS n:1- loop rdrop
  ) 0 ROWS n:1- loop ;

: grid-widget  \ m --
  nk:widget drop
  { rows: @ROWS, cols: @COLS } nk:layout-grid-begin 
    ( >r
      (  
        tuck r@ "%d:%d" s:strfmt m:exists? if 
          swap 1 r@ 1 nk:grid -1 nk:rect-shrink 0 "black" nk:fill-rect
        else
          swap 1 r@ 1 nk:grid 0 2 "black" nk:stroke-rect
        then
      ) 0 ROWS n:1- loop rdrop
    ) 0 COLS n:1- loop
  nk:layout-grid-end drop ;

: new-win
  {
    name: "main",
    wide: 674,
    high: 608,
    resizable: false,
    bg: "white",
    title: "Game Of Life"
  } nk:win ;

: main-render
  {
    bg: "white",
    padding: [8,8],
    flags: [ @nk:WINDOW_NO_SCROLLBAR ]
  }
 
  nk:begin
    null { rows: 1, cols: 1, margin: 8 } nk:layout-grid-begin
      0 1 0 1 nk:grid nk:rect>local nk:grid-push population @ grid-widget 
    nk:layout-grid-end
  nk:end 
  population @ evolve population ! ;

: init
  m:new populate-random population !
  2048k 2048k nk:max-vertex-element ;

: app:main
  init
  new-win ' main-render 100 nk:render-loop-timed ;
  
Attachments
life.png
life.png (3.99 KiB) Viewed 911 times

Return to “C/C++”