Author Topic: Re: Heartbeats  (Read 361 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Heartbeats
« on: February 28, 2019, 06:57:09 pm »
Damn! I posted this in your Cardiod Thread and then withdrew it because it was not same type of Cardiod.

Now it is!
Code: QB64: [Select]
  1. _TITLE "Beating Cardiod" 'B+ 2019-02-16
  2.  
  3. CONST xmax = 800
  4. CONST ymax = 600
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE (1280 - xmax) / 2 + 30, (760 - ymax) / 2
  7.  
  8. 'center of screen
  9. CX = xmax / 2
  10. CY = ymax / 2
  11.  
  12. WHILE _KEYDOWN(27) = 0
  13.     CLS
  14.     loopCount = (loopCount + 1) MOD 2
  15.     IF loopCount THEN magnify = 10 ELSE magnify = 15
  16.     FOR a = -_PI TO _PI STEP _PI(1 / 360)
  17.         x = CX + magnify * xCard(a)
  18.         y = CY - magnify * yCard(a)
  19.         IF a <> -_PI THEN
  20.             LINE (x, y)-(lastx, lasty), _RGB(180, 60, 30)
  21.         END IF
  22.         lastx = x: lasty = y
  23.     NEXT
  24.     PAINT (CX, CY), _RGB(180, 60, 30), _RGB(180, 60, 30)
  25.     _DISPLAY
  26.     IF loopCount THEN _DELAY 50 / 60 ELSE _DELAY 40 / 65
  27.  
  28. 'Reference and thanks to:
  29. ' http://mathworld.wolfram.com/HeartCurve.html
  30. ' find the 6th heart curve equations #7, 8
  31. FUNCTION xCard (t)
  32.     xCard = 16 * SIN(t) ^ 3
  33.  
  34. FUNCTION yCard (t)
  35.     yCard = 13 * COS(t) - 5 * COS(2 * t) - 2 * COS(3 * t) - COS(4 * t)
  36.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Heartbeats
« Reply #1 on: February 28, 2019, 07:06:08 pm »
Here it is with random beats and magnifications:
Code: QB64: [Select]
  1. _TITLE "Beating Cardiod" 'B+ 2019-02-16
  2. '2019-02-28 random magnify and beat, redder heart
  3.  
  4.  
  5. CONST xmax = 800
  6. CONST ymax = 600
  7. SCREEN _NEWIMAGE(xmax, ymax, 32)
  8. _SCREENMOVE (1280 - xmax) / 2 + 30, (760 - ymax) / 2
  9.  
  10. 'center of screen
  11. CX = xmax / 2
  12. CY = ymax / 2 - 50
  13.  
  14. WHILE _KEYDOWN(27) = 0
  15.     CLS
  16.     loopCount = (loopCount + 1) MOD 2
  17.     IF loopCount THEN magnify = 10 ELSE magnify = RND * 10 + 12
  18.     FOR a = -_PI TO _PI STEP _PI(1 / 360)
  19.         x = CX + magnify * xCard(a)
  20.         y = CY - magnify * yCard(a)
  21.         IF a <> -_PI THEN
  22.             LINE (x, y)-(lastx, lasty), _RGB(140, 0, 0)
  23.         END IF
  24.         lastx = x: lasty = y
  25.     NEXT
  26.     PAINT (CX, CY), _RGB(180, 0, 0), _RGB(140, 0, 0)
  27.     _DISPLAY
  28.     IF loopCount THEN _DELAY 40 / 60 ELSE _DELAY (30 + RND * 15) / 65
  29.  
  30. 'Reference and thanks to:
  31. ' http://mathworld.wolfram.com/HeartCurve.html
  32. ' find the 6th heart curve equations #7, 8
  33. FUNCTION xCard (t)
  34.     xCard = 16 * SIN(t) ^ 3
  35.  
  36. FUNCTION yCard (t)
  37.     yCard = 13 * COS(t) - 5 * COS(2 * t) - 2 * COS(3 * t) - COS(4 * t)
  38.  
« Last Edit: February 28, 2019, 07:11:46 pm by bplus »