Table of contents
1.
Introduction
2.
Getting Started
3.
Rhodonea Curve
3.1.
Explanation
4.
Maurer Rose
4.1.
Explanation
5.
Frequently Asked Questions
5.1.
What is Python pygame used for?
5.2.
Who introduced the concept of Maurer rose?
5.3.
What does rose mean in math?
5.4.
Why is it called a rose curve?
6.
Conclusion
Last Updated: Mar 27, 2024

Rhodonea Curves and Maurer Rose in Python

Author Harsh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

We'll make a Rhodonea Curve and Maurer Rose pattern with Python in this article! But before jumping right into it. Let's first create a basic structure of our program. We’ll later extend this program to draw Rhodonea Curve and Maurer Rose patterns.

Also see, Fibonacci Series in Python

Getting Started

Before diving into the good stuff lets first setup our program a bit like importing the required libraries, defining the variables, setting the title of our window, and all those things. Then we will extend this code according to our needs.

from math import sin
from math import cos
from math import radians

import pygame

# petals
n = 5

# size of our pattern
size = 100

# Background color
bgColor = (199, 197, 197)

# width and height of our window
(width, height) = (600, 400)

# Setup the window and init the screen surface
window = pygame.display.set_mode((width, height))

# Setting background color
window.fill(bgColor) 

# Title of our window
pygame.display.set_caption('Rhodonea Curves and Maurer Rose in Python')

# we'll update the definition of these functions later on
def drawRhodoneaCurve():
    pass

def drawMaurerRose(d):
    pass


# double-buffering
pygame.display.flip()

# Main Loop
while True :
    # Poll the events in the event queue
    for event in pygame.event.get() :
        # if the user closed the window
        if event.type == pygame.QUIT :

# deactivate pygame and quit the program
            pygame.quit()
            quit()

# Draws the surface object to the screen.
        pygame.display.update()
You can also try this code with Online Python Compiler
Run Code

You can also practice with the help of Online Python Compiler

Rhodonea Curve

The Rhodonea Curve (also known as the rose in mathematics) is a curve with the formula 

r = cos(n*theta), where n is an integer indicating the number of petals.

The formula mentioned above is in polar form. However, because pixel positions in computer graphics are expressed in cartesian rather than polar form, the curve must be re-described as a collection of all points (x, y) in parametric equations.

def drawRhodoneaCurve():
    positions = []
    for i in range(0, 361):
        # formula of rhodonea curve
        r = size * sin(radians(n * i))
 
        # Converting to cartesian coordinates
        x = r * cos(radians(i))
        y = r * sin(radians(i))
 
        list.append(positions, (width / 2 + x, height / 2 + y))
 
    # Draws a set of line segments connected by set of vertices positions
    pygame.draw.lines(window, (0, 0, 0), False, positions, 3)
You can also try this code with Online Python Compiler
Run Code

 

After updating the definition of drawRhodoneaCurve() in our original code and then calling it just above the “pygame.display.flip()” line. We’ll get output like the image below:

Rhodonea curve (n = 5)

Explanation

  • We calculate the vertices using the formula.
     
  • We save a list named points that contains all of the rose's vertices, and then we feed this list of vertices to pygame.draw.lines, which generates a series of continuous straight lines, which we use to draw a polygonal chain.
     
  • By default, PyGame has its coordinates in the Top-Left corner. So in order to draw our pattern in the center of the screen we are shifting the coordinates by (width/2, height/2).
     

Maurer Rose

A Maurer rose of the rose r = sin(nθ) is made up of 360 lines connecting the 361 points above. A Maurer rose is a rose-shaped polygonal curve with vertices.

Evolution of a Maurer rose, where n = 2 and d = 29 (Source: Wikipedia

 

Update the definition of drawMaurerRose(d) function in our original code and then call it. While calling make sure to provide the value of d.

def drawMaurerRose(d):
    positions =[]
    for i in range(0, 361):
        # The equation of a maurer rose
        k = i * d
        r = size * sin(radians(n * k))
 
        # Converting to cartesian coordinates
        x = r * cos(radians(k))
        y = r * sin(radians(k))
 
        list.append(positions, (width / 2 + x, height / 2 + y))
    # Draws a set of line segments connected by set of vertices points
    pygame.draw.lines(window, (0, 0, 0), False, positions, 2)
You can also try this code with Online Python Compiler
Run Code

 

After running, implement the above code in our original program and then run it. We’ll get output like this:

Maurer Rose (n=5 and d=29)

Explanation

  • The name of the function has been changed from drawRhodoneaCurve to drawMaurerRose, and it now takes an extra parameter d!
     
  • We now have a new variable k, which is derived from the formula. Its value is equal to i*d at each iteration.
     
  • We now use k instead of i.

Frequently Asked Questions

What is Python pygame used for?

The pygame library is an open-source module for the Python programming language that is designed to aid in the development of games and other multimedia applications. Pygame, which is based on the SDL (Simple DirectMedia Layer) development library, can run on a variety of platforms and operating systems.

 

Who introduced the concept of Maurer rose?

The concept of a Maurer rose was introduced by Peter M. Maurer. A Maurer rose consists of some lines that connect some points on a rose curve.

 

What does rose mean in math?

In mathematics, a rose or rhodonea curve is a sinusoid with no phase angle that is displayed in polar coordinates and described by either the cosine or sine functions. Rose curves, or "rhodonea," were named by Guido Grandi, an Italian mathematician who researched them between 1723 and 1728.

 

Why is it called a rose curve?

Rose curves are named after the loops they form, which resemble petals. The number of petals will be determined by the value of n.

Conclusion

In this article, we have extensively discussed Rhodonea Curves and Maurer Rose in Python.

We hope that this blog has helped you enhance your knowledge about Rhodonea Curves and Maurer Rose and if you would like to learn more, check out our articles on our Website.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problems, interview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass