Author Topic: Rotating Spiral Words  (Read 3421 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Rotating Spiral Words
« on: November 28, 2020, 02:15:45 am »
This shows words written in a spiral and then it all rotates. I got the spiral code about a year ago somewhere online. It's the same code I used in my Fun With Math program last year. Tonight I finally decided to see if I could write words with it, so I came up with this little thing. Others have probably made it in the past, in fact it looks vaguely familiar from maybe last year, but I'm glad I figured it all out myself using the RotoZoom Sub. It will be hard to read, but maybe if you look at it long enough you can read it. If not, just look at the code on the words$ on the top line. This string can be changed to anything else as long as it's not too long. Feel free to mess around with it. :)

Code: QB64: [Select]
  1. words$ = "ABCDEFGHIJKLMNOPQRSTUVQXYZ.....1234567890....HELLO..EVERYONE!...I HOPE YOU CAN READ THIS...I MADE THIS LITTLE PROGRAM IN ABOUT 1 HOUR USING QB64 PROGRAMMING LANGUAGE. TELL ME WHAT YOU THINK, THANKS!"
  2. letters = LEN(words$)
  3. DIM lett$(500)
  4. DIM spiralwords AS LONG
  5. spiral& = _NEWIMAGE(800, 600, 32)
  6. SCREEN spiral&
  7. FOR l = 1 TO letters
  8.     lett$(l) = MID$(words$, l, 1)
  9.  
  10. FOR d = 300 TO 1 STEP -.125
  11.     s = s + 1
  12.     IF s / 4 + (s / 20) = INT(s / 4 + (s / 20)) THEN ll = ll + 1
  13.     x = COS(s * -3.141592 / 180) * d
  14.     y = SIN(s * -3.141592 / 180) * d
  15.     IF s / 4 + (s / 20) <> INT(s / 4 + (s / 20)) THEN GOTO skip:
  16.     IF lett$(ll) = "" THEN GOTO skip:
  17.     _PRINTSTRING (x + 400, y + 300), lett$(ll)
  18.     skip:
  19.     _DELAY .001
  20. spiralwords = _COPYIMAGE(0)
  21.  
  22.     angle = angle + 1
  23.     IF angle > 359 THEN angle = 0
  24.     RotoZoom 400, 300, spiralwords, 1, angle
  25.     _DELAY .05
  26.     _DISPLAY
  27.     CLS
  28.  
  29. SUB RotoZoom (X AS LONG, Y AS LONG, hdl AS LONG, Scale AS SINGLE, Rotation AS SINGLE)
  30.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  31.     W& = _WIDTH(hdl&): h& = _HEIGHT(hdl&)
  32.     px(0) = -W& / 2: py(0) = -h& / 2: px(1) = -W& / 2: py(1) = h& / 2
  33.     px(2) = W& / 2: py(2) = h& / 2: px(3) = W& / 2: py(3) = -h& / 2
  34.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  35.     FOR I& = 0 TO 3
  36.         x2& = (px(I&) * cosr! + sinr! * py(I&)) * Scale + X: y2& = (py(I&) * cosr! - px(I&) * sinr!) * Scale + Y
  37.         px(I&) = x2&: py(I&) = y2&
  38.     NEXT
  39.     _MAPTRIANGLE (0, 0)-(0, h& - 1)-(W& - 1, h& - 1), hdl& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  40.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, h& - 1), hdl& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  41.  

« Last Edit: November 28, 2020, 02:20:34 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rotating Spiral Words
« Reply #1 on: November 28, 2020, 03:20:33 am »
@SierraKen  It's cool seeing you progress and fun!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Rotating Spiral Words
« Reply #2 on: November 28, 2020, 04:06:46 pm »
Thanks B+! I don't think I will ever break from programming in BASIC. :)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Rotating Spiral Words
« Reply #3 on: November 29, 2020, 05:29:17 pm »
This is SO cool... Trying to read and focus on the letters as they spiral inward was a challenge.. for me anyway... Can you imagine if George Lucas decided to apply this method to his Star Wars (my apologies for the crude language... I don't normally use the 'S..W..." words) movie intros? lol

Nicely done!!
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Rotating Spiral Words
« Reply #4 on: November 29, 2020, 10:23:41 pm »
LOLOL Thanks Johnno! :)))

Offline Bolee

  • Newbie
  • Posts: 4
    • View Profile
Re: Rotating Spiral Words
« Reply #5 on: February 17, 2021, 05:20:23 am »
There was something on the Freebasic site to do with a ULAM Spiral. Maybe this could be applied to words like your program.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rotating Spiral Words
« Reply #6 on: February 17, 2021, 12:21:36 pm »
There was something on the Freebasic site to do with a ULAM Spiral. Maybe this could be applied to words like your program.

Ulam Spirals ugly as sin, try this one from Ashish Kingdom!
Code: QB64: [Select]
  1. 'Coded By Ashish in QB64
  2. _Title "IFS Spiral"
  3.  
  4. Screen _NewImage(800, 600, 32)
  5.  
  6. Dim Shared gx, gy
  7. Color _RGBA(255, 255, 255, 10)
  8. drawSpiral _Width * .75, _Height * .25, 1
  9.  
  10. For i = 0 To 100
  11.     vx = gx
  12.     vy = gy
  13.     drawSpiral vx, vy, 1
  14.  
  15.  
  16. Sub drawSpiral (x!, y!, N~&)
  17.     Select Case Rnd(1)
  18.         Case 0 TO 0.05
  19.             xx! = -0.121212 * x! + 0.257576 * y! - 6.721654
  20.             yy! = 0.151515 * x! + 0.053030 * y! + 1.377236
  21.         Case 0.05 TO 0.10
  22.             xx! = 0.181818 * x! - 0.136364 * y! + 6.086107
  23.             yy! = 0.090909 * x! + 0.181818 * y! + 1.568035
  24.         Case Else
  25.             xx! = 0.787879 * x! - 0.424242 * y! + 1.758647
  26.             yy! = 0.242424 * x! + 0.859848 * y! + 1.408065
  27.     End Select
  28.     PSet (xx! * 60 + _Width * .5, yy! * 60)
  29.     If N~& < 10000 Then
  30.         drawSpiral xx!, yy!, N~& + 1
  31.     Else
  32.         gx = xx!
  33.         gy = yy!
  34.     End If
  35.  
  36.  
  37.  

BTW Sin used to mean the gap between living a healthy moral life and not with the threat of going to hell implied but not damned. So Ulams spiral is gapped.
« Last Edit: February 17, 2021, 12:25:31 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rotating Spiral Words
« Reply #7 on: February 17, 2021, 12:31:12 pm »
Or how about rotating spiral polygon fills:

Code: QB64: [Select]
  1. _Title "Polygon Demo by bplus"
  2. ' polygon demo.bas for QB64 (B+=MGA) 2017-09-17
  3. Const xmax = 700
  4. Const ymax = 700
  5.  
  6. Screen _NewImage(xmax, ymax, 32)
  7. _Delay .25
  8.  
  9. x0 = xmax / 2: y0 = ymax / 2
  10. For n = 3 To 9
  11.     radius = 345
  12.     Cls
  13.     rr = Rnd * 75: gg = Rnd * 75: bb = Rnd * 75
  14.     For a = 0 To _Pi(2) Step _Pi(1 / 20)
  15.         radius = radius - 8
  16.         pc& = _RGB(radius / 345 * 200 + rr, radius / 345 * 200 + gg, radius / 345 * 200 + bb)
  17.         Color pc&
  18.         polygon x0, y0, radius, n, a
  19.         Paint (x0, y0), pc&, pc&
  20.         _Limit 10
  21.     Next
  22.     Sleep 2
  23.  
  24. Sub polygon (xOrigin, yOrigin, radius, nVertex, RadianAngleOffset)
  25.     polyAngle = _Pi(2) / nVertex
  26.     x1 = xOrigin + radius * Cos(polyAngle + RadianAngleOffset)
  27.     y1 = yOrigin + radius * Sin(polyAngle + RadianAngleOffset)
  28.     For i = 2 To nVertex + 1
  29.         x2 = xOrigin + radius * Cos(i * polyAngle + RadianAngleOffset)
  30.         y2 = yOrigin + radius * Sin(i * polyAngle + RadianAngleOffset)
  31.         Line (x1, y1)-(x2, y2)
  32.         x1 = x2: y1 = y2
  33.     Next
  34.  
  35.  

Welcome to this Forum @Bolee
« Last Edit: February 17, 2021, 12:34:45 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Rotating Spiral Words
« Reply #8 on: February 17, 2021, 03:09:18 pm »
Yes, it does remind me of Star Wars... After watching the movie, the swirling effect mimics the water in the bowl, flushing the vomit into a  facility far far away.

Okay, cool effect, but if you really want to impress me, add highlighting with cut and paste!

Pete
« Last Edit: February 17, 2021, 03:10:48 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/