47
\$\begingroup\$

Your challenge is to draw/plot one of the hearts below. The size must be at least 50x50 pixels (vector graphics is OK). You may choose which of the hearts you want to draw/plot. Axes, grid lines etc. are accepted. There must be at least 100 distinct coordinates/points on the graph. The heart can be filled with color if you want to.

enter image description here

The equations are either:

enter image description here

or

enter image description here

enter image description here

t is in the range [-1, 1].

or

enter image description here

or

enter image description here

This is so the shortest code (in each language) in bytes wins. Please provide the output (or link to an online interpreter).

\$\endgroup\$
0

20 Answers 20

68
\$\begingroup\$

TI-80 BASIC, 45 43 41 39 bytes

LBL 1
RAND4-2->X
RAND4-2
IF (X²+ANS²-1)³<X²ANS³
PT-ON(X,ANS
GOTO 1

enter image description here

This took a while, and my battery is low so I didn't want to keep going.

I tried to use the second equation, but couldn't get it to work it actually turned out to be longer, so I just adapted the other answer I had.

EDIT: I just noticed the 50x50 pixel requirement, unfortunately the screen is only 47 pixels high so this isn't possible.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ creative indeed! \$\endgroup\$
    – dalearn
    Commented Feb 13, 2017 at 17:13
  • 8
    \$\begingroup\$ It's been a while, but can you replace IF (X²+ANS²-1)³-X²ANS³<0 with IF (X²+ANS²-1)³<X²ANS³? \$\endgroup\$
    – wchargin
    Commented Feb 15, 2017 at 3:58
  • \$\begingroup\$ Oh, I can't believe I didn't think of that! thanks \$\endgroup\$
    – 12Me21
    Commented Feb 15, 2017 at 13:04
47
\$\begingroup\$

Perl, 86 bytes

$y=1-$_/25,say+map$y**3*($_*=$_/1e3)-($_+$y**2-1)**3>0?$|--?v60:3:$",-40..40for-6..50

Run with perl -E.

Plots a filled ASCII heart, using the first equation. Note that the x-axis is stretched by a factor of ~1.265: this is to counteract the fact that terminal fonts are usually much bigger vertically than horizontally.

Output:

                3<3<3<3<3<3<3<                   3<3<3<3<3<3<3<                 
              3<3<3<3<3<3<3<3<3<3<           3<3<3<3<3<3<3<3<3<3<               
            3<3<3<3<3<3<3<3<3<3<3<3<       3<3<3<3<3<3<3<3<3<3<3<3<             
          3<3<3<3<3<3<3<3<3<3<3<3<3<3<   3<3<3<3<3<3<3<3<3<3<3<3<3<3<           
         3<3<3<3<3<3<3<3<3<3<3<3<3<3<3< 3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<          
        3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3 <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<         
       3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3        
      <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<       
      3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3       
     <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<      
     3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3      
    <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<     
    3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3     
    <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<     
    3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3     
    <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<     
   3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3    
   <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<    
    3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3     
    <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<     
    3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3     
    <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<     
    3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3     
     <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<      
     3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3      
     <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<      
      3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3       
      <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<       
       3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3        
       <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<        
        3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3         
         <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<          
         3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3          
          <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<           
           3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3            
            <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<             
             3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3              
              <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<               
               3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3                
                <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<                 
                 3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3                  
                  <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<                   
                   3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3                    
                     <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<                      
                      3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3                       
                       <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<                        
                         3<3<3<3<3<3<3<3<3<3<3<3<3<3<3                          
                           <3<3<3<3<3<3<3<3<3<3<3<3<                            
                            3<3<3<3<3<3<3<3<3<3<3<3                             
                              <3<3<3<3<3<3<3<3<3<                               
                                3<3<3<3<3<3<3<3                                 
                                  <3<3<3<3<3<                                   
                                    3<3<3<3                                     
                                     <3<3<                                      
                                       3                                        

Explanation (since OP asked for it):

condition := $y**3*($_*=$_/1e3)-($_+$y**2-1)**3>0

This is simply the first equation, slightly rearranged to make it shorter. $y directly represents the y in the formula. $_ is initially proportional to x, but is multiply-assigned with itself ($_*=$_/1e3), making it proportional to x². Since x² is used twice in the formula, this saves a few bytes.

1e3 means 1000, and was picked because it’s short and the result looks good. ** is Perl’s power operator. I use >0 rather than ==0 because I want a filled heart.

flip_flop := $|--?v60:3

v60 is an abuse of the archaic version-string syntax to denote the character with ASCII code 60: '<'.

$| is a magical variable that can only ever be 0 or 1. Decrementing when it’s already 0 sets it to 1. Decrementing when it’s 1 naturally sets it to 0. Thus, $|-- is often used as a flip-flop: each time it’s evaluated, it alternates between true and false.

As a whole, this expression returns alternatively '<' and 3.

inner_loop := <condition> ? <flip_flop> :$"

Nested ternaries. If condition is false (→ we’re outside the heart), evaluates to $", which is a magical variable that defaults to " " (a single space). If condition is true (→ we’re inside the heart), it evaluates flip_flop.

outer_loop := say+map <inner_loop> ,-40..40

Evaluates inner_loop repeatedly, with $_ (Perl’s “default” variable) going from -40 to 40, in increments of 1. It collects the results of those evaluation in a temporary list, then prints them all, concatenated, ending with a new line.

$y=1-$_/25, <outer_loop> for-6..50

This runs outer_loop repeatedly, with $y going from 1.24 (1 - (-6 / 25)) to -1 (1 - 50 / 25), in decrements of 0.04.

Note that y is divided by 25, while x² is divided by 1000, which is the same as dividing x by sqrt(1000). The ~1.265 factor I mentioned is sqrt(1000) / 25.

\$\endgroup\$
4
  • 5
    \$\begingroup\$ Huh, I guess it doesn't violate any rules... My favorite so far :) I'd love an explanation though :) \$\endgroup\$ Commented Feb 13, 2017 at 17:01
  • 2
    \$\begingroup\$ I'm confused about something. Why use ?v60 over, say, "<"? \$\endgroup\$
    – anon
    Commented Feb 13, 2017 at 21:44
  • \$\begingroup\$ Same length, but easier to type. \$\endgroup\$
    – Grimmy
    Commented Feb 14, 2017 at 7:39
  • \$\begingroup\$ A heart made from hearts. \$\endgroup\$ Commented Feb 14, 2017 at 12:29
34
\$\begingroup\$

Mathematica WolframAlpha, 17 15 13 11 bytes

Shaved off 2 bytes thanks to Martin Ender (1st heart curve -> heart curve 1)

Shaved off another 2 bytes thanks to Martin Ender (heart curve 1 -> heartcurve1)

This is probably cheating (the obvious solution), but here goes.

heartcurve1

Try it here!

I'm sure there's a way to shorten 1st, heart or curve such that Wolfram still accepts it. Well it's free of spaces now, maybe some sort of abbreviation for heart?

Do I get bonus points for plotting 2 of them?

heartcurves

Try that here!

\$\endgroup\$
6
  • 5
    \$\begingroup\$ heart curve 1 \$\endgroup\$ Commented Feb 13, 2017 at 13:34
  • 6
    \$\begingroup\$ Actually, heartcurve1 works. \$\endgroup\$ Commented Feb 13, 2017 at 13:35
  • 24
    \$\begingroup\$ @MartinEnder What in the world \$\endgroup\$
    – Thunda
    Commented Feb 13, 2017 at 13:36
  • 1
    \$\begingroup\$ first one of heartcurves looks more like a butt though \$\endgroup\$
    – Mikhail V
    Commented Feb 14, 2017 at 22:17
  • \$\begingroup\$ @MikhailV 0th heartcurve (cardoid) looks like a butt. \$\endgroup\$
    – Thunda
    Commented Feb 15, 2017 at 8:31
29
\$\begingroup\$

Mathematica, 52 bytes

RegionPlot[(x^2+y^2-1)^3-x^2y^3<0,{x,-2,2},{y,-2,2}]

enter image description here

We could save one more byte with ContourPlot but then the background gets a bit trippy:

ContourPlot[(x^2+y^2-1)^3-x^2y^3,{x,-2,2},{y,-2,2}]

enter image description here

For one additional byte we could use the fourth formula and PolarPlot instead:

PolarPlot[(x=Sin@t)Abs@Cos@t^.5/(x+7/5)-2x+2,{t,0,7}]

enter image description here

\$\endgroup\$
1
  • 24
    \$\begingroup\$ "A bit trippy" is a bit of an understatement... \$\endgroup\$
    – user45941
    Commented Feb 13, 2017 at 13:41
26
\$\begingroup\$

Casio fx-7700GH, 21 bytes

sin θ √ Abs cos θ ÷ ( sin θ + 7 ÷ 5 ) - 2 sin θ + 2

Unnamed graph function to be entered into one of the polar coordinate graphing function slots, then does what it says on the tin.

The graphing range must be manually set (unless it happens to fit to the current set range), I set it to Xmin=-2.75, Xmax=2.75, Ymin=-4, Ymax=1.

Should work on other Casio Power Graphic Series calculators too, and quite possibly later Casio graphic calculators.

A heart drawn by a Casio fx-7700GH calculator (yep I'm pretty old and dusty)

\$\endgroup\$
18
\$\begingroup\$

MATLAB / Octave, 31 bytes

ezplot('(x^2+y^2-1)^3-x^2*y^3')

enter image description here

\$\endgroup\$
0
10
\$\begingroup\$

Desmos, 20 16 15 bytes

V 2:

xx).3y=xx+yy-1

( = xx)^.3y=xx+yy-1)

V 1:

xx+yy-1)3=xxy3

V 0:

(x2+y2-1)3=x2y3
\$\endgroup\$
9
  • \$\begingroup\$ you could use xx instead of x^2 \$\endgroup\$
    – 12Me21
    Commented Feb 15, 2017 at 14:47
  • \$\begingroup\$ Your byte count is wrong, you have an extra newline. \$\endgroup\$
    – Riker
    Commented Feb 16, 2017 at 21:46
  • \$\begingroup\$ @Riker, I don't see how it's wrong. Where is there a newline? \$\endgroup\$
    – Daniel
    Commented Feb 16, 2017 at 21:47
  • \$\begingroup\$ imgur.com/a/4eTyt V2 is 14 bytes \$\endgroup\$
    – Riker
    Commented Feb 16, 2017 at 21:47
  • \$\begingroup\$ @Riker, ah you forgot the ^. It's really xx)^.3=xx+yy-1 \$\endgroup\$
    – Daniel
    Commented Feb 16, 2017 at 21:49
9
\$\begingroup\$

SmileBASIC, 85 81 bytes

X=RNDF()*4-2Y=RNDF()*4-2GPSET X*50+99,Y*50+99,-(-X*X*Y*Y*Y>POW(X*X+Y*Y-1,3))EXEC.

enter image description here

\$\endgroup\$
8
\$\begingroup\$

MATL, 36 bytes

1e4t:w/EqXJX,JY,J|Yl**JX,X^J|.3^*&XG

Try it at MATL Online

enter image description here

\$\endgroup\$
1
  • 10
    \$\begingroup\$ Tfw MATL solution is longer than MATLAB :) \$\endgroup\$
    – brainkz
    Commented Feb 14, 2017 at 11:00
7
\$\begingroup\$

Python, 119 116 bytes

from turtle import*
from math import*
t=1
while-t<1:a=abs(t);c=cos(t);goto(sin(t)*c*log(a)*99,c**.5*a**.3*99);t-=.01

Try it online

x=sin(t)*cos(t)*log(abs(t))

y=cos(t)**.5*abs(t)**.3

\$\endgroup\$
7
\$\begingroup\$

Jelly, 31 bytes

*3×
²+’*3<çị⁾* 
25µNr÷21µ²ç@þUY

Try it online!

or 35 bytes with a , rather than * fill: change middle line to ²+’*3<ç×9829Ọ»⁶.

          ♥♥♥♥♥♥♥♥♥♥           ♥♥♥♥♥♥♥♥♥♥          
        ♥♥♥♥♥♥♥♥♥♥♥♥♥♥       ♥♥♥♥♥♥♥♥♥♥♥♥♥♥        
      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥      
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥     
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥     
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥    
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥   
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥   
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥   
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥   
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥   
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥    
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥    
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥     
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥     
      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥      
      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥      
       ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥       
        ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥        
        ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥        
         ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥         
          ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥          
           ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥           
            ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥            
             ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥             
              ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥              
               ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥               
                 ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥                 
                  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥                  
                   ♥♥♥♥♥♥♥♥♥♥♥♥♥                   
                     ♥♥♥♥♥♥♥♥♥                     
                      ♥♥♥♥♥♥♥                      
                        ♥♥♥                        
                         ♥                         

How?

Implements: equation over a 51 by 51 line feed separated grid of characters.

*3× - Link 1: y, xSquared
*3  - cube y
  × - multiply the result by xSquared

²+’*3<çị⁾*  - Link 2: y, xSquared
²           - square y
 +          - add xSquared to the result
  ’         - subtract one
   *3       - cube the result
     <      - less than? (1 if True, 0 if False)
      ç     -     the result of the last link (1) as a dyad: f(y, xSquared)
       ị    - index into (1-based):
        ⁾*  - the string "* " (there is a trailing space on this line)

       ×9829Ọ»⁶ - alternative ending of link 2
       ×9829    - multiply (vectorises) by 9829
            Ọ   - cast to character (vectorises) (9829 is the ♥, 0 is the null-byte)
             »  - maximum (vectorises) of that and:
              ⁶ -     space character (ordinal of space is 32, greater than the null-byte, less than ♥)

25µNr÷21µ²ç@þUY - Main link: no arguments
25              - 25
  µ             - monadic chain separation call that i
   N            - negate i
    r           - inclusive range(negated i, i) -> [-25, -24, ..., 24, 25]
     ÷21        - divide by 21 (vectorises) -> [-1.1904761904761905, -1.1428571428571428, ..., 1.1428571428571428, 1.1904761904761905]
        µ       - monadic chain separation call that r
         ²      - square r (vectorises) (make the xSquared values, left to right)
             U  - upend r (make the y values, top to bottom)
            þ   - outer product using:
          ç@    -     last link (2) as a dyad with reversed arguments: f(y, xSquared)
              Y - join with line feeds
                - implicit print
\$\endgroup\$
6
\$\begingroup\$

SageMath, 66 bytes

polar_plot(sin(x)*abs(cos(x))^.5/(sin(x)+7/5)-2*sin(x)+2,(0,2*pi))

Try it online

Unfortunately, the long names of implicit_plot and parametric_plot (plus the need to define a variable other than the implicitly-defined x for the former) make the first three options much too long to be considered.

Thanks to busukxuan and Andrea Lazzarotto for a byte

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Does ^.5 work in place of **.5? \$\endgroup\$
    – busukxuan
    Commented Feb 14, 2017 at 3:49
  • 1
    \$\begingroup\$ @busukxuan Nope. Sage is built on Python, and ^ is XOR. \$\endgroup\$
    – user45941
    Commented Feb 14, 2017 at 5:59
  • 1
    \$\begingroup\$ But sage substitutes ^ with **. I was wondering if it was because it couldn't substitute correctly if followed by a . \$\endgroup\$
    – busukxuan
    Commented Feb 14, 2017 at 6:03
  • \$\begingroup\$ @busukxuan Sage uses Python's power notation (**). If you tried to use ^, you'd end up with a warning and an incorrect result. \$\endgroup\$
    – user45941
    Commented Feb 14, 2017 at 11:14
  • 1
    \$\begingroup\$ @AndreaLazzarotto Then apparently my memory is faulty. Thanks. \$\endgroup\$
    – user45941
    Commented Feb 14, 2017 at 20:41
6
\$\begingroup\$

C, 137 133 bytes

p;float x,y,f;v(){for(p=4e3;p;x=(float)(p%99-50)/35,y=(float)(p/40-45)/40,f=x*x+y*y-1)putchar(p--%99?f*f*f-x*x*y*y*y<1e-3?35:32:10);}

http://codepad.org/zqqYUui8

Thanks @AlbertRenshaw, I also changed the 100s to 99s for 2 more bytes

\$\endgroup\$
1
  • 1
    \$\begingroup\$ +1; I like the use of v for the function, good flair. You can shave two bytes by replacing 4000 with 4e3 and replacing 0.001 with 1e-3 \$\endgroup\$ Commented Feb 15, 2017 at 3:31
5
\$\begingroup\$

Ruby, 80 bytes

Show Ruby some love.

-2.step(2,0.2){|y|-2.step(2,0.1){|x|$><<'. O'[(y*y-1+x*=x)**3+x*y**3<=>0]};puts}

Output:

         OOOOO     OOOOO             
      .OOOOOOOOO.OOOOOOOOO.          
     OOOOOOOOOOOOOOOOOOOOOOO         
     OOOOOOOOOOOOOOOOOOOOOOO         
     OOOOOOOOOOOOOOOOOOOOOOO         
      OOOOOOOOOOOOOOOOOOOOO          
      .OOOOOOOOOOOOOOOOOOO.          
        OOOOOOOOOOOOOOOOO            
         OOOOOOOOOOOOOOO             
           OOOOOOOOOOO               
              OOOOO                  
                .                    

with some empty lines above and below

\$\endgroup\$
5
\$\begingroup\$

JavaScript (ES6), 151 147 bytes

document.write`<canvas id=c>`;for(i=0;x=2-i/24,i<97;i++)for(j=0;y=2-j/24,z=x*x+y*y-1,j<97;j++)z*z*z-x*x*y*y*y<0&&c.getContext`2d`.fillRect(i,j,1,1)

Edit: Saved 4 bytes thanks to @user2428118. ES7 version for 143 bytes:

document.write`<canvas id=c>`;for(i=0;i<97;i++)for(x=2-i/24,j=0;j<97;j++)x*x*(y=2-j/24)**3-(x*x+y*y-1)**3>0&&c.getContext`2d`.fillRect(i,j,1,1)

\$\endgroup\$
8
  • \$\begingroup\$ how about y**3 instead of y*y*y ? \$\endgroup\$
    – svarog
    Commented Feb 14, 2017 at 7:14
  • 1
    \$\begingroup\$ @svarog Thus my note "Would be slightly shorter in ES7"... \$\endgroup\$
    – Neil
    Commented Feb 14, 2017 at 8:36
  • \$\begingroup\$ well, it works on chromium 55, so why not add an es7 version ? \$\endgroup\$
    – svarog
    Commented Feb 14, 2017 at 9:14
  • 1
    \$\begingroup\$ @svarog Because I don't have chromium 55 handy... \$\endgroup\$
    – Neil
    Commented Feb 14, 2017 at 15:20
  • 1
    \$\begingroup\$ @ThisSuitIsBlackNot It complained about undeclared variables when I tried. \$\endgroup\$
    – Neil
    Commented Feb 15, 2017 at 18:03
4
\$\begingroup\$

BBC BASIC, 80

Will finish golfing tomorrow.

Download interpreter at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html

ORIGIN99,99F.u=-56TO56x=u/50b=x^2^.33/2r=(b^2-x^2+1)^.5*50L.u,b*50-r,u,r+b*50N.

Draws a filled heart using the first equation, which we rearrange and take the cube root of (there are 3 cube roots of a real number, one real and 2 complex but we only interested in the real root here.) We then rearrange again to get a quadratic in y

x^2+y^2-1=(x^0.66)y

y^2-(x^0.66)y+x^2-1=0

Using the standard quadratic formula for expressions of the type ay^2+by+c=0, and taking advantage of the fact that a=1 we get

y = -b/2 +/- sqrt((b/2)^2-c)

y = -b/2 +/- sqrt((b/2)^2-x^2+1)

where -b/2 = (x^0.66)/2 (represented by b in the program.)

We simply scan through the values of x from left to right, drawing a vertical line between each pair of valid values for y to build up a solid shape.

ORIGIN99,99F.u=-56TO56x=u/50b=x^2^.33/2r=(b^2-x^2+1)^.5*50L.u,b*50-r,u,r+b*50N.

ungolfed

ORIGIN99,99
FORu=-56TO56
  x=u/50
  b=x^2^.33/2
  r=(b^2-x^2+1)^.5*50
  LINEu,b*50+r,u,b*50-r
NEXT
\$\endgroup\$
2
\$\begingroup\$

Processing.js: 123 119 bytes

ungolfed:

t = 0; 

void setup() {
    size(99, 300); 
} 

void draw() {
    point(59+99*sin(t)*cos(t)*log(t),350-400*sqrt(cos(t))*pow(t,0.3));
    t+=0.01;
}

golfed:

t=0;void setup(){size(99,300);}void draw(){point(59+99*sin(t)*cos(t)*log(t),350-400*sqrt(cos(t))*pow(t,0.3));t+=0.01;}

this one is quite cheaty as it plots #2 from 0 to infinity instead of from -1 to 1 as shown in the picture to save on the two abs(t). But it's technically correct as there are more than 100 points.


130 bytes "correctier" one

t=-1;void setup(){size(99,300);}void draw(){point(59+99*sin(t)*cos(t)*log(abs(t)),350-400*sqrt(cos(t))*pow(abs(t),0.3));t+=0.01;}

try it online

note : there's probably a way to get 100 points on the default 100x100 canvas and shave the setup off.

\$\endgroup\$
4
  • \$\begingroup\$ None of your snippets do anything for me on my local version of Processing (except for the second one which just draws 1 point) \$\endgroup\$
    – user41805
    Commented Feb 13, 2017 at 15:34
  • \$\begingroup\$ have you tried on sketchpad? ("try it online") you need to click "render sketch" \$\endgroup\$
    – satibel
    Commented Feb 13, 2017 at 15:35
  • \$\begingroup\$ But I think that would be called "Processing.JS" instead. For the snippet to work for me, you have to use float instead of int \$\endgroup\$
    – user41805
    Commented Feb 13, 2017 at 15:37
  • \$\begingroup\$ oops, forgot the .js, and thanks to that I saved 4 bytes by removing the useless int. \$\endgroup\$
    – satibel
    Commented Feb 13, 2017 at 15:41
2
\$\begingroup\$

TI-84 Basic, 40 38 bytes

Similar to @12Me21's answer & output, but for the TI-83/84 series instead.

While 1:2rand-1→A:2rand-1:If (A²+Ans²-1)³>A²Ans³:Pt-On(A,Ans:End
\$\endgroup\$
2
  • \$\begingroup\$ Is using Ans actually smaller here? I thought Ans was 2 bytes. \$\endgroup\$
    – 12Me21
    Commented Feb 13, 2017 at 16:48
  • \$\begingroup\$ @12Me21 No, it's the same size, and faster too. (For TI-83/84 at least, I don't know about TI-80). \$\endgroup\$
    – Timtech
    Commented Feb 13, 2017 at 16:52
1
\$\begingroup\$

BBC BASIC (BBC Micro) (126 bytes)

This is a variation of Level River Street's answer, but for the original BBC Micro's iteration of BBC BASIC.

You can copy and paste either of the following into JSBeeb's new paste functionality at https://bbc.godbolt.org/ (A JavaScript powered BBC Micro emulator), once it has pasted, press Enter inside the 'screen' to show a new prompt, then type RUN, then press Enter to run either version.

golfed. (126 bytes)

1MO.1:V.29,64;64;:MOVE-57,20:GC.0,1:F.U=-56TO56:X=U/50:IFX<>0TH.B=X^2^.33/2
2R=(B^2-X^2+1)^.5*50:DRAWU,B*50+R:DRAW U,B*50-R:N.

ungolfed. (176 bytes)

1 MODE 1
2 VDU 29,64;64;
3 MOVE -57,20
4 GCOL 0,1
5 FOR U = -56 TO 56
6 X = U/50
7 IF X <> 0 THEN B = X^2^.33/2
8 R = (B^2-X^2+1)^.5*50
9 DRAW U,B*50+R
10 DRAW U,B*50-R
11 NEXT

Line 7 requires a check for X, to prevent a "Log range" error when X becomes 0 half way through the loop. Other than this, it's pretty much the same. It's a lot slower to draw on a real machine, which JSBeeb emulates pretty well.

\$\endgroup\$
1
\$\begingroup\$

Google Sheets (Conditional Formatting), 73

Set conditional formatting on range A1:CV100:

=(2500/9-(Column()-25)^2-(ROW()-25)^2)^3>(Column()-25)^2*(ROW()-25)^3/.06

You'll have to adjust your columns/rows so that 100x100 cells fit on your screen. (10 pixels is a good value.) Colors the cells in the cardioid.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.