Heart in fortran

Well it’s not valentines day! But I just crossed my 5th wedding anniversary so it’s apt to do some heart warming geeky thing.

Red Heart created with Fortran

The above heart is rendered by pgplot from a program written in fortran.

The magic happens because of this little equation

y= sqrt(cos(x))*cos(200*x) + sqrt(abs(x)) – 0.7 * (4.0 – x*x)^0.01

-2.0>x<2.0

Here’s the complete program.

PROGRAM HEART

USE IFQWIN

TYPE(QWINFO) :: WINFO
INTEGER(4) :: RESULT
INTEGER :: PGOPEN
REAL XR(4000),YR(4000)

WINFO%TYPE=QWIN$MAX
RESULT= SETWSIZEQQ(QWIN$FRAMEWINDOW,WINFO)

RESULT=ABOUTBOXQQ(“HEART IN PGPLOT\RSUKHBINDER SINGH\RVERSION 1.0″C)
IF(PGOPEN(‘?’) .LE. 0) STOP
XR(1)=-2.0
XINC=0.001
YR(1)=(COS(XR(1)))**0.5 * COS(200*XR(1)) + (ABS(XR(1)))**0.5 -0.7 * (4.0 -XR(1) * XR(1))**0.01
DO I=2,4000
XR(I)=XR(I-1)+XINC
YR(I)=(COS(XR(I)))**0.5 * COS(200*XR(I)) + (ABS(XR(I)))**0.5 -0.7 * (4.0 -XR(I) * XR(I))**0.01
END DO

CALL PGENV(-2.0,2.0,-2.0,1.5,1,-1)
CALL PGSCI(2)
CALL PGPT(4000,XR,YR,1)

CALL PGCLOS
END PROGRAM

Showed it to my wife. From her quizzical look, I guess a real heart shaped gift would have been more appropriate! ;) Lesson learnt :)

Thanks walkingrandomly

About these ads

Tagged: , , , ,

4 thoughts on “Heart in fortran

  1. WalkingRandomly January 18, 2012 at 5:37 am Reply

    You’re welcome :)

  2. collisionavoidance January 18, 2012 at 4:53 pm Reply

    Wish you all the best. May you share your time together.

    Priyankar

  3. [...] i was lazy and used the code from previous”Heart In fortran” code and created this [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 932 other followers

%d bloggers like this: