# St. Patrick's Day Challenge!

Seeing as its St. Patrick's day, I thought I would have a little challenge

Your task is to write a program draws a clover in any way possible. Each leaf has to be symmetrical, and the user has to input the number of leaves that they want on the clover. It then must be drawn. This has to be generated. You cannot just load an image or have ASCII art saved as a variable. However using modules like turtle to generate (and draw is included under generate) are fine.

You can use any language. This is a code-golf so the shortest answer wins.

Begin! Happy St Patrick's Day!

Just for reference, here is an example of a 3 leaf clover

Just for DavidCarraher

• Also, you might want to specify a shamrock instead of a clover! Mar 18, 2014 at 3:33

## Mathematica - 106 bytes

c=RegionPlot[x^2+y^2<Abs@Sin[#x~ArcTan~y/2]||x>0&&y^2<.001,{x,-1,1},{y,-1,1},Frame->0>1,PlotStyle->Green]&


Ungolfed version:

c[leaves_] := (
angle = ArcTan[x,y];
RegionPlot[
x^2 + y^2 < Abs[Sin[leaves*angle/2]]
|| x > 0 && y^2 < .001
, {x,-1,1}
, {y,-1,1}
, Frame -> False, PlotStyle -> Green
]);


Here are the outputs for c[3] through c[6].

At the cost of another 7 bytes you can improve the colour (using PlotStyle->Darker@Green or PlotStyle->Hue[.3,1,.7] instead), and for another 15 bytes you can remove some of the sampling artifacts (using an additional option ,PlotPoints->90), giving a total of 128 bytes for these beauties:

The braces and commes in those pictures are not produced by c, but just by how I output them to fit them all in one row.

Lastly, here is an attempt at somewhat neater shading. I didn't even bother golfing this down further, the option names are just too long. I'm not even sure I'm too pleased with the result, but I thought I'd post it anyway. This is 188 bytes as it stands:

c=RegionPlot[x^2+y^2<Abs@Sin[(l=#)x~(a=ArcTan)~y/2]||x>0&&y^2<.001,{x,-1,1},{y,-1,1},Frame->0>1,PlotPoints->90,ColorFunction->(Hue[.3,1,.5+.2Sin[.5l#~a~#2]^8]&),ColorFunctionScaling->0>1]&


• Your Abs[] has no closing bracket Mar 18, 2014 at 23:08
• let's see a 3d version too? Mar 21, 2014 at 13:21
• @MichaelStern tempting :) ... but maybe some other time... I just spent my entire free time for today on another answer ^^ Mar 21, 2014 at 13:34

# C (145 126)

float d=2/--r,x,y=-1;for(;y<=1;y+=d,puts(""))for(x=-1;x<=1;x+=d)putchar(x*x+y*y<fabs(sin(l*atan2(x,y)))||fabs(x)<d&y>0?35:32);


Draws a clove in ASCII art; the function is passed the number of desired leaves and the resolution in characters. See example here: http://ideone.com/YDGN4H

Note that the result is much nicer when the horizontal resolution is doubled, at the cost of a slightly more verbose code (see http://ideone.com/RYaLz4).

Full version:

#include <math.h>
#include <stdio.h>

void clover(float l, float r)
{
float d = 2.f / --r;
float x, y=-1.f;
for (; y<=1.f; y+=d){
for (x=-1.f; x<=1.; x+=d){
printf((x*x + y*y < fabs(sin(l * atan2(x,y))) | (fabs(x) < d & y > 0)) ? "#" : " ");
}
printf("\n");
}
}

int main(int argc, char* argv[])
{
clove(4.f, 48.f);
return 0;
}

• Best use of variables names l and r! Mar 18, 2014 at 23:43