In this tutorial, we will create the Rhodonea Curve and Maurer Rose pattern in Python! Before we get into what exactly is a Rodoneus Curve or Maurer`s Rose, we need to prepare the basic structure of our program!
Before we continue exploring the Rodonei curves or the Maurer rose patterns, we first need to prepare the basic structure of our program. So when we refactor our code, we will only change the function, while the rest of the program will be the same. So here is the main structure of the program —
If you run the code you get e error that
drawPattern is undefined. We`ll define this later. But for now, just let it be and let`s move on to understand what Rodonea Curves are !
Rodonea Curve (also known like math in the form of rose ) — it is basically a curve that can be expressed as where an integer specifying the number of petals ( if even and when strange)
Confused? em> Take a look at this image comparing the 12 petal rose and the 5 petal rose —
Note that the coordinates in the equation above are in polar form. But since in computer graphics we express the arrangement of pixels in a Cartesian rather than a polar form, the curve must be rewritten as a set of all points each in the form parametric equation as shown below:
The above was just theory, and in case you don`t fully understand the concept, you will understand when you see it in action . Just add the following to line 17 (right above where we called
This will give the following result —
pointswhich contains all the vertices of the rose, and later this vertex list is fed into
pygame.draw.lines a>which draws a sequence of continuous straight lines, and here we use it to draw a polygonal chain (since the rose is just a polygonal chain)
radians code > here. This is because angles are in degree format (we could use radians directly, but the range expects only integers, also for Maurer curves we have to use degrees anyway, so why not start from here) — hopefully we didn`t have to do Any conversion ourselves as Python3 provides built-in functions
Now what is Maurer Rose?
Now that we know about the Rodonei Curves, let`s move on to Maurer Rose:
Rose Maurera — this is a rhodonean curve of the form consisting of 361 lines connected by 361 points — each of the forms for each in the set , where is an integer
Varying values can create different types of roses even if they have the same number of petals (which means the same value )
Now the Cartesian coordinates will look like this:
Dirty hands with Maurer roses
So, to do something from what we just learned, we
drawPatternfunction is new: —
# Draws a Maurer rose with a value of n and d, which is `size`
drawMaurerRose (n, d, size):
# Maurer Rose equation
i < / code>
* code >
sin (radians (n
# Convert to Cartesian coordinates
cos (radians (k))
sin (radians (k))
. append (points, (width
# Draws a set of lines connected by many vertices
# Also, don`t close the path and paint it black and set the width to 5
pygame.draw.lines (screen, (
, po ints,
# Try changing these values to whatever you want
And now when you run the program, you should get the following result —
Changed only selected lines, everything else —
drawRhodoneaCurv eand now expects an additional parameter
kwhich actually comes from a formula. Its value at each iteration is
i * d, so for
d = 1the function is exactly the same as
n = 6and
d = 71. The values were copied from WikiPedia as a random
dvalue can sometimes lead to strange looking roses!
This book introduces machine learning methods in finance. It features a unified treatment of machine learn...
In Learn Python 3 the Hard Way PDF, you'll learn Python by working through 52 brilliantly crafted exercises. Read them. Enter your code exactly. (No copying and pasting!) Correct your mistakes. ...
Computer languages have so far been of the ‘interpreted’ or the ‘compiled’ type. Compiled languages (like ‘C’) have been more common. You prepare a program, save it (the debugged version),...
Learning Correct Cryptography by Example. The interconnected world of the current era has drastically changed everything, including banking, entertainment, and even statecraft. Despite difference...