Author Topic: Re: Cardioid  (Read 919 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Cardioid
« on: February 16, 2019, 08:50:56 am »
For semi-obvious reasons, back in community college the professor called this the "assoid". Not a crappy name, if you ask me.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cardioid
« Reply #1 on: February 16, 2019, 04:39:59 pm »
Oh Valentine's day was this week, thanks [banned user] for reminder.

EDIT:(pulled my code out of this thread because NOT a mod of [banned user]'s)
« Last Edit: February 17, 2019, 11:09:48 am by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Cardioid
« Reply #2 on: February 17, 2019, 09:51:52 am »
Nice program, [banned user], I'm impressed that you got the bottom cusp as well

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cardioid
« Reply #3 on: February 17, 2019, 02:49:58 pm »
Some nice renderings there! Why didn't you use the r g b values for coloring? It gives the drawings some sparkle.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cardioid
« Reply #4 on: February 17, 2019, 07:49:08 pm »
OK I watched the video, what a crazy guy!

Here is a Cardioid the fast and simple way compared to Shiffman's:
Code: QB64: [Select]
  1. _TITLE "Cardioid and Beyond"
  2. CONST xmax = 700
  3. CONST ymax = 700
  4. CONST npoints = 200
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. CX = xmax / 2
  7. CY = ymax / 2
  8. DA = _PI(2 / npoints)
  9. R = CX - 10
  10.  
  11. Mult = 2
  12. CIRCLE (CX, CY), R
  13. FOR i = 1 TO 200
  14.     x1 = CX + R * COS(i * DA)
  15.     y1 = CY + R * SIN(i * DA)
  16.     x2 = CX + R * COS(Mult * i * DA)
  17.     y2 = CY + R * SIN(Mult * i * DA)
  18.     LINE (x1, y1)-(x2, y2)
  19.  

And here is that super cool thing he did at the end:
Code: QB64: [Select]
  1. _TITLE "Cardioid and Beyond" 'B+ 2019-02-17
  2. CONST xmax = 700
  3. CONST ymax = 700
  4. CONST npoints = 200
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. CX = xmax / 2
  7. CY = ymax / 2
  8. DA = _PI(2 / npoints)
  9. R = CX - 10
  10.  
  11. FOR Mult = 0 TO 100 STEP .01
  12.     CLS
  13.     CIRCLE (CX, CY), R
  14.     FOR i = 1 TO 200
  15.         x1 = CX + R * COS(i * DA)
  16.         y1 = CY + R * SIN(i * DA)
  17.         x2 = CX + R * COS(Mult * i * DA)
  18.         y2 = CY + R * SIN(Mult * i * DA)
  19.         LINE (x1, y1)-(x2, y2)
  20.     NEXT
  21.     _DISPLAY
  22.     _LIMIT 30

Colorized:
Code: QB64: [Select]
  1. _TITLE "Cardioid and Beyond" 'B+ 2019-02-17
  2. CONST xmax = 700
  3. CONST ymax = 700
  4. CONST npoints = 200
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. DIM SHARED pR, pG, pB, cN
  7. CX = xmax / 2
  8. CY = ymax / 2
  9. DA = _PI(2 / npoints)
  10. R = CX - 10
  11.  
  12. FOR Mult = 0 TO 100 STEP .01
  13.     CLS
  14.     COLOR &HFFFFFFFF
  15.     PRINT "Multiple: ";
  16.     PRINT USING "###.##"; Mult
  17.     IF Mult = INT(Mult) THEN resetPlasma
  18.     CIRCLE (CX, CY), R, _RGB32(0, 128, 0)
  19.     FOR i = 1 TO 200
  20.         x1 = CX + R * COS(i * DA)
  21.         y1 = CY + R * SIN(i * DA)
  22.         x2 = CX + R * COS(Mult * i * DA)
  23.         y2 = CY + R * SIN(Mult * i * DA)
  24.         changePlasma
  25.         LINE (x1, y1)-(x2, y2)
  26.     NEXT
  27.     _DISPLAY
  28.     _LIMIT 30
  29.  
  30. SUB changePlasma ()
  31.     cN = cN + 1
  32.     COLOR _RGB(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
  33.  
  34. SUB resetPlasma ()
  35.     pR = RND ^ 2: pG = RND ^ 2: pB = RND ^ 2
  36.  
  37.  

EDIT: colorized with plasma
« Last Edit: February 18, 2019, 09:57:14 am by bplus »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Cardioid
« Reply #5 on: February 18, 2019, 10:13:53 am »
@[banned user]
Nice work! Sometime, it looked like a 3D illusion to me.

@bplus
Nice work on that plasma cardiod.

if (Me.success) {Me.improve()} else {Me.tryAgain()}


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