Author Topic: Lightning Globe  (Read 6356 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Lightning Globe
« on: September 04, 2019, 11:28:42 pm »
I've been working on a new lightning globe program. It's just something fun I'm messing around with. But like usual, I think I got it down and then something really weird happens. The program stops completely or it's trapped in a loop somewhere and I can't figure it out. It's a very small program and any help is appreciated, thanks. It makes 1 lightning bolt from the center to where you click your mouse on the globe. Then it stops! LOL I have no idea why yet. You can see that I'm even testing it at the bottom of the program to see if the whole program stops or what, and it does. I do that with 2 LOCATE lines. I mean, the program keeps going (somewhere) but it doesn't reach the bottom of the program after you make 1 lightning bolt first. Is there some focus command I don't know about using the mouse? Oh also for some reason, instead of making a white circle on the globe, it makes a white square, with a CIRCLE command??? lol

Code: QB64: [Select]
  1. _TITLE "Lightning Globe by Ken G."
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. x = 400
  4. y = 300
  5. c = 0
  6. st = 2
  7. FOR sz = 1 TO 200 STEP .25
  8.     c = c + .05
  9.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  10. NEXT sz
  11. c = 0
  12. FOR sz = 1 TO 30 STEP .25
  13.     c = c + .005
  14.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  15. NEXT sz
  16.  
  17. 'Main Loop
  18.  
  19. go:
  20. mouseWheel = 0
  21.     handx = _MOUSEX
  22.     handy = _MOUSEY
  23.     mouseLeftButton = _MOUSEBUTTON(1)
  24.     mouseRightButton = _MOUSEBUTTON(2)
  25.     mouseMiddleButton = _MOUSEBUTTON(3)
  26.     mouseWheel = mouseWheel + _MOUSEWHEEL
  27. IF mouseLeftButton = -1 THEN
  28.     IF POINT(handx, handy) <> _RGB32(0, 0, 0) THEN
  29.         RANDOMIZE TIMER
  30.         lxx = (RND * 60) + 370
  31.         lyy = (RND * 60) + 270
  32.         DO
  33.             oldlx = lxx
  34.             oldly = lyy
  35.             IF lxx < handx THEN dxx = 10
  36.             IF lxx > handx THEN dxx = -10
  37.             IF lyy < handy THEN dyy = 10
  38.             IF lyy > handy THEN dyy = -10
  39.             RANDOMIZE TIMER
  40.             dx = (RND * 8) - 4
  41.             dy = (RND * 8) - 4
  42.             lxx = lxx + dx
  43.             lyy = lyy + dy
  44.             lxx = lxx + dxx
  45.             lyy = lyy + dyy
  46.             IF POINT(lxx, lyy) = _RGB32(0, 0, 0) THEN
  47.                 FOR sz = 1 TO 10 STEP .5
  48.                     CIRCLE (handx, handy), sz, _RGB32(255, 255, 255)
  49.                 NEXT sz
  50.                 _DELAY .02
  51.                 GOTO nex:
  52.             END IF
  53.             LINE (oldlx, oldly)-(lxx, lyy), _RGB32(255, 255, 255)
  54.         LOOP
  55.     END IF
  56. nex:
  57. LOCATE 2, 1: PRINT ttt: ttt = ttt + 1
  58. LOCATE 1, 1: PRINT handx, handy, mouseLeftButton
  59. GOTO go:
  60. 'Going back to the start of Main Loop.
  61.  
  62.  
« Last Edit: September 04, 2019, 11:32:08 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #1 on: September 05, 2019, 12:04:56 am »
Nevermind, LOL I found the problem..... I added a _LIMIT 50 at the bottom loop and it's making the last line non-stop because the globe is 3D, not 2D, and I was thinking the lightning would go to the edge of the globe but it doesn't of course. LOL Will try to fix it...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Lightning Globe
« Reply #2 on: September 05, 2019, 01:21:47 am »
Hi Ken, man I gave up trying to fix yours, here's mine to break!

Code: QB64: [Select]
  1. _TITLE "Lightning Globe" 'B+ 2019-09-05
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 60
  4. COLOR &HFF00BBFF
  5.     CLS
  6.     CIRCLE (400, 300), 30, &HFF202040
  7.     PAINT (400, 300), &HFF202040
  8.     CIRCLE (400, 300), 200, &HFFFFFFFF
  9.     PAINT (400, 300), &H16FFFFFF, &HFFFFFFFF
  10.  
  11.     mx = _MOUSEX: my = _MOUSEY: MB = _MOUSEBUTTON(1)
  12.     a = _ATAN2(my - 300, mx - 400)
  13.     IF MB THEN
  14.         'from random point of circle
  15.         LINE (0, 0)-(_WIDTH, _HEIGHT), &H88FFFFFF, BF
  16.         _DISPLAY
  17.         CLS
  18.         CIRCLE (400, 300), 30, &HFF202040
  19.         PAINT (400, 300), &HFF202040
  20.         IF ((mx - 400) ^ 2 + (my - 300) ^ 2) ^ .5 > 200 THEN
  21.             rx = 400 + 200 * COS(a): ry = 300 + 200 * SIN(a)
  22.         ELSE
  23.             rx = mx: ry = my
  24.         END IF
  25.         a = _PI(2) * RND
  26.         gx = 400 + 30 * COS(a): gy = 300 + 30 * SIN(a)
  27.         Lightning rx, ry, gx, gy, 100
  28.         CIRCLE (400, 300), 200, &HFFFFFFFF
  29.         PAINT (400, 300), &H16FFFFFF, &HFFFFFFFF
  30.         _DELAY .001
  31.     END IF
  32.     _LIMIT 100
  33.     _DISPLAY
  34.  
  35. SUB Lightning (xx1, yy1, xx2, yy2, dd)
  36.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: d = dd
  37.     IF d < 5 THEN
  38.         COLOR _RGB(225, 225, 245)
  39.         LINE (x1, y1)-(x2, y2)
  40.     ELSE
  41.         mx = (x2 + x1) / 2
  42.         my = (y2 + y1) / 2
  43.         mx = mx + -.5 * RND * d * .4 * rand&&(-5, 5)
  44.         my = my + -.5 * RND * d * .4 * rand&&(-5, 5)
  45.         Lightning x1, y1, mx, my, d / 2
  46.         Lightning x2, y2, mx, my, d / 2
  47.     END IF
  48.  
  49. FUNCTION rand&& (lo&&, hi&&)
  50.     rand&& = INT(RND * (hi&& - lo&& + 1)) + lo&&
  51.  
  52.  
  53.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #3 on: September 05, 2019, 01:22:27 am »
LOL I did it! I made the Lightning Globe I wanted to make to begin with. You can even hold down the mouse button on the globe and it makes different lightning to your mouse pointer. It could use a little sprucing up, like I removed the POINT command to where you click at and just made a IF/THEN for a make-believe box around the globe. I still don't know exactly how to use POINT with IF/THEN statements. It didn't seem to work when I tried it like this: a& = POINT(x,y) : IF a& <> _RGB32(0,0,0) THEN  .... Or instead of the _RGB32(0,0,0) do you just use 0 ? Anyways, please check out my new Lightning Globe. Use the mouse to click it. Esc ends the program.

Code: QB64: [Select]
  1. _TITLE "Lightning Globe by Ken G. - Use Mouse and Left Mouse Button On the Globe. Esc to end."
  2. _LIMIT 100
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. x = 400
  5. y = 300
  6. c = 1
  7. st = 2
  8. go:
  9. a$ = INKEY$
  10. IF a$ = CHR$(27) THEN END
  11. _LIMIT 200
  12. FOR sz = 1 TO 200 STEP .25
  13.     c = c + .05
  14.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  15. NEXT sz
  16. c = 0
  17. FOR sz = 1 TO 30 STEP .25
  18.     c = c + .005
  19.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  20. NEXT sz
  21.  
  22. mouseWheel = 0
  23.     handx = _MOUSEX
  24.     handy = _MOUSEY
  25.     mouseLeftButton = _MOUSEBUTTON(1)
  26.     mouseRightButton = _MOUSEBUTTON(2)
  27.     mouseMiddleButton = _MOUSEBUTTON(3)
  28.     mouseWheel = mouseWheel + _MOUSEWHEEL
  29. _LIMIT 200
  30. IF mouseLeftButton = -1 THEN
  31.     IF handx < 600 AND handx > 200 AND handy > 100 AND handy < 500 THEN
  32.         RANDOMIZE TIMER
  33.         lxx = (RND * 60) + 370
  34.         lyy = (RND * 60) + 270
  35.         DO
  36.             _LIMIT 300
  37.             oldlx = lxx
  38.             oldly = lyy
  39.             IF lxx < handx THEN dxx = 10
  40.             IF lxx > handx THEN dxx = -10
  41.             IF lyy < handy THEN dyy = 10
  42.             IF lyy > handy THEN dyy = -10
  43.             RANDOMIZE TIMER
  44.             dx = (RND * 8) - 4
  45.             dy = (RND * 8) - 4
  46.             lxx = lxx + dx
  47.             lyy = lyy + dy
  48.             lxx = lxx + dxx
  49.             lyy = lyy + dyy
  50.             LINE (oldlx, oldly)-(lxx, lyy), _RGB32(255, 255, 255)
  51.             ttt = ttt + 1
  52.             IF ttt > 20 THEN GOTO nex:
  53.         LOOP
  54.     END IF
  55. nex:
  56. ttt = 0
  57. lxx2 = (RND * 60) + 370
  58. lyy2 = (RND * 60) + 270
  59. lxx3 = (RND * 200) + 270
  60. lyy3 = (RND * 200) + 170
  61. lxx4 = (RND * 60) + 370
  62. lyy4 = (RND * 60) + 270
  63. lxx5 = (RND * 200) + 270
  64. lyy5 = (RND * 200) + 170
  65.  
  66.  
  67.     _LIMIT 200
  68.     oldlx2 = lxx2
  69.     oldly2 = lyy2
  70.     oldlx4 = lxx4
  71.     oldly4 = lyy4
  72.     IF lxx2 < lxx3 THEN dxx = 10
  73.     IF lxx2 > lxx3 THEN dxx = -10
  74.     IF lyy2 < lyy3 THEN dyy = 10
  75.     IF lyy2 > lyy3 THEN dyy = -10
  76.  
  77.     IF lxx4 < lxx5 THEN dxx2 = 10
  78.     IF lxx4 > lxx5 THEN dxx2 = -10
  79.     IF lyy4 < lyy5 THEN dyy2 = 10
  80.     IF lyy4 > lyy5 THEN dyy2 = -10
  81.     dx = (RND * 8) - 4
  82.     dy = (RND * 8) - 4
  83.     dx2 = (RND * 8) - 4
  84.     dy2 = (RND * 8) - 4
  85.     lxx2 = lxx2 + dx
  86.     lyy2 = lyy2 + dy
  87.     lxx2 = lxx2 + dxx
  88.     lyy2 = lyy2 + dyy
  89.     lxx4 = lxx4 + dx2
  90.     lyy4 = lyy4 + dy2
  91.     lxx4 = lxx4 + dxx2
  92.     lyy4 = lyy4 + dyy2
  93.     LINE (oldlx2, oldly2)-(lxx2, lyy2), _RGB32(155, 155, 155)
  94.     LINE (oldlx4, oldly4)-(lxx4, lyy4), _RGB32(155, 155, 155)
  95.     ttt2 = ttt2 + 1
  96.     IF ttt2 > 10 THEN GOTO nex2:
  97.  
  98. nex2:
  99. LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, 30), BF
  100. ttt2 = 0
  101. GOTO go:
  102. 'Going back to the start of Main Loop.
  103.  
  104.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #4 on: September 05, 2019, 01:26:17 am »
Yours is pretty cool B+. But why the flashing all around screen? I like how you have 2 lightning bolts instead of my 1 that the user makes. I might spruce mine up some.
« Last Edit: September 05, 2019, 01:27:47 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Lightning Globe
« Reply #5 on: September 05, 2019, 01:30:54 am »
Quote
But why the flashing all around screen?

Drama

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #6 on: September 05, 2019, 01:35:49 am »
Ah OK cool... so visual effects. :)

Try out mine and tell me what you think. I used a lot of what you taught me, like the fade out with RGB32 constantly erasing the screen. Man, back in the old days with the older computers, that was unheard of pretty much. So programs like this were incredibly harder to erase everything. I posted mine above.
« Last Edit: September 05, 2019, 01:37:11 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Lightning Globe
« Reply #7 on: September 05, 2019, 09:14:06 am »
Ken, you are coming along nicely keep trying new things to get practice with them. You have ambitions beyond your experience which is great motivator, don't give up on arrays and SUBs these are power tools that will help you achieve your vision. Learning mouse is great!

For polling the mouse ie, getting updates of location and mouse buttons do this:
Code: QB64: [Select]
  1.    WHILE _MOUSEINPUT: WEND ' <<<<<<<<<<<<<<<<<<<<<<< empty loop, because that is all you need!
  2.     mx = _MOUSEX: my = _MOUSEY: MB = _MOUSEBUTTON(1) '<<<< right after store states of mouse
  3.  

Now IF you need wheel info, THEN  put something inside the WHILE _MOUSEINPUT: WEND loop.

FellippeHeitor

  • Guest
Re: Lightning Globe
« Reply #8 on: September 05, 2019, 10:55:37 am »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Lightning Globe
« Reply #9 on: September 05, 2019, 11:31:41 am »
Hi Ken, man I gave up trying to fix yours, here's mine to break!

Code: QB64: [Select]
  1. _TITLE "Lightning Globe" 'B+ 2019-09-05
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 60
  4. COLOR &HFF00BBFF
  5.     CLS
  6.     CIRCLE (400, 300), 30, &HFF202040
  7.     PAINT (400, 300), &HFF202040
  8.     CIRCLE (400, 300), 200, &HFFFFFFFF
  9.     PAINT (400, 300), &H16FFFFFF, &HFFFFFFFF
  10.  
  11.     mx = _MOUSEX: my = _MOUSEY: MB = _MOUSEBUTTON(1)
  12.     a = _ATAN2(my - 300, mx - 400)
  13.     IF MB THEN
  14.         'from random point of circle
  15.         LINE (0, 0)-(_WIDTH, _HEIGHT), &H88FFFFFF, BF
  16.         _DISPLAY
  17.         CLS
  18.         CIRCLE (400, 300), 30, &HFF202040
  19.         PAINT (400, 300), &HFF202040
  20.         IF ((mx - 400) ^ 2 + (my - 300) ^ 2) ^ .5 > 200 THEN
  21.             rx = 400 + 200 * COS(a): ry = 300 + 200 * SIN(a)
  22.         ELSE
  23.             rx = mx: ry = my
  24.         END IF
  25.         a = _PI(2) * RND
  26.         gx = 400 + 30 * COS(a): gy = 300 + 30 * SIN(a)
  27.         Lightning rx, ry, gx, gy, 100
  28.         CIRCLE (400, 300), 200, &HFFFFFFFF
  29.         PAINT (400, 300), &H16FFFFFF, &HFFFFFFFF
  30.         _DELAY .001
  31.     END IF
  32.     _LIMIT 100
  33.     _DISPLAY
  34.  
  35. SUB Lightning (xx1, yy1, xx2, yy2, dd)
  36.     x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: d = dd
  37.     IF d < 5 THEN
  38.         COLOR _RGB(225, 225, 245)
  39.         LINE (x1, y1)-(x2, y2)
  40.     ELSE
  41.         mx = (x2 + x1) / 2
  42.         my = (y2 + y1) / 2
  43.         mx = mx + -.5 * RND * d * .4 * rand&&(-5, 5)
  44.         my = my + -.5 * RND * d * .4 * rand&&(-5, 5)
  45.         Lightning x1, y1, mx, my, d / 2
  46.         Lightning x2, y2, mx, my, d / 2
  47.     END IF
  48.  
  49. FUNCTION rand&& (lo&&, hi&&)
  50.     rand&& = INT(RND * (hi&& - lo&& + 1)) + lo&&
  51.  
  52.  
  53.  

Here's mine, in about half the code, without any of that fancy math to get lost in. ;D

Take a look at how simple this little lightning zapper is, and see if you guys understand how it works.  I honestly don't think you can get any simpler than this little concept:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. CONST LevelOfVariance = 5 'Change this value to have fun with the strength of the "draw" to target.
  3.     _LIMIT 60
  4.     CLS
  5.     CIRCLE (320, 240), 20, &HFFAAAAAA
  6.     PAINT (320, 240), &HFFAAAAAA
  7.         StartX = 320: StartY = 240: EndX = _MOUSEX: EndY = _MOUSEY
  8.         Kolor = &HFF000000 + INT(RND * &H1000000)
  9.         COLOR Kolor
  10.         DO UNTIL StartX = EndX AND StartY = EndY
  11.             CoinToss = RND * 100 'The strength of "draw" which pulls the lightning to the target.
  12.             IF CoinToss < LevelOfVariance THEN 'Higher values meander less and go directly to the target.
  13.                 XChange = SGN(EndX - StartX) '-1,0,1, drawn always towards the mouse
  14.                 YChange = SGN(EndY - StartY)
  15.             ELSE
  16.                 XChange = INT(RND * 3) - 1 '-1, 0, or 1, drawn in a random direction to let the lightning wander
  17.                 YChange = INT(RND * 3) - 1
  18.             END IF
  19.             StartX = StartX + XChange
  20.             StartY = StartY + YChange
  21.             PSET (StartX, StartY), Kolor
  22.         LOOP
  23.     END IF
  24.     _DISPLAY
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #10 on: September 05, 2019, 12:44:18 pm »
Thanks B+, I added your Mouse code to a Notepad. Yeah, I should use SUB's more, etc... hard to teach an old dog new tricks :).

Steve that's really awesome! I wonder if there's a way to make a window a circle instead of a rectangle, I never seen one all these years I think.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Lightning Globe
« Reply #11 on: September 05, 2019, 12:48:40 pm »
Hi Ken,

You can make a peep hole in a rectangle screen...

Oh man! Steve's got my mind in the gutter at IRC ;-P

Hey Ken, try out IRC!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #12 on: September 05, 2019, 04:37:49 pm »
Here is an updated version of mine. I enhanced it by making 2 lightning bolts at 25% of the time. Seems like more often, but that's what I set it on. I also sped it up some and added a glow to the entire globe when you make a lightning bolt. I still don't know the math to make the bolts 100% inside the globe. I tried a POINT command along with the mouse button click, but no luck. For some reason is squeezes through and still makes a bolt outside the globe even farther than what I have now. So I went back with the invisible box around the globe.
B+, yeah I been to the IRC room 3 times now, it's pretty cool. :)

Code: QB64: [Select]
  1. _TITLE "Lightning Globe by Ken G. - Use Mouse and Left Mouse Button On the Globe. Esc to end."
  2. _LIMIT 100
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. x = 400
  5. y = 300
  6. c = 1
  7. st = 2
  8. l = 500
  9. go:
  10. a$ = INKEY$
  11. IF a$ = CHR$(27) THEN END
  12. _LIMIT 200
  13. FOR sz = 1 TO 200 STEP .25
  14.     c = c + .05 + r
  15.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  16. NEXT sz
  17. c = 0
  18. FOR sz = 1 TO 30 STEP .25
  19.     c = c + .005
  20.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  21. NEXT sz
  22.  
  23. handx = _MOUSEX: handy = _MOUSEY: MB = _MOUSEBUTTON(1)
  24. _LIMIT 200
  25.  
  26. IF l > 500 THEN l = 500
  27. IF l < 50 THEN l = 50
  28. IF MB = -1 THEN
  29.     IF handx < 600 AND handx > 200 AND handy > 100 AND handy < 500 THEN
  30.         r = .1
  31.         RANDOMIZE TIMER
  32.         lxx = (RND * 60) + 370
  33.         lyy = (RND * 60) + 270
  34.         RANDOMIZE TIMER
  35.         lxxx = (RND * 60) + 370
  36.         lyyy = (RND * 60) + 270
  37.         bolts = INT(RND * 100) + 1
  38.         DO
  39.             _LIMIT 500
  40.             oldlx = lxx
  41.             oldly = lyy
  42.             oldlxx = lxxx
  43.             oldlyy = lyyy
  44.             IF lxx < handx THEN dxx = 10
  45.             IF lxx > handx THEN dxx = -10
  46.             IF lyy < handy THEN dyy = 10
  47.             IF lyy > handy THEN dyy = -10
  48.             IF lxxx < handx THEN dxxx = 10
  49.             IF lxxx > handx THEN dxxx = -10
  50.             IF lyyy < handy THEN dyyy = 10
  51.             IF lyyy > handy THEN dyyy = -10
  52.             RANDOMIZE TIMER
  53.             dx = (RND * 8) - 4
  54.             dy = (RND * 8) - 4
  55.             RANDOMIZE TIMER
  56.             dxxxx = (RND * 8) - 4
  57.             dyyyy = (RND * 8) - 4
  58.             lxx = lxx + dx
  59.             lyy = lyy + dy
  60.             lxx = lxx + dxx
  61.             lyy = lyy + dyy
  62.             lxxx = lxxx + dxxxx
  63.             lyyy = lyyy + dyyyy
  64.             lxxx = lxxx + dxxx
  65.             lyyy = lyyy + dyyy
  66.             LINE (oldlx, oldly)-(lxx, lyy), _RGB32(255, 255, 255)
  67.             IF bolts > 75 THEN LINE (oldlxx, oldlyy)-(lxxx, lyyy), _RGB32(255, 255, 255)
  68.             ttt = ttt + 1
  69.             IF ttt > 20 THEN GOTO nex:
  70.         LOOP
  71.     END IF
  72. r = 0
  73. nex:
  74. ttt = 0
  75. lxx2 = (RND * 60) + 370
  76. lyy2 = (RND * 60) + 270
  77. lxx3 = (RND * 200) + 270
  78. lyy3 = (RND * 200) + 170
  79. lxx4 = (RND * 60) + 370
  80. lyy4 = (RND * 60) + 270
  81. lxx5 = (RND * 200) + 270
  82. lyy5 = (RND * 200) + 170
  83.  
  84.  
  85.     _LIMIT 500
  86.     oldlx2 = lxx2
  87.     oldly2 = lyy2
  88.     oldlx4 = lxx4
  89.     oldly4 = lyy4
  90.     IF lxx2 < lxx3 THEN dxx = 10
  91.     IF lxx2 > lxx3 THEN dxx = -10
  92.     IF lyy2 < lyy3 THEN dyy = 10
  93.     IF lyy2 > lyy3 THEN dyy = -10
  94.  
  95.     IF lxx4 < lxx5 THEN dxx2 = 10
  96.     IF lxx4 > lxx5 THEN dxx2 = -10
  97.     IF lyy4 < lyy5 THEN dyy2 = 10
  98.     IF lyy4 > lyy5 THEN dyy2 = -10
  99.     dx = (RND * 8) - 4
  100.     dy = (RND * 8) - 4
  101.     dx2 = (RND * 8) - 4
  102.     dy2 = (RND * 8) - 4
  103.     lxx2 = lxx2 + dx
  104.     lyy2 = lyy2 + dy
  105.     lxx2 = lxx2 + dxx
  106.     lyy2 = lyy2 + dyy
  107.     lxx4 = lxx4 + dx2
  108.     lyy4 = lyy4 + dy2
  109.     lxx4 = lxx4 + dxx2
  110.     lyy4 = lyy4 + dyy2
  111.     LINE (oldlx2, oldly2)-(lxx2, lyy2), _RGB32(155, 155, 155)
  112.     LINE (oldlx4, oldly4)-(lxx4, lyy4), _RGB32(155, 155, 155)
  113.     ttt2 = ttt2 + 1
  114.     IF ttt2 > 10 THEN GOTO nex2:
  115.  
  116. nex2:
  117. LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, 30), BF
  118. ttt2 = 0
  119. GOTO go:
  120. 'Going back to the start of Main Loop.
  121.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #13 on: September 05, 2019, 04:55:12 pm »
LOL!  Thank you Steve (SMcneill) for the math!! He gave it to me in the IRC room. It's a lot simpler than I thought using the _HPOT command to get the longer side of a right triangle! So I finally got it where you can't make the lightning outside of the globe. Although sometimes the lightning does go a little bit outside, but I will keep that there just for the brightness and mystery of the electricity.  :) So here is what I have. By the way, I was thinking a lot about this program last night and it might have been B+'s globe that he posted months ago that inspired me to make this. When I started this I didn't think about that, but later on I remembered his. Thanks B+ and Steve!

Code: QB64: [Select]
  1. 'This program was made on Sept. 5, 2019 by Ken G.
  2. 'Thank you to B+ and Steve for the inspiration and some help.
  3. _TITLE "Lightning Globe by Ken G. - Use Mouse and Left Mouse Button On the Globe. Esc to end."
  4. _LIMIT 100
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. x = 400
  7. y = 300
  8. c = 1
  9. st = 2
  10. l = 500
  11. go:
  12. a$ = INKEY$
  13. IF a$ = CHR$(27) THEN END
  14. _LIMIT 200
  15. FOR sz = 1 TO 200 STEP .25
  16.     c = c + .05 + r
  17.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  18. NEXT sz
  19. c = 0
  20. FOR sz = 1 TO 30 STEP .25
  21.     c = c + .005
  22.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  23. NEXT sz
  24.  
  25. handx = _MOUSEX: handy = _MOUSEY: MB = _MOUSEBUTTON(1)
  26. _LIMIT 200
  27.  
  28. IF l > 500 THEN l = 500
  29. IF l < 50 THEN l = 50
  30. IF MB = -1 THEN
  31.     'IF handx < 600 AND handx > 200 AND handy > 100 AND handy < 500 THEN
  32.     IF _HYPOT(handx - 400, handy - 300) < 200 THEN
  33.  
  34.         r = .1
  35.         RANDOMIZE TIMER
  36.         lxx = (RND * 60) + 370
  37.         lyy = (RND * 60) + 270
  38.         RANDOMIZE TIMER
  39.         lxxx = (RND * 60) + 370
  40.         lyyy = (RND * 60) + 270
  41.         bolts = INT(RND * 100) + 1
  42.         DO
  43.             _LIMIT 500
  44.             oldlx = lxx
  45.             oldly = lyy
  46.             oldlxx = lxxx
  47.             oldlyy = lyyy
  48.             IF lxx < handx THEN dxx = 10
  49.             IF lxx > handx THEN dxx = -10
  50.             IF lyy < handy THEN dyy = 10
  51.             IF lyy > handy THEN dyy = -10
  52.             IF lxxx < handx THEN dxxx = 10
  53.             IF lxxx > handx THEN dxxx = -10
  54.             IF lyyy < handy THEN dyyy = 10
  55.             IF lyyy > handy THEN dyyy = -10
  56.             RANDOMIZE TIMER
  57.             dx = (RND * 8) - 4
  58.             dy = (RND * 8) - 4
  59.             RANDOMIZE TIMER
  60.             dxxxx = (RND * 8) - 4
  61.             dyyyy = (RND * 8) - 4
  62.             lxx = lxx + dx
  63.             lyy = lyy + dy
  64.             lxx = lxx + dxx
  65.             lyy = lyy + dyy
  66.             lxxx = lxxx + dxxxx
  67.             lyyy = lyyy + dyyyy
  68.             lxxx = lxxx + dxxx
  69.             lyyy = lyyy + dyyy
  70.             LINE (oldlx, oldly)-(lxx, lyy), _RGB32(255, 255, 255)
  71.             IF bolts > 75 THEN LINE (oldlxx, oldlyy)-(lxxx, lyyy), _RGB32(255, 255, 255)
  72.             ttt = ttt + 1
  73.             IF ttt > 20 THEN GOTO nex:
  74.         LOOP
  75.     END IF
  76. r = 0
  77. nex:
  78. ttt = 0
  79. lxx2 = (RND * 60) + 370
  80. lyy2 = (RND * 60) + 270
  81. lxx3 = (RND * 200) + 270
  82. lyy3 = (RND * 200) + 170
  83. lxx4 = (RND * 60) + 370
  84. lyy4 = (RND * 60) + 270
  85. lxx5 = (RND * 200) + 270
  86. lyy5 = (RND * 200) + 170
  87.  
  88.  
  89.     _LIMIT 500
  90.     oldlx2 = lxx2
  91.     oldly2 = lyy2
  92.     oldlx4 = lxx4
  93.     oldly4 = lyy4
  94.     IF lxx2 < lxx3 THEN dxx = 10
  95.     IF lxx2 > lxx3 THEN dxx = -10
  96.     IF lyy2 < lyy3 THEN dyy = 10
  97.     IF lyy2 > lyy3 THEN dyy = -10
  98.  
  99.     IF lxx4 < lxx5 THEN dxx2 = 10
  100.     IF lxx4 > lxx5 THEN dxx2 = -10
  101.     IF lyy4 < lyy5 THEN dyy2 = 10
  102.     IF lyy4 > lyy5 THEN dyy2 = -10
  103.     dx = (RND * 8) - 4
  104.     dy = (RND * 8) - 4
  105.     dx2 = (RND * 8) - 4
  106.     dy2 = (RND * 8) - 4
  107.     lxx2 = lxx2 + dx
  108.     lyy2 = lyy2 + dy
  109.     lxx2 = lxx2 + dxx
  110.     lyy2 = lyy2 + dyy
  111.     lxx4 = lxx4 + dx2
  112.     lyy4 = lyy4 + dy2
  113.     lxx4 = lxx4 + dxx2
  114.     lyy4 = lyy4 + dyy2
  115.     LINE (oldlx2, oldly2)-(lxx2, lyy2), _RGB32(155, 155, 155)
  116.     LINE (oldlx4, oldly4)-(lxx4, lyy4), _RGB32(155, 155, 155)
  117.     ttt2 = ttt2 + 1
  118.     IF ttt2 > 10 THEN GOTO nex2:
  119.  
  120. nex2:
  121. LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, 30), BF
  122. ttt2 = 0
  123. GOTO go:
  124. 'Going back to the start of Main Loop.
  125.  
  126.  

« Last Edit: September 05, 2019, 05:05:21 pm by SierraKen »

Marked as best answer by SierraKen on September 05, 2019, 05:09:31 pm

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Lightning Globe
« Reply #14 on: September 05, 2019, 09:09:21 pm »
Here is the final version of my Lightning Globe (most likely). I made a stand and changed the colors of the electricity to a bright purple like the real ones are. I also made filled in circles to where the lightning begins in the center and larger ones where they end.

Code: QB64: [Select]
  1. 'This program was made on Sept. 5, 2019 by Ken G.
  2. 'Thank you to B+ and Steve for the inspiration and some help.
  3. _TITLE "Lightning Globe by Ken G. - Use Mouse and Left Mouse Button On the Globe. Esc to end."
  4. _SCREENMOVE 400, 60
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. x = 400
  7. y = 300
  8. c = 1
  9. st = 2
  10. go:
  11. a$ = INKEY$
  12. IF a$ = CHR$(27) THEN END
  13. _LIMIT 1000
  14. LINE (400, 300)-(150, 600), _RGB32(50, 50, 50)
  15. LINE (400, 300)-(650, 600), _RGB32(50, 50, 50)
  16. LINE (150, 600)-(650, 600), _RGB32(50, 50, 50)
  17. PAINT (500, 580), _RGB32(50, 50, 50)
  18.  
  19. FOR sz = 1 TO 200 STEP .25
  20.     c = c + .05 + r
  21.     CIRCLE (x, y), sz, _RGB32(c, c / 2, c)
  22. NEXT sz
  23. c = 0
  24. FOR sz = 1 TO 30 STEP .25
  25.     c = c + .005
  26.     CIRCLE (x, y), sz, _RGB32(c, c, c)
  27. NEXT sz
  28.  
  29. handx = _MOUSEX: handy = _MOUSEY: MB = _MOUSEBUTTON(1)
  30.  
  31. IF l > 500 THEN l = 500
  32. IF l < 50 THEN l = 50
  33.  
  34. IF MB = -1 AND _HYPOT(handx - 400, handy - 300) < 200 THEN
  35.     r = .1
  36.     lxx = (RND * 60) + 370
  37.     lyy = (RND * 60) + 270
  38.     lxxx = (RND * 60) + 370
  39.     lyyy = (RND * 60) + 270
  40.     bolts = INT(RND * 100) + 1
  41.     CIRCLE (lxx, lyy), 4, _RGB32(255, 245, 255)
  42.     PAINT (lxx, lyy), _RGB32(255, 245, 255)
  43.     IF bolts > 50 THEN
  44.         CIRCLE (lxxx, lyyy), 4, _RGB32(255, 245, 255)
  45.         PAINT (lxxx, lyyy), _RGB32(255, 245, 255)
  46.     END IF
  47.  
  48.     DO
  49.         _LIMIT 1000
  50.         oldlx = lxx
  51.         oldly = lyy
  52.         oldlxx = lxxx
  53.         oldlyy = lyyy
  54.         IF lxx < handx THEN dxx = 10
  55.         IF lxx > handx THEN dxx = -10
  56.         IF lyy < handy THEN dyy = 10
  57.         IF lyy > handy THEN dyy = -10
  58.         IF lxxx < handx THEN dxxx = 10
  59.         IF lxxx > handx THEN dxxx = -10
  60.         IF lyyy < handy THEN dyyy = 10
  61.         IF lyyy > handy THEN dyyy = -10
  62.         RANDOMIZE TIMER
  63.         dx = (RND * 8) - 4
  64.         dy = (RND * 8) - 4
  65.         RANDOMIZE TIMER
  66.         dxxxx = (RND * 8) - 4
  67.         dyyyy = (RND * 8) - 4
  68.         lxx = lxx + dx
  69.         lyy = lyy + dy
  70.         lxx = lxx + dxx
  71.         lyy = lyy + dyy
  72.         lxxx = lxxx + dxxxx
  73.         lyyy = lyyy + dyyyy
  74.         lxxx = lxxx + dxxx
  75.         lyyy = lyyy + dyyy
  76.         LINE (oldlx, oldly)-(lxx, lyy), _RGB32(255, 230, 255)
  77.         IF bolts > 50 THEN LINE (oldlxx, oldlyy)-(lxxx, lyyy), _RGB32(255, 230, 255)
  78.         ttt = ttt + 1
  79.         IF ttt > 20 THEN
  80.             CIRCLE (lxx, lyy), 10, _RGB32(255, 245, 255)
  81.             PAINT (lxx, lyy), _RGB32(255, 245, 255)
  82.             GOTO nex:
  83.         END IF
  84.     LOOP
  85. r = 0
  86. nex:
  87. ttt = 0
  88. lxx2 = (RND * 60) + 370
  89. lyy2 = (RND * 60) + 270
  90. lxx3 = (RND * 200) + 270
  91. lyy3 = (RND * 200) + 170
  92. lxx4 = (RND * 60) + 370
  93. lyy4 = (RND * 60) + 270
  94. lxx5 = (RND * 200) + 270
  95. lyy5 = (RND * 200) + 170
  96.  
  97. CIRCLE (lxx2, lyy2), 4, _RGB32(255, 245, 255)
  98. PAINT (lxx2, lyy2), _RGB32(255, 245, 255)
  99. CIRCLE (lxx4, lyy4), 4, _RGB32(255, 245, 255)
  100. PAINT (lxx4, lyy4), _RGB32(255, 245, 255)
  101.  
  102.     _LIMIT 1000
  103.     oldlx2 = lxx2
  104.     oldly2 = lyy2
  105.     oldlx4 = lxx4
  106.     oldly4 = lyy4
  107.     IF lxx2 < lxx3 THEN dxx = 10
  108.     IF lxx2 > lxx3 THEN dxx = -10
  109.     IF lyy2 < lyy3 THEN dyy = 10
  110.     IF lyy2 > lyy3 THEN dyy = -10
  111.  
  112.     IF lxx4 < lxx5 THEN dxx2 = 10
  113.     IF lxx4 > lxx5 THEN dxx2 = -10
  114.     IF lyy4 < lyy5 THEN dyy2 = 10
  115.     IF lyy4 > lyy5 THEN dyy2 = -10
  116.     dx = (RND * 8) - 4
  117.     dy = (RND * 8) - 4
  118.     dx2 = (RND * 8) - 4
  119.     dy2 = (RND * 8) - 4
  120.     lxx2 = lxx2 + dx
  121.     lyy2 = lyy2 + dy
  122.     lxx2 = lxx2 + dxx
  123.     lyy2 = lyy2 + dyy
  124.     lxx4 = lxx4 + dx2
  125.     lyy4 = lyy4 + dy2
  126.     lxx4 = lxx4 + dxx2
  127.     lyy4 = lyy4 + dyy2
  128.     LINE (oldlx2, oldly2)-(lxx2, lyy2), _RGB32(255, 161, 255)
  129.     LINE (oldlx4, oldly4)-(lxx4, lyy4), _RGB32(255, 161, 255)
  130.     ttt2 = ttt2 + 1
  131.     IF ttt2 > 50 THEN
  132.         CIRCLE (lxx2, lyy2), 8, _RGB32(255, 230, 255)
  133.         PAINT (lxx2, lyy2), _RGB32(255, 230, 255)
  134.         CIRCLE (lxx4, lyy4), 8, _RGB32(255, 230, 255)
  135.         PAINT (lxx4, lyy4), _RGB32(255, 230, 255)
  136.         GOTO nex2:
  137.     END IF
  138.  
  139. nex2:
  140. LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, 30), BF
  141. ttt2 = 0
  142. GOTO go:
  143. 'Going back to the start of Main Loop.
  144.  
  145.  
« Last Edit: September 05, 2019, 09:51:19 pm by SierraKen »