The love formula

Jim Hurley jhurley0305 at sbcglobal.net
Fri Feb 15 17:51:08 EST 2013


This is a little late for Valentine's day, but I was being smothered in affection yesterday ;)

Here is a link to show the formula for a heart: 

http://www.google.com/imgres?q=the+love+formula&hl=en&client=safari&tbo=d&rls=en&biw=1335&bih=943&tbm=isch&tbnid=S0s-aYE5EW3kdM:&imgrefurl=http://9gag.com/gag/125927&docid=ZUOxCpj_QyMOlM&imgurl=http://d24w6bsrhbeh9d.cloudfront.net/photo/125927_700b.jpg&w=700&h=768&ei=dLkeUaj-Oci9igLty4CYCw&zoom=1&ved=1t:3588,r:5,s:0,i:96&iact=rc&dur=1220&sig=100340526412447560004&page=1&tbnh=172&tbnw=157&start=0&ndsp=20&tx=107&ty=88

And here is a script to draw one in LC.



local x0, y0, x, signum

on mouseUp
  --The equation of a heart is x^2 + (y - x^(2/3))^2  = 1
  --So that y = x^(2/3) + or - sqrt(1-x^2) 
  -- The plus give the top of the heart and the minus produces the bottom

  if there is no grc "heart" then create grc "heart"
  set the style of grc "heart" to "line"
  set the points of grc "heart" to empty
  put the width of this card/2 into x0
  Put round( the height of this card /2) into y0
  put  0 into x
  --Signum is used to change the sign of the square root
  put 1 into  signum
  put drawHeart() into tTopPoints
  put 0 into x
  --Now the bottom
  put -1 into signum
  put drawHeart() into tBottomPoints
  if last line of tBottpPoints is empty then delete the last line of tBottomPoints
  --The botton get drawn bottom up--so reverse the points.
  put reverse(tBottomPoints) into tBottomPoints
  --Combine top and bottom.
  put tTopPoints & cr & tBottomPoints into tFinal
  if the last line of tFinal is empty then delete last char of tFinal
--Now put those points into the center of the screen--at x0,y0
  repeat for each line tLine in tFinal
     if tLine is empty then next repeat
     put x0 + 100*item 1 of tLine into xTemp
     put x0 - 100*item 1 of tLine into xTempLeftSide
     put y0 - 100*item 2 of tLine into yTemp
     put  round(xTemp) , round(yTemp) into temp
     if temp is not empty then put temp & cr after results
     put  round(xTempLeftSide) , round(yTemp)  into temp2
     if temp2 is not empty then put temp2 & cr after resultsLeftSide
  end repeat
  set the points of grc "heart" to empty 
  set the points of grc "heart" to resultsLeftSide
  put cr & resultsLeftSide after results
  set the points of grc "heart" to results
end mouseUP

function y x
  return  x^(2/3) + signum* sqrt (1 - x^2) 
end y

function DrawHeart
  repeat 
     if x>= 1 then exit repeat
     put x , y(x) into tPoint
     put tPoint & cr after tPoints
     add .002to x
  end repeat
  return tPoints
end DrawHeart

function reverse tPoints
  repeat for each line tLine in tPoints
     put tLine & cr before results
  end repeat
  return results 
end reverse





More information about the use-livecode mailing list