Author Topic: Rotating Flower  (Read 5096 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Rotating Flower
« on: March 21, 2022, 08:00:51 pm »
Many of you have probably seen this before and have made it before. But without looking at any of your code, except for the Wiki pages, I decided to try it myself. This flower has 3 layers and the pedals keep going around and around because there is no way to stop it and look right that I can figure out. It's because the last pedal is placed on top of both the left and the right (the first) pedal and won't go underneath the first pedal. There might be a way around this using advanced math or maybe even using the POINT command, but since I'm using the ROTOZOOM Sub that I found in the Wiki pages, this is as good as I can get. Check it out. :) Oh by the way, something tells me that there was a RotoZoom command, without having to use the Sub, but I couldn't find it in the Wiki. I'll place a photo of this flower below.

Code: QB64: [Select]
  1. _Title "Ken's Rotating Flower"
  2. Dim image As Long
  3. Screen _NewImage(800, 600, 32)
  4.  
  5. For tt = 0 To _Pi Step .2
  6.     For t = 1 To 20 Step .1
  7.         Circle (400 + t, 150 + tt), 100, _RGB32(255, 0, 0), _Pi, ((3 * _Pi) / 2)
  8.         Circle (298 + t, 250 + tt), 100, _RGB32(255, 0, 0), (2 * _Pi), (_Pi / 2)
  9.     Next t
  10. Next tt
  11. Paint (350, 200), _RGB32(255, 255, 128), _RGB32(255, 0, 0)
  12.  
  13. image& = _CopyImage(0)
  14. 'sky
  15. Paint (1, 1), _RGB32(128, 255, 255)
  16. zoom = 1.5
  17. zoom2 = .5
  18. zoom3 = .2
  19.     _Limit 20
  20.     RotoZoom 400, 300, image&, zoom, angle
  21.     RotoZoom 400, 300, image&, zoom2, angle
  22.     RotoZoom 400, 300, image&, zoom3, angle
  23.     _Display
  24.     angle = angle + 20
  25.     If angle >= 360 Then Paint (400, 300), _RGB32(255, 255, 128), _RGB32(255, 0, 0): angle = 0
  26.     _Delay .1
  27.  
  28.  
  29. Sub RotoZoom (X As Long, Y As Long, image&, Scale As Single, Rotation As Single)
  30.     Dim px(3) As Single: Dim py(3) As Single
  31.     W& = _Width(image&): H& = _Height(image&)
  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), image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  40.     _MapTriangle (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  41.  
Ken's Rotating Flower.jpg
* Ken's Rotating Flower.jpg (Filesize: 150.43 KB, Dimensions: 800x623, Views: 163)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rotating Flower
« Reply #1 on: March 21, 2022, 08:35:07 pm »
A little mod
Code: QB64: [Select]
  1. _Title "Ken's Rotating Flower"
  2. Dim image As Long
  3. Screen _NewImage(800, 600, 32)
  4.  
  5. For tt = 0 To _Pi Step .2
  6.     For t = 1 To 20 Step .1
  7.         Circle (400 + t, 150 + tt), 100, _RGB32(255, 0, 0), _Pi, ((3 * _Pi) / 2)
  8.         Circle (298 + t, 250 + tt), 100, _RGB32(255, 0, 0), (2 * _Pi), (_Pi / 2)
  9.     Next t
  10. Next tt
  11. Paint (350, 200), _RGB32(255, 255, 128), _RGB32(255, 0, 0)
  12.  
  13. image& = _CopyImage(0)
  14. 'sky
  15. Paint (1, 1), _RGB32(128, 255, 255)
  16. zoom = 1.5
  17. zoom2 = .5
  18. zoom3 = .2
  19. m = .99
  20.     _Limit 20
  21.     RotoZoom 400, 300, image&, zoom, angle + bump
  22.     RotoZoom 400, 300, image&, zoom2, angle + bump
  23.     RotoZoom 400, 300, image&, zoom3, angle + bump
  24.     zoom = zoom * m
  25.     zoom2 = zoom2 * m
  26.     zoom3 = zoom3 * m
  27.     If zoom < .1 Then m = 1.02: bump = Rnd * .1
  28.     If zoom > 1.7 Then m = .98: bump = Rnd * .1
  29.     _Display
  30.     angle = angle + 20
  31.     If angle >= 360 Then Paint (400, 300), _RGB32(255, 255, 128), _RGB32(255, 0, 0): angle = 0
  32.     _Delay .1
  33.  
  34.  
  35. Sub RotoZoom (X As Long, Y As Long, image&, Scale As Single, Rotation As Single)
  36.     Dim px(3) As Single: Dim py(3) As Single
  37.     W& = _Width(image&): H& = _Height(image&)
  38.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  39.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  40.     sinr! = Sin(-Rotation / 57.2957795131): cosr! = Cos(-Rotation / 57.2957795131)
  41.     For i& = 0 To 3
  42.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  43.         px(i&) = x2&: py(i&) = y2&
  44.     Next
  45.     _MapTriangle (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  46.     _MapTriangle (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  47.  
  48.  
  49.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Rotating Flower
« Reply #2 on: March 21, 2022, 09:10:18 pm »
Thanks B+ :). I took your idea and modded it a tiny bit by making the app finish when it gets super small so nobody can see the overlap problem. Thanks! People know when it's finished when the title bar says "Press Esc to quit."

Code: QB64: [Select]
  1. 'Thanks to B+ for the mod idea and the rest of the QB64 forum gang for this idea in the past.
  2. 'Made on March 21, 2022 by SierraKen with a small mod by B+.
  3.  
  4. _Title "Rotating Flower"
  5. Dim image As Long
  6. Screen _NewImage(800, 600, 32)
  7.  
  8. For tt = 0 To _Pi Step .2
  9.     For t = 1 To 20 Step .1
  10.         Circle (400 + t, 150 + tt), 100, _RGB32(255, 0, 0), _Pi, ((3 * _Pi) / 2)
  11.         Circle (298 + t, 250 + tt), 100, _RGB32(255, 0, 0), (2 * _Pi), (_Pi / 2)
  12.     Next t
  13. Next tt
  14. Paint (350, 200), _RGB32(255, 255, 128), _RGB32(255, 0, 0)
  15.  
  16. image& = _CopyImage(0)
  17. 'sky
  18. Paint (1, 1), _RGB32(128, 255, 255)
  19. zoom = 1.5
  20. zoom2 = .5
  21. zoom3 = .2
  22. m = .99
  23.     _Limit 20
  24.     RotoZoom 400, 300, image&, zoom, angle + bump
  25.     RotoZoom 400, 300, image&, zoom2, angle + bump
  26.     RotoZoom 400, 300, image&, zoom3, angle + bump
  27.     zoom = zoom * m
  28.     zoom2 = zoom2 * m
  29.     zoom3 = zoom3 * m
  30.     'If zoom < .1 Then m = 1.02: bump = Rnd * .1
  31.     If zoom < .05 Then
  32.         _Title "Press Esc to quit."
  33.         Do: Loop Until InKey$ = Chr$(27)
  34.         _Title "Rotating Flower"
  35.         End
  36.     End If
  37.     If zoom > 1.7 Then m = .98: bump = Rnd * .1
  38.     _Display
  39.     angle = angle + 20
  40.     If angle >= 360 Then Paint (400, 300), _RGB32(255, 255, 128), _RGB32(255, 0, 0): angle = 0
  41.     _Delay .1
  42.  
  43.  
  44. Sub RotoZoom (X As Long, Y As Long, image&, Scale As Single, Rotation As Single)
  45.     Dim px(3) As Single: Dim py(3) As Single
  46.     W& = _Width(image&): H& = _Height(image&)
  47.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  48.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  49.     sinr! = Sin(-Rotation / 57.2957795131): cosr! = Cos(-Rotation / 57.2957795131)
  50.     For i& = 0 To 3
  51.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  52.         px(i&) = x2&: py(i&) = y2&
  53.     Next
  54.     _MapTriangle (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  55.     _MapTriangle (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  56.  
Ken's Rotating Flower With Mod.jpg
* Ken's Rotating Flower With Mod.jpg (Filesize: 163.36 KB, Dimensions: 799x625, Views: 180)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rotating Flower
« Reply #3 on: March 22, 2022, 11:12:39 am »
Need to offset those pedals some way.

Code: QB64: [Select]
  1. _Title "b+ Makeover of Ken's Rotating Flower"
  2. Dim image As Long
  3. Screen _NewImage(700, 700, 32)
  4. _ScreenMove 250, 20
  5. For r = 50 To 60 Step .25
  6.     Circle (350, 350), r, _RGB32(100, 0, 0), , , .5  'ovals half width for height
  7. Paint (350, 350), _RGB32(200, 0, 40), _RGB32(100, 0, 0)
  8. image = _CopyImage(0)
  9. Print " Here is one petal, press any to continue..."
  10.  
  11. Color , _RGB32(128, 255, 255) ' Ken's sky color, nice
  12. For r = 20 To 0 Step -.25 ' draw a yellow center
  13.     Circle (350, 350), r, &HFFFFFF00
  14. r = 250: zoom = 1
  15. Do ' each loop draws a ring of petals around the center starting on outside
  16.     For a = start To _Pi(2) - .00001 Step _Pi(2 / 30) ' a goes around a circle from 0 to 2*pi = 360 degrees
  17.         x = 350 + r * Cos(a): y = 350 + r * Sin(a) ' here is x, y coordinate for petal center
  18.         angle = _Atan2(350 - y, 350 - x) ' here is the angle of the petal to the center of screen
  19.         RotoZoom x, y, image, zoom, _R2D(angle) ' draw petal centered at x, y, scaled at zoom level, convert angle radians to degrees for rotozoom
  20.         _Display
  21.         _Delay .1
  22.     Next
  23.     zoom = zoom * .75 ' decrease petal scale by 75%
  24.     r = r * .75 '  'next ring of petals decrease radius by 75%
  25.     If r < 20 Then Exit Do ' r is too small we are done!
  26.     toggle = 1 - toggle ' this alters petals so they are offset each time around
  27.     If toggle Then start = -_Pi(1 / 30) Else start = 0 ' offset by half the angle "a" step size
  28.  
  29.  
  30. Sub RotoZoom (X As Long, Y As Long, image&, Scale As Single, Rotation As Single)
  31.     Dim px(3) As Single: Dim py(3) As Single
  32.     W& = _Width(image&): H& = _Height(image&)
  33.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  34.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  35.     sinr! = Sin(-Rotation / 57.2957795131): cosr! = Cos(-Rotation / 57.2957795131)
  36.     For i& = 0 To 3
  37.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  38.         px(i&) = x2&: py(i&) = y2&
  39.     Next
  40.     _MapTriangle (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  41.     _MapTriangle (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  42.  
  43.  

 
b+ makeover Kens Flower.PNG
« Last Edit: March 22, 2022, 12:54:11 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Rotating Flower
« Reply #4 on: March 22, 2022, 01:54:45 pm »
Here is one I just threw together to make it look better. B+ yours is incredible. I wouldn't have known to make it like that.

Code: QB64: [Select]
  1. 'Thanks to B+ for the mod idea and the rest of the QB64 forum gang for this idea in the past.
  2. 'Made on March 21, 2022 by SierraKen with a small mod by B+.
  3.  
  4. _Title "Rotating Flower"
  5. Dim image As Long
  6. Screen _NewImage(800, 600, 32)
  7. co = 150
  8. co2 = 255
  9. For tt = 0 To _Pi Step .2
  10.     For t = -30 To 30 Step .1
  11.         co = co + .25
  12.         co2 = co2 - .25
  13.         If co2 < 150 Then co2 = 255
  14.         If co > 255 Then co = 150
  15.         Circle (400 + t, 150 + tt), 100, _RGB32(co, 0, 0), _Pi, ((3 * _Pi) / 2)
  16.         Circle (298 + t, 250 + tt), 100, _RGB32(co2, 0, 0), (2 * _Pi), (_Pi / 2)
  17.     Next t
  18. Next tt
  19.  
  20. image& = _CopyImage(0)
  21. 'sky
  22. For yy = 0 To 600
  23.     cl = cl + .5
  24.     Line (0, yy)-(800, yy), _RGB32(128, cl, cl)
  25. Next yy
  26. zoom = 1.5
  27. zoom2 = .5
  28. zoom3 = .2
  29. m = .99
  30.     _Limit 20
  31.     RotoZoom 400, 300, image&, zoom, angle + bump
  32.     RotoZoom 400, 300, image&, zoom2, angle + bump
  33.     RotoZoom 400, 300, image&, zoom3, angle + bump
  34.     zoom = zoom * m
  35.     zoom2 = zoom2 * m
  36.     zoom3 = zoom3 * m
  37.     'If zoom < .1 Then m = 1.02: bump = Rnd * .1
  38.     If zoom < .5 Then
  39.         For sz = .1 To 5 Step .1
  40.             Circle (400, 300), sz, _RGB32(255, 255, 127)
  41.         Next sz
  42.         _Display
  43.         Sleep
  44.         End
  45.     End If
  46.     _Title "Press Esc to quit."
  47.     If zoom > 1.7 Then m = .98: bump = Rnd * .1
  48.     _Display
  49.     angle = angle + 20
  50.     If angle >= 360 Then angle = 0
  51.     _Delay .1
  52.  
Ken's Rotating Flower With Mod 2.jpg
* Ken's Rotating Flower With Mod 2.jpg (Filesize: 120.66 KB, Dimensions: 798x625, Views: 181)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Rotating Flower
« Reply #5 on: March 22, 2022, 02:56:14 pm »
Code: QB64: [Select]
  1. _Title "b+ Makeover #2 of Ken's Rotating Flower"
  2. Dim image As Long
  3. Screen _NewImage(700, 700, 32)
  4. _ScreenMove 250, 20
  5. For r = 0 To 60 Step .25
  6.     Circle (350, 350), r, _RGB32(255 - r * 4, 0, 0), , , .5 'ovals half width for height
  7. image = _CopyImage(0)
  8. Print " Here is one petal, press any to continue..."
  9. For i = 0 To 700
  10.     Line (0, i)-(700, i), _RGB32(0, 160, 255 - i / 700 * 255)
  11. For r = 20 To 0 Step -.25 ' draw a yellow center
  12.     Circle (350, 350), r, &HFFFFFF00
  13. r = 250: zoom = 1
  14. Do ' each loop draws a ring of petals around the center starting on outside
  15.     For a = start To _Pi(2) - .00001 Step _Pi(2 / 30) ' a goes around a circle from 0 to 2*pi = 360 degrees
  16.         x = 350 + r * Cos(a): y = 350 + r * Sin(a) ' here is x, y coordinate for petal center
  17.         angle = _Atan2(350 - y, 350 - x) ' here is the angle of the petal to the center of screen
  18.         RotoZoom x, y, image, zoom, _R2D(angle) ' draw petal centered at x, y, scaled at zoom level, convert angle radians to degrees for rotozoom
  19.         _Display
  20.         _Delay .1
  21.     Next
  22.     zoom = zoom * .75 ' decrease petal scale by 75%
  23.     r = r * .75 '  'next ring of petals decrease radius by 75%
  24.     If r < 20 Then Exit Do ' r is too small we are done!
  25.     toggle = 1 - toggle ' this alters petals so they are offset each time around
  26.     If toggle Then start = -_Pi(1 / 30) Else start = 0 ' offset by half the angle "a" step size
  27.  
  28. Sub RotoZoom (X As Long, Y As Long, image&, Scale As Single, Rotation As Single)
  29.     Dim px(3) As Single: Dim py(3) As Single
  30.     W& = _Width(image&): H& = _Height(image&)
  31.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  32.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  33.     sinr! = Sin(-Rotation / 57.2957795131): cosr! = Cos(-Rotation / 57.2957795131)
  34.     For i& = 0 To 3
  35.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  36.         px(i&) = x2&: py(i&) = y2&
  37.     Next
  38.     _MapTriangle (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  39.     _MapTriangle (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  40.  

 
image_2022-03-22_145606.png

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Rotating Flower
« Reply #6 on: March 22, 2022, 04:05:11 pm »
Awesome piece of artwork B+.