QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on August 03, 2020, 04:34:34 pm

Title: Slinky Animated Sequence
Post by: SierraKen on August 03, 2020, 04:34:34 pm
Using the same math equations as my random curly hair program, I decided to make a Slinky.
It's non-stop and when it reaches the end of the screen, about 2 seconds later it starts over again.

Code: QB64: [Select]
  1. 'Slinky Animated Sequence - by SierraKen
  2. 'August 3, 2020
  3.  
  4. SCREEN _NEWIMAGE(1000, 600, 32)
  5. h = 2: h2 = -.04: fuzzy = 150
  6. c1 = 255: c2 = 255: c3 = 169
  7. t = -400
  8.     FOR tt = 1 TO 2
  9.         FOR a = 1 TO 650 STEP 20
  10.             _LIMIT 300
  11.             seconds = seconds + 1
  12.             sec = (60 - seconds) * 6 + 280
  13.             xx = INT(SIN(sec / 180 * 3.141592) * 180) + 400
  14.             yy = INT(COS(sec / 180 * 3.141592) * 180) + 300
  15.             s = sec
  16.             FOR d = 55 TO 35 STEP h2
  17.                 s = s + h
  18.                 x = COS(s * 3.141592 / fuzzy) * d
  19.                 y = SIN(s * 3.141592 / fuzzy) * d
  20.                 x2 = x + xx: y2 = y + yy
  21.                 x3 = x2 + t
  22.                 IF tt = 2 AND a > 600 THEN GOTO again:
  23.                 FOR sz = .25 TO 1 STEP .25
  24.                     CIRCLE (x3, y2 + 50 + h - (h2 * 10)), sz, _RGB32(c1, c2, c3)
  25.                 NEXT sz
  26.             NEXT d
  27.             _DELAY .05
  28.         NEXT a
  29.         _DELAY .02
  30.         seconds = 0
  31.         c1 = 0: c2 = 0: c3 = 0
  32.     NEXT tt
  33.     again:
  34.     seconds = 0
  35.     CLS
  36.     c1 = 255: c2 = 255: c3 = 169
  37.     t = t + 355
  38.     IF t > 800 THEN t = -400
  39.  
Title: Re: Slinky Animated Sequence
Post by: Dav on August 03, 2020, 05:04:55 pm
Lol.  Cool.  You come up with some interesting things, @SierraKen

- Dav
Title: Re: Slinky Animated Sequence
Post by: johnno56 on August 03, 2020, 06:40:53 pm
Does it come in blue? lol

Nicely done! Will version #2 include a set of stairs?
Title: Re: Slinky Animated Sequence
Post by: SierraKen on August 03, 2020, 08:33:11 pm
LOL Thanks guys. :) You can make it any color you want, it only has one CIRCLE command. :)  c1, c2, and c3 are the colors.
Title: Re: Slinky Animated Sequence
Post by: FellippeHeitor on August 03, 2020, 08:50:50 pm
That was fun, Ken!
Title: Re: Slinky Animated Sequence
Post by: OldMoses on August 03, 2020, 10:02:11 pm
I messed around with random colors for it.

Changing line 37:
Code: QB64: [Select]
  1.  c1 = 255: c2 = 255: c3 = 169

to:
Code: QB64: [Select]
  1. c1 = ByteRan: c2 = ByteRan: c3 = ByteRan

and adding the following function:
Code: QB64: [Select]
  1. FUNCTION ByteRan
  2.  
  3.     ByteRan = INT(256 * RND(1))
  4.  
  5. END FUNCTION 'ByteRan
  6.  

After seeing the effect that had, I got to really parsing out some of what your code was doing, and I'm kind of amazed at how it was done. Nice work.
Title: Re: Slinky Animated Sequence
Post by: Richard Frost on August 03, 2020, 10:58:26 pm
Now you could do the Ren & Stimpy toy, the log.

"What rolls down stairs, alone or in pairs, runs over your neighbor's dog, it's log log log."
Title: Re: Slinky Animated Sequence
Post by: SierraKen on August 03, 2020, 11:03:24 pm
Thanks guys :)).

LOL Richard, been ages since I seen that show. :)
Title: Re: Slinky Animated Sequence
Post by: SierraKen on August 03, 2020, 11:07:19 pm
OldMoses, to be honest, I really don't know how the SIN and COS equations work exactly. It is code I got a year ago for spirals and circles and I just put them together. Spirals going in half-circles. :)
Title: Re: Slinky Animated Sequence
Post by: OldMoses on August 04, 2020, 04:10:22 am
OldMoses, to be honest, I really don't know how the SIN and COS equations work exactly. It is code I got a year ago for spirals and circles and I just put them together. Spirals going in half-circles. :)

I have the same problem. Been using trig for years and still don't quite "get it". It's like driving a car, you can do it without understanding how it works, but if it breaks down, you at a disadvantage to fix it.
Title: Re: Slinky Animated Sequence
Post by: loudar on August 04, 2020, 06:02:08 am
Just out of curiosity, why not use _PI instead of 3.141592 (and 3.151492, but that's either a typo or an easteregg)? :D
Title: Re: Slinky Animated Sequence
Post by: bplus on August 04, 2020, 11:33:54 am
Just out of curiosity, why not use _PI instead of 3.141592 (and 3.151492, but that's either a typo or an easteregg)? :D

_PI is a function, number literals are faster, faster than even a constant? I sure hate to have to measure the difference!
It may be all the same after compiled.

He may or may not know he is converting to Radians for SIN and COS and wouldn't need the _PI/180, could use _D2R same thing.

SIN and COS are ratio's unique to the Angle argument of the function, so it is important to understand QB64 SIN and COS are expecting Radian Angle arguments.
Title: Re: Slinky Animated Sequence
Post by: SierraKen on August 04, 2020, 03:36:37 pm
Thanks B+, but actually, I  was just lazy and didn't even think about using anything else besides the code I found a year ago. lol
But thanks Loudar for showing me the Pi error, I didn't even notice it, I just fixed it in the code above.
Title: Re: Slinky Animated Sequence
Post by: _vince on August 06, 2020, 07:50:13 am
Can't go wrong with
Code: [Select]
dim shared pi as double
pi = 4*atn(1)

Works with QB64, freebasic, and QB. I am opposed to _PI and _D2R in principle and avoid using them. I do approve of _ATAN2, _ASIN, and _ACOS on the other hand.

Anyways, nice work @SierraKen. Now let's make it crawl down a set of stairs like the real ones!
Title: Re: Slinky Animated Sequence
Post by: SMcNeill on August 06, 2020, 08:11:15 am
Can't go wrong with
Code: [Select]
dim shared pi as double
pi = 4*atn(1)

Works with QB64, freebasic, and QB. I am opposed to _PI and _D2R in principle and avoid using them. I do approve of _ATAN2, _ASIN, and _ACOS on the other hand.

Anyways, nice work @SierraKen. Now let's make it crawl down a set of stairs like the real ones!

Why use a formula at all?  Why not just

CONST PI## = 3.141592654(to whatever degree of precision is desired)
Title: Re: Slinky Animated Sequence
Post by: _vince on August 06, 2020, 09:24:06 am
Why use a formula at all?
- easier to remember and looks cleaner
- the formula should maximize precision to the particular data type, though it could be that ATN may still have some error deep in the decimal places
Title: Re: Slinky Animated Sequence
Post by: SierraKen on August 06, 2020, 09:47:50 pm
Thanks Vince. I don't know if I will make more mods of the Slinky or not. Anyone else is free to do it though. :)