Author Topic: Dav's Doodle Dandy - animated image drawing.  (Read 5978 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #15 on: June 08, 2021, 10:22:08 pm »
@bplus:  Thanks! Really helpful code.  I took it apart, and I think it can fit in very easily into a drawing program.  The only thing I added was the IF length > size% THEN part before drawing the length, because I'm using large radius sizes for brushes and no need to draw in the length unless gaps are larger than the size% (it slowed it down on really large circle radius sizes). 

I really appreciate that code!

- Dav

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. CLS , _RGB(255, 255, 255)
  4.  
  5. clr& = _RGB(200, 100, 50)
  6. size% = 50
  7.  
  8.  
  9.     mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  10.  
  11.     IF mb THEN
  12.  
  13.         IF lastmx AND lastmy THEN
  14.             stepx = lastmx - mx
  15.             stepy = lastmy - my
  16.             length = INT((stepx ^ 2 + stepy ^ 2) ^ .5)
  17.  
  18.             IF length THEN
  19.                 dx = stepx / length
  20.                 dy = stepy / length
  21.  
  22.                 IF length > size% THEN
  23.  
  24.                     FOR i = 0 TO length
  25.                         FOR d = 1 TO size% STEP .2
  26.                             CIRCLE (mx + dx * i, my + dy * i), d, clr&
  27.                         NEXT
  28.                     NEXT
  29.  
  30.                 END IF
  31.  
  32.             ELSE
  33.                 FOR d = 1 TO size% STEP .2
  34.                     CIRCLE (mx, my), d, clr&
  35.                 NEXT
  36.             END IF
  37.  
  38.         END IF
  39.         lastmx = mx: lastmy = my
  40.     ELSE
  41.         lastmx = 0: lastmy = 0
  42.     END IF
  43.  
  44.  
  45.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #16 on: June 08, 2021, 11:00:21 pm »
Yeah I thought it easy to implement and easy for changing radius = brush size.

@Dav might also be handy to change radius with mouse wheel.
« Last Edit: June 08, 2021, 11:10:51 pm by bplus »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #17 on: June 09, 2021, 09:00:56 am »
@Dav might also be handy to change radius with mouse wheel.

That sounds like a good idea. I don’t have a mouse wheel for testing it out, but I can add in the code anyway. Currently The brush size is changed with the +/-keys. 

I hope to post a new player and demo file soon to show the new updates, the maker program is taking the most work.

Btw @bplus, do you have a GitHub page or place where your put all you code snippets? You sure have a ton of golden nuggets people can learn from.

- Dav
« Last Edit: June 09, 2021, 09:07:08 am by Dav »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #18 on: June 09, 2021, 11:00:39 am »
@Dav thanks, I am thinking this app might be perfect for your right click popup menu.

Quote
Btw @bplus, do you have a GitHub page or place where your put all you code snippets? You sure have a ton of golden nuggets people can learn from.

I have a few choice items stashed or linked in this thread that I add to now and then
https://www.qb64.org/forum/index.php?topic=1511.0

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #19 on: June 09, 2021, 04:34:23 pm »
@Dav thanks, I am thinking this app might be perfect for your right click popup menu.

Yeah, I'm doing a right click menu thing for it, trying to combine a menu it with a color picker. 

I getting a weird hangup/delay with the IDE (v1.5) programming this.  It's like the IDE is checking syntax or something, and it has to think for about 15 seconds and freezes.  Then all is well.  Happened a few times.  Nothing I can narrow down yet - not sure if it happens when typing or clicking on a new line.  I'll try to catch what I'm doing when the freeze happens.

- Dav

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #20 on: June 09, 2021, 10:02:50 pm »
@bplus: I was still getting occasional gaps in when drawing fast long lines. After playing around with it for a while, adding the little stilldown flag resulted in absolutely no gaps in the drawing line now.

Btw, your way of polling mouse input is best (WHILE _MOUSEINPUT: WEND).  My way was causing a noticeable drawing drag (mi = _MOUSEINPUT).   

The code below is the method I'm going with -  runs pretty smooth on even large brush size% numbers.

- Dav

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. CLS , _RGB(255, 255, 255)
  4.  
  5. clr& = _RGB(0, 0, 0)
  6. size% = 15
  7.  
  8.  
  9.     'mi = _MOUSEINPUT
  10.  
  11.     mx = _MOUSEX: my = _MOUSEY
  12.     mb1 = _MOUSEBUTTON(1)
  13.  
  14.     IF mb1 THEN
  15.         IF stilldown = 1 THEN
  16.             stepx = lastmx - mx
  17.             stepy = lastmy - my
  18.             length = INT((stepx ^ 2 + stepy ^ 2) ^ .5)
  19.             dx = stepx / length
  20.             dy = stepy / length
  21.             FOR i = 0 TO length
  22.                 FOR d = 1 TO size%
  23.                     CIRCLE (mx + dx * i, my + dy * i), d, clr&
  24.                 NEXT
  25.             NEXT
  26.         ELSE
  27.             FOR d = 1 TO size% STEP .2
  28.                 CIRCLE (mx, my), d, clr&
  29.             NEXT
  30.         END IF
  31.         lastmx = mx: lastmy = my
  32.         stilldown = 1
  33.     ELSE
  34.         stilldown = 0
  35.     END IF
  36.  
  37.     _LIMIT 300
  38.  
  39.  
« Last Edit: June 09, 2021, 10:09:16 pm by Dav »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Dav's Doodle Dandy - animated image drawing.
« Reply #21 on: June 09, 2021, 10:24:35 pm »
Quote
@bplus: I was still getting occasional gaps in when drawing fast long lines. After playing around with it for a while, adding the little stilldown flag resulted in absolutely no gaps in the drawing line now.

Yeah as I said I had a Windows Update waiting in wings and was getting bogged down and interrupts and Not Responding crap with everything I did while testing the mouse drawing. I did notice occasional jumps but wasn't sure if Windows was just being obnoxious until I stopped and did update.

@Dav your solution here is smooth as silk! nice fix.