Author Topic: Slinky Animated Sequence  (Read 5867 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Slinky Animated Sequence
« 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.  
« Last Edit: August 04, 2020, 03:38:05 pm by SierraKen »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Slinky Animated Sequence
« Reply #1 on: August 03, 2020, 05:04:55 pm »
Lol.  Cool.  You come up with some interesting things, @SierraKen

- Dav

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Slinky Animated Sequence
« Reply #2 on: August 03, 2020, 06:40:53 pm »
Does it come in blue? lol

Nicely done! Will version #2 include a set of stairs?
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Slinky Animated Sequence
« Reply #3 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.

FellippeHeitor

  • Guest
Re: Slinky Animated Sequence
« Reply #4 on: August 03, 2020, 08:50:50 pm »
That was fun, Ken!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Slinky Animated Sequence
« Reply #5 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.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Slinky Animated Sequence
« Reply #6 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."
It works better if you plug it in.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Slinky Animated Sequence
« Reply #7 on: August 03, 2020, 11:03:24 pm »
Thanks guys :)).

LOL Richard, been ages since I seen that show. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Slinky Animated Sequence
« Reply #8 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. :)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Slinky Animated Sequence
« Reply #9 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.

Offline loudar

  • Newbie
  • Posts: 73
  • improve it bit by bit.
    • View Profile
Re: Slinky Animated Sequence
« Reply #10 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
Check out what I do besides coding: http://loudar.myportfolio.com/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Slinky Animated Sequence
« Reply #11 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.
« Last Edit: August 04, 2020, 11:41:08 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Slinky Animated Sequence
« Reply #12 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.
« Last Edit: August 04, 2020, 03:38:46 pm by SierraKen »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Slinky Animated Sequence
« Reply #13 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!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Slinky Animated Sequence
« Reply #14 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)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!