Author Topic: Having Fun With Water Waves Again  (Read 4016 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Having Fun With Water Waves Again
« on: November 29, 2020, 01:42:57 am »
Last June I made some cool looking water waves if any of you remember. I will put the link it below. So tonight I decided to try a simpler approach on them which makes smaller waves and more of them. Instead of plotting each point, this time I just used one single CIRCLE command for the entire program. I then added the idea B+ gave me last time to shift them over to the side to make an angle and it did the same thing here. :) Check it out!

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. c = .01 'c is shape of half-circle.
  3. d = 1 'd is direction of up and down.
  4. xx = 400 'Added amount to fill the screen below.
  5.     IF d = 1 THEN c = c + .01
  6.     IF c > .9 THEN d = 2
  7.     IF d = 2 THEN c = c - .01
  8.     IF c < .01 THEN d = 1
  9.     xx = xx + 2 'Movement from left to right.
  10.     IF xx > 2000 THEN xx = 400
  11.     FOR y = 300 TO 600 STEP 1 'Vertical Loop.
  12.         xxx = xxx + 1 'Shift making it at an angle.
  13.         FOR x = xx + 800 TO -xx STEP -50 'Horizontal Loop.
  14.             CIRCLE (x + xxx, y), 25, _RGB32(0, b, 155 + b), _PI, 2 * _PI, c 'All of the waves you see.
  15.             b = b + 1 'Blue color.
  16.             IF b > 100 THEN b = 0
  17.         NEXT x
  18.     NEXT y
  19.     xxx = 0
  20.     _DISPLAY
  21.     CLS
  22.     PAINT (2, 2), _RGB32(116, 205, 255) 'Sky
  23.     _LIMIT 30
  24.  

Here is last June's waves: https://www.qb64.org/forum/index.php?topic=2682.0


Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #1 on: November 29, 2020, 05:21:05 pm »
Hi Ken,

I think that replacing the "paint()" command with LINE (0, 0)-(800, 325), _RGB32(116, 205, 255), BF may be a little more efficient...

Principle: (correct me if I am wrong) A floodfill needs to process surrounding pixels from the 'start point' and either continues check and plotting, as it goes, until it reaches a predetermined colour or the edge of the screen. Doing this 30 times per second could cause a lot of memory usage and on some older machines it may impact performance... There is probably a lot more involved but this is 'my' understanding... lol
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #2 on: November 29, 2020, 05:39:12 pm »
Thanks Johnno, I keep forgetting about that. It did reduce my CPU usage from around 6% to around 4%. Also, I have it cover the entire screen to fill-in any dark areas of the water.
Edit: I also just deleted CLS since that is not needed anymore either. :)

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. c = .01 'c is shape of half-circle.
  3. d = 1 'd is direction of up and down.
  4. xx = 400 'Added amount to fill the screen below.
  5.     IF d = 1 THEN c = c + .01
  6.     IF c > .9 THEN d = 2
  7.     IF d = 2 THEN c = c - .01
  8.     IF c < .01 THEN d = 1
  9.     xx = xx + 2 'Movement from left to right.
  10.     IF xx > 2000 THEN xx = 400
  11.     FOR y = 300 TO 600 STEP 1 'Vertical Loop.
  12.         xxx = xxx + 1 'Shift making it at an angle.
  13.         FOR x = xx + 800 TO -xx STEP -50 'Horizontal Loop.
  14.             CIRCLE (x + xxx, y), 25, _RGB32(0, b, 155 + b), _PI, 2 * _PI, c 'All of the waves you see.
  15.             b = b + 1 'Blue color.
  16.             IF b > 100 THEN b = 0
  17.         NEXT x
  18.     NEXT y
  19.     xxx = 0
  20.     _DISPLAY
  21.     LINE (0, 0)-(800, 600), _RGB32(128, 233, 255), BF
  22.     _LIMIT 30
  23.  
« Last Edit: November 29, 2020, 05:43:55 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #3 on: November 29, 2020, 06:18:44 pm »
I just whipped up a little program to test the timing between Paint and Line()-(),,bf

Every time BF was instant. The majority of the time, paint varied between 0.05 and 0.0 seconds. So, visually anyway, either method is as good as the other.... I don't know how to test for memory usage...

So, on more recent machines - visually, my earlier explanation may not be applicable...
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #4 on: November 29, 2020, 08:47:08 pm »
To see CPU usage and memory usage, while the program is running, press Ctrl Alt Del and look at the name of your program on the list of programs running and what they are using. This is for Windows only. Then just close it when you are done.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #5 on: December 01, 2020, 01:38:53 am »
OK try again, a little drama to the calm scene :)
* Making waves.zip (Filesize: 2.86 KB, Downloads: 164)
« Last Edit: December 01, 2020, 01:49:26 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #6 on: December 02, 2020, 01:20:30 pm »
LOL B+! I was wondering if someone would add an animal, etc. to this. lol Good one.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Having Fun With Water Waves Again
« Reply #7 on: December 02, 2020, 01:27:29 pm »
Ha! I was wondering when / if you would notice, a fun little break from puzzle making and analyzing. :)