14
5
A Spirograph is a toy that draws hypotrochoids and epitrochoids. For this challenge, we'll just focus on the hypotrochoids.
From Wikipedia:
A hypotrochoid is a roulette traced by a point attached to a circle of radius r rolling around the inside of a fixed circle of radius R, where the point is a distance d from the center of the interior circle.
The parametric equations for them can be defined as:
Where θ is the angle formed by the horizontal and the center of the rolling circle.
Your task is to write a program that will draw the path traced by the point defined above. As input, you'll be given R, r, and d, all integers between 1 and 200 inclusive.
You can receive this input from stdin, arguments, or user input, but it cannot be hardcoded into the program. You can accept it in whatever form is most convenient for you; as strings, integers, etc.
Assume:
- Input units are given in pixels.
- R >= r
Output should be a graphical representation of the hypotrochoid defined by the input. No ASCII- or other text-based output is allowed. This image can be saved to a file or displayed on screen. Include a screenshot or image of the output for an input of your choosing.
You can choose any colors you like for the path/background, subject to a contrast restriction. The two colors must have HSV 'Value' component at least half the scale apart. For instance, if you're measuring HSV from [0...1]
, there should be at least 0.5
difference. Between [0...255]
there should be a minimum 128
difference.
This is a code golf, minimum size of source code in bytes wins.
Bit late, but if
r<0
, does that produce an epitrochoid? – Beta Decay – 2017-05-07T17:51:21.823Can we assume
R > r
orR ≥ r
? (Same forr
andd
.) – Martin Ender – 2014-05-23T17:09:17.38310Congratulations on posting the 2000th question! ;-) – Doorknob – 2014-05-23T17:11:04.663
@m.buettner
R>=r
, butd
is not constrained tor
, and can be anywhere in the 1-200 range. – Geobits – 2014-05-23T17:12:21.943What kind of resolution are we talking about? – Kyle Kanos – 2014-05-23T17:19:25.653
@KyleKanos Since input is in pixels and each has a cap of 200, It shouldn't ever be larger than 798x798, given
R=200, r=1, d=200
. You can size the image to the input if you want, or keep it at a constant size, as long as it's all visible. – Geobits – 2014-05-23T17:22:55.247@Geobits: whoops, didn't see the first bullet that said input in pixels. – Kyle Kanos – 2014-05-23T17:24:17.633