Author Topic: Mid-Year Christmas Lights  (Read 3465 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Mid-Year Christmas Lights
« on: August 25, 2020, 10:02:10 pm »
LOL just me experimenting again. Some of you might have made this before because it looks very familiar, but I think it's neat. It changes to new lights in different locations every few seconds.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. DIM xx(10), yy(10)
  3. DIM cc(10)
  4. _TITLE "Christmas Lights"
  5. start:
  6. tt = 2
  7. t2 = 1
  8. FOR a = 1 TO 10
  9.     xx(a) = RND * 800
  10.     yy(a) = RND * 600
  11.     c = INT(RND * 2) + 1
  12.     IF c = 1 THEN cc(a) = _RGB32(255, 0, 0)
  13.     IF c = 2 THEN cc(a) = _RGB32(0, 255, 0)
  14.  
  15.     _LIMIT 10
  16.     a$ = INKEY$
  17.     IF a$ = CHR$(27) THEN END
  18.     t2 = t2 + 1
  19.     FOR amount = 1 TO 10
  20.         FOR t = 359 + t2 TO t2 STEP -1
  21.             tt = tt + .25
  22.             x = (SIN(t) * (90 - tt)) + xx(amount)
  23.             y = (COS(t) * tt) + yy(amount)
  24.             CIRCLE (x, y), 1, cc(amount)
  25.         NEXT t
  26.         tt = 2
  27.     NEXT amount
  28.     _DISPLAY
  29.     CLS
  30.     m = m + 1
  31.     IF m = 50 THEN m = 0: GOTO start:
  32.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mid-Year Christmas Lights
« Reply #1 on: August 26, 2020, 11:47:36 am »
Hi Ken,

Nice effect.

You know if you can draw one of those diamond lights ornaments, you can draw any amount at any scale in a subroutine. All you would do is supply it with an x, y center, a color and a scale. The scale you would use with the multipliers of the radius for SIN and COS calculations to find the x,y pixels for the lights.

THEN
You can decorate trees or garland with those lights or hang them from top of screen and/or spell out Merry Christmas or Happy New Year or both ;)

PLUS you could blink them or have them roll through color patterns.


FellippeHeitor

  • Guest
Re: Mid-Year Christmas Lights
« Reply #2 on: August 26, 2020, 12:03:16 pm »
These are very good looking!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mid-Year Christmas Lights
« Reply #3 on: August 26, 2020, 02:39:40 pm »
Thanks guys! B+ yeah the lights started out really huge, so I figured out how to shrink them without having a bunch of pixel "glow" all over the place lol. I might play around with it and make something neat like that. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mid-Year Christmas Lights
« Reply #4 on: August 26, 2020, 05:11:16 pm »
Here is a much better version. Instead of just 10 at a time, I made 80 at a time with PSET instead of CIRCLE and increased the screen to 1000 x 800. I think most people have this size of screen by now, or larger. If by chance you are still using a 20 year old CRT monitor with 800 x 600, you can still run it but press Esc to quit the program since X will probably be off the screen.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1200, 800, 32)
  2. DIM xx(80), yy(80)
  3. DIM cc(80)
  4. _TITLE "Christmas Lights"
  5. start:
  6. tt = 2
  7. t2 = 1
  8. FOR a = 1 TO 80
  9.     xx(a) = RND * 1200
  10.     yy(a) = RND * 800
  11.     c = INT(RND * 2) + 1
  12.     IF c = 1 THEN cc(a) = _RGB32(255, 0, 0)
  13.     IF c = 2 THEN cc(a) = _RGB32(0, 255, 0)
  14.  
  15.     _LIMIT 10
  16.     a$ = INKEY$
  17.     IF a$ = CHR$(27) THEN END
  18.     t2 = t2 + 5
  19.     FOR amount = 1 TO 80
  20.         FOR t = 359 + t2 TO t2 STEP -1
  21.             tt = tt + .25
  22.             x = (SIN(t) * (90 - tt)) + xx(amount)
  23.             y = (COS(t) * tt) + yy(amount)
  24.             PSET (x, y), cc(amount)
  25.         NEXT t
  26.         tt = 2
  27.     NEXT amount
  28.     _DISPLAY
  29.     CLS
  30.     m = m + 1
  31.     IF m = 50 THEN m = 0: GOTO start:
  32.  

« Last Edit: August 26, 2020, 05:15:42 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mid-Year Christmas Lights
« Reply #5 on: August 26, 2020, 07:03:37 pm »
Actually with graphics, you can draw all you want off screen might waste time but does not error.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mid-Year Christmas Lights
« Reply #6 on: August 26, 2020, 09:02:47 pm »
That is rather weird object that ornament. But I pinned it down and fiddled with it:
Code: QB64: [Select]
  1. _TITLE "Draw Ken's Ornament" 'b+ 2020-08-26
  2. SCREEN _NEWIMAGE(1000, 700, 32)
  3. _DELAY .25
  4. DIM SHARED pR, pG, pB, pN AS DOUBLE
  5.  
  6. resetPlasma
  7. drawOrnament 500, 350, 90, 0
  8. LINE (400, 250)-STEP(200, 200), , B
  9. resetPlasma
  10. FOR r = 0 TO 200
  11.     CLS
  12.     PRINT r
  13.     drawOrnament 500, 350, r, 0
  14.     _DISPLAY
  15.     _LIMIT 10
  16. resetPlasma
  17. FOR r = 0 TO 200
  18.     CLS
  19.     PRINT r
  20.     drawOrnament 500, 350, r, -1
  21.     _DISPLAY
  22.     _LIMIT 10
  23.     CLS
  24.     rStop = (RND * 80 + 5) \ 1
  25.     FOR a = 1 TO rStop
  26.         resetPlasma
  27.         drawOrnament RND * 1000, RND * 700, 90, RND * 1 \ 1
  28.     NEXT
  29.     _DISPLAY
  30.     _DELAY 2
  31.  
  32.  
  33. 'Ken designed at r = 100, no 90 is best radius
  34. SUB drawOrnament (x, y, r, lineTF) ' well use r for radius instead of a scale
  35.     ' took me awhile to pin down this drawing!
  36.     'CIRCLE (x, y), 3
  37.     'CIRCLE (x + r, y), 3
  38.     'CIRCLE (x - r, y), 3
  39.     'CIRCLE (x, y + r), 3
  40.     'CIRCLE (x, y - r), 3
  41.     t2 = .22
  42.     FOR a = 359 + t2 TO t2 STEP -1
  43.         x = x + tt * COS(a)
  44.         y = y + (r - tt) * SIN(a)
  45.         tt = tt + .25
  46.         IF a = 359 + t2 THEN
  47.             PSET (x, y), Plasma~&
  48.         ELSE
  49.             IF lineTF THEN LINE -(x, y), Plasma~& ELSE PSET (x, y), Plasma~&
  50.         END IF
  51.     NEXT
  52.  
  53. FUNCTION Plasma~& ()
  54.     pN = pN + .1 'dim shared cN as Double, pR as integer, pG as integer, pB as integer
  55.     Plasma~& = _RGB32(127 + 127 * SIN(pR * pN), 127 + 127 * SIN(pG * pN), 127 + 127 * SIN(pB * pN))
  56.  
  57. SUB resetPlasma ()
  58.     pR = RND ^ 2: pG = RND ^ 2: pB = RND ^ 2
  59.  
  60.  
« Last Edit: August 26, 2020, 09:04:20 pm by bplus »