Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. An interesting look at Flood Fill Algorithm implemented in C++ vs QML Javascript
Forum Update on Monday, May 27th 2025

An interesting look at Flood Fill Algorithm implemented in C++ vs QML Javascript

Scheduled Pinned Locked Moved Unsolved Showcase
2 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TenKOhms
    wrote on 10 Sept 2017, 15:20 last edited by
    #1

    I want to preface by saying I’m very new to Javascript.
    Here is the video:
    https://youtu.be/M2_aYzdMAcw

    This was written using the Qt framework, which I’m sure adds even more overhead to the javascript code, so take it with a grain of salt.

    Part of a game I’m working on is similar to a paint application. Originally, since the front end is written in QML, I wrote the flood fill algorithm for the paint bucket in javascript, which worked perfectly fine for filling in enclosed items, or if the window was small. If the window was maximized and the paint bucket was requested on the background; however, it seemed the application would hang for a few seconds and then finally finish. I figured that’s just how it was going to be since there are a lot of pixels to iterate through, but during game testing with my friends it was a feature that was discussed a lot. I decided to rewrite the same exact paint bucket in c++. Even with the added code to save the image and then read the image, the algorithm implemented in c++ was much, much quicker.

    Javascript Results output:

    qml: 11:06:39 AM EDT <- paint bucket started on enclosed shape

    qml: 11:06:39 AM EDT <- paint bucket finished on enclosed shape

    qml: 11:06:40 AM EDT <- paint bucket started on background

    qml: 11:06:45 AM EDT <- paint bucket finished on background

    C++ Results output:

    qml: 11:06:58 AM EDT <- paint bucket started on enclosed shape

    qml: 11:06:58 AM EDT <- paint bucket finished on enclosed shape

    qml: 11:06:59 AM EDT <- paint bucket started on background

    qml: 11:07:00 AM EDT <- paint bucket finished on background

    Source can be found here:
    https://gitlab.com/tenkohms/CPPvsJavascript_PaintBucket

    Quick plug, if you want to check out my slow moving kickstarter of the game I made that uses this paint code:

    kickstarter.com/projects/370338426/scribble-0/

    ? 1 Reply Last reply 10 Sept 2017, 15:34
    0
    • T TenKOhms
      10 Sept 2017, 15:20

      I want to preface by saying I’m very new to Javascript.
      Here is the video:
      https://youtu.be/M2_aYzdMAcw

      This was written using the Qt framework, which I’m sure adds even more overhead to the javascript code, so take it with a grain of salt.

      Part of a game I’m working on is similar to a paint application. Originally, since the front end is written in QML, I wrote the flood fill algorithm for the paint bucket in javascript, which worked perfectly fine for filling in enclosed items, or if the window was small. If the window was maximized and the paint bucket was requested on the background; however, it seemed the application would hang for a few seconds and then finally finish. I figured that’s just how it was going to be since there are a lot of pixels to iterate through, but during game testing with my friends it was a feature that was discussed a lot. I decided to rewrite the same exact paint bucket in c++. Even with the added code to save the image and then read the image, the algorithm implemented in c++ was much, much quicker.

      Javascript Results output:

      qml: 11:06:39 AM EDT <- paint bucket started on enclosed shape

      qml: 11:06:39 AM EDT <- paint bucket finished on enclosed shape

      qml: 11:06:40 AM EDT <- paint bucket started on background

      qml: 11:06:45 AM EDT <- paint bucket finished on background

      C++ Results output:

      qml: 11:06:58 AM EDT <- paint bucket started on enclosed shape

      qml: 11:06:58 AM EDT <- paint bucket finished on enclosed shape

      qml: 11:06:59 AM EDT <- paint bucket started on background

      qml: 11:07:00 AM EDT <- paint bucket finished on background

      Source can be found here:
      https://gitlab.com/tenkohms/CPPvsJavascript_PaintBucket

      Quick plug, if you want to check out my slow moving kickstarter of the game I made that uses this paint code:

      kickstarter.com/projects/370338426/scribble-0/

      ? Offline
      ? Offline
      A Former User
      wrote on 10 Sept 2017, 15:34 last edited by
      #2

      @TenKOhms said in An interesting look at Flood Fill Algorithm implemented in C++ vs QML Javascript:

      ven with the added code to save the image and then read the image, the algorithm implemented in c++ was much, much quicker

      Yep, never use JavaScript for anything but very simple GUI logic.

      1 Reply Last reply
      0

      1/2

      10 Sept 2017, 15:20

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved