Author Topic: Pattern Challenge By Ashish : #1  (Read 1438 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Pattern Challenge By Ashish : #1
« on: July 08, 2019, 01:43:45 am »
Hi everyone!
I created a pattern and let me see who is the first to reproduce it! :D

Please see the attachment for the pattern.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Pattern Challenge By Ashish : #1
« Reply #1 on: July 08, 2019, 03:39:54 am »
That looks like an iris.

Iris everyone good luck trying to reproduce it!

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pattern Challenge By Ashish : #1
« Reply #2 on: July 09, 2019, 05:33:49 pm »
Hi Ashish,

I accept your challenge:
Code: QB64: [Select]
  1. _TITLE "I See Ashish Challenge #1 Takes Us On A Tangent" 'bplus 2019-07-09
  2. CONST xmax = 740, ymax = 740, xc = xmax / 2, yc = ymax / 2, br = 370
  3. TYPE tData
  4.     n AS INTEGER 'n points
  5.     r AS SINGLE 'inner radius
  6.     osStart AS SINGLE
  7.     osStop AS SINGLE
  8.     osStep AS SINGLE
  9.     c AS _UNSIGNED LONG
  10.  
  11. DIM t(10) AS tData
  12. t(0).n = 150: t(0).r = .08 * br: t(0).c = &H5522AAEE
  13. t(1).n = 220: t(1).r = .095 * br: t(1).c = &H3344DD55
  14. t(2).n = 350: t(2).r = .14 * br: t(2).c = &H2222FFAA
  15. t(3).n = 16: t(3).r = .35 * br: t(3).c = &H19AAFFFF: t(3).osStart = _PI / 72: t(3).osStop = _PI(3 / 72): t(3).osStep = _PI / 360
  16. t(4).n = 199: t(4).r = .53 * br: t(4).c = &H22008800
  17. t(5).n = 200: t(5).r = .67 * br: t(5).c = &H220000FF
  18. t(6).n = 300: t(6).r = .81 * br: t(6).c = &H220000FF
  19. t(10).n = 27: t(10).r = .88 * br: t(10).c = &H28FFFF77: t(10).osStart = .15: t(10).osStop = .16: t(10).osStep = _PI(1 / 1440)
  20. t(7).n = 350: t(7).r = .9 * br: t(7).c = &H2244FF44
  21. t(8).n = 350: t(8).r = .93 * br: t(8).c = &H226666FF
  22. t(9).n = 350: t(9).r = .95 * br: t(9).c = &H228888FF
  23.  
  24. SCREEN _NEWIMAGE(xmax, ymax, 32)
  25. DIM tSet AS INTEGER, ao
  26. FOR tSet = 0 TO 10
  27.     IF t(tSet).osStep THEN
  28.         FOR ao = t(tSet).osStart TO t(tSet).osStop STEP t(tSet).osStep
  29.             tangentsC1C2 xc, yc, t(tSet).r, br, t(tSet).n, ao, t(tSet).c
  30.         NEXT
  31.     ELSE
  32.         tangentsC1C2 xc, yc, t(tSet).r, br, t(tSet).n, 0, t(tSet).c
  33.     END IF
  34.  
  35. SUB tangentsC1C2 (x, y, rInner, rOuter, nAround, raOffset, c AS _UNSIGNED LONG)
  36.     ' x, y are same as for circle,
  37.     ' rOuter is the outer limit radius
  38.     ' nAround to evenly distribute lines around the circle
  39.     ' radAngleOffset to start lines at different places on circle
  40.     DIM alpha, beta, cosLength, tAngle, x1, y1, x2, y2, x3, y3, i AS INTEGER
  41.  
  42.     'calc the length from rInner to Router at Tangent
  43.     alpha = _ACOS(rInner / rOuter)
  44.     beta = _PI(1 / 2) - alpha
  45.     cosLength = rOuter * COS(beta)
  46.     tAngle = _PI(2) / nAround
  47.     FOR i = 1 TO nAround
  48.         x1 = x + rInner * COS(i * tAngle + raOffset)
  49.         y1 = y + rInner * SIN(i * tAngle + raOffset)
  50.         x2 = x1 + cosLength * COS(i * tAngle + raOffset + _PI / 2)
  51.         y2 = y1 + cosLength * SIN(i * tAngle + raOffset + _PI / 2)
  52.         x3 = x1 + cosLength * COS(i * tAngle + raOffset + _PI(3 / 2))
  53.         y3 = y1 + cosLength * SIN(i * tAngle + raOffset + _PI(3 / 2))
  54.         LINE (x2, y2)-(x3, y3), c
  55.     NEXT
  56.  


Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Pattern Challenge By Ashish : #1
« Reply #3 on: July 09, 2019, 06:54:45 pm »
Nice!

I put a _DELAY .01 in the FOR/NEXT loop. It makes it look like a youtube vid of a Spirotot. Unfortunately, that original toddler version is no where to be found.

Put the ring in the square
And the pen in the slot
Go round, round, round
With Spirotot

Make a round round ball
And that's not all
You can draw a lot
With Spirotot

Well, at age 6, I wasn't impressed. I think I changed the lyrics to... You can't draw squat with Spirotot, but I digress.

Anyway, a better version, called Spirograph, is still on the market:


I beginning to think learning C is taking a toll...

Pete

I had a geometry once, but I chopped it down.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pattern Challenge By Ashish : #1
« Reply #4 on: July 10, 2019, 09:04:10 am »
:) The _delay is nice aspect thanks Pete.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: Pattern Challenge By Ashish : #1
« Reply #5 on: July 11, 2019, 02:39:52 am »
Perfect Bplus!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Pattern Challenge By Ashish : #1
« Reply #6 on: July 12, 2019, 02:52:10 am »
Thanks Ashish, glad you approve.