# Spiral Art

The basic idea behind a spiral is to parametrize like this.......

$x = r \cos \theta \\ y = r \sin \theta$

....and then gradually decrease the radius as the angle increases. To make things more interesting, you can put sinusoidal variation in the radius too, with different harmonics thrown in to create different effects. The harmonics are added so that their magnitudes are inversely proportional to their frequency, relative to the base frequency. For example, a sinusoidal term with a frequency three times that of the base term has a magnitude one third that of the base term.

I have posted two spirals: one with even harmonics and one with odd harmonics. The code to generate these is also attached. Click the images to enlarge them.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import math r = 20.0 theta = 0.0 dr = 0.005 dtheta = 2.0*math.pi/400.0 choose = 0 while theta <= 20.0*math.pi: if choose == 0: # Even harmonic spiral x = r*(1.0 + 0.2*math.sin(20.0*theta) + 0.1*math.sin(40.0*theta) + 0.05*math.sin(80.0*theta))*math.cos(theta) y = r*(1.0 + 0.2*math.sin(20.0*theta) + 0.1*math.sin(40.0*theta) + 0.05*math.sin(80.0*theta))*math.sin(theta) if choose == 1: # Odd harmonic spiral x = r*(1.0 + 0.2*math.sin(20.0*theta) + 0.0667*math.sin(60.0*theta) + 0.04*math.sin(100.0*theta))*math.cos(theta) y = r*(1.0 + 0.2*math.sin(20.0*theta) + 0.0667*math.sin(60.0*theta) + 0.04*math.sin(100.0*theta))*math.sin(theta) print x,y r = r - dr theta = theta + dtheta 

Note by Steven Chase
1 year, 1 month ago

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

• Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
• Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
• Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold
- bulleted- list
• bulleted
• list
1. numbered2. list
1. numbered
2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in $$ ... $$ or $ ... $ to ensure proper formatting.
2 \times 3 $2 \times 3$
2^{34} $2^{34}$
a_{i-1} $a_{i-1}$
\frac{2}{3} $\frac{2}{3}$
\sqrt{2} $\sqrt{2}$
\sum_{i=1}^3 $\sum_{i=1}^3$
\sin \theta $\sin \theta$
\boxed{123} $\boxed{123}$

Sort by:

@Karan Chatrath In case you are interested

- 1 year, 1 month ago

@Steven Chase Sir .Thanks Yeah it's also awesome. But I like your profile images more than this. They were more crazy according to my opinion.

- 1 year, 1 month ago

Creating the profile pic must have been much harder, due to the wireframe and the 3d aspect of it, that too on python.

- 1 year, 1 month ago

Yeah, the helix was a much bigger undertaking

- 1 year, 1 month ago

Yeah and the rendering time without GPU wow...

- 1 year, 1 month ago

@Steven Chase when I copied this code and run in my computer and plotted in excel I get this image

- 11 months, 3 weeks ago

Hmmm... that's interesting... what do you think the error might be?

- 11 months, 3 weeks ago

@Krishna Karthik Bro I don't know, can you run in your computer and reply me what you are getting. Thanks in advance

- 11 months, 3 weeks ago

Of course! cheers.

- 11 months, 3 weeks ago

@Krishna Karthik bro i am waiting for your comment .what are you getting while running the above code ??

- 11 months, 3 weeks ago

I get the same thing as Steven did. I think you have copied the code wrong.

- 11 months, 3 weeks ago

@Krishna Karthik ok bro let me try again. thanks

btw if you don't mind ,please call him as Steven sir .they are older than us.

- 11 months, 3 weeks ago

Bro, this is the internet. People are called informally on the internet. Unless they specifically say against that, I am going to just call them by first name.

I think it's some sort of an Indian custom to suffix with sir for someone older. Maybe I'll refer to him as sir if I directly address them.

- 11 months, 3 weeks ago

@Krishna Karthik as you wish bro.it is your choice .

He has helped me so much in physics and maths ,so its my respect for him

- 11 months, 3 weeks ago

Very true. He has pointed me to so many resources, really great person. He helped me with classical mechanics and inspired me to learn numerical technique. I do respect him a lot. I will address him as sir when I speak to him. Thanks bro, cheers! :)

- 11 months, 3 weeks ago

Oh, I think I noticed the error and why the graph is not showing the correct thing. Have you perhaps only chosen one of the columns? Make sure you select both and look at the line, not the line with dots (as it will clutter).

- 11 months, 3 weeks ago

Ha that's really cool! I really like python. Try to paint a Mandelbrot Set!

- 1 year, 1 month ago

Here you go

- 1 year, 1 month ago

I think the second spiral looks the best. I really love how it spirals inward.

- 1 year, 1 month ago

@Steven Chase sir the code which you have provided above.
i run this code and when plotted in excel and was not giving the figure which is above .

- 11 months, 3 weeks ago

Highlight both columns and then plot as a scatter with smooth lines

- 11 months, 3 weeks ago

precicely, sir. That's what I think the error is too. Scattering with dots will create clutter too.

- 11 months, 3 weeks ago

Yup, buddy, I think you haven't underlined both columns. Plot with smooth lines too.

- 11 months, 3 weeks ago

@Steven Chase sir i have highlighted both columns many times
I am getting this only

- 11 months, 3 weeks ago

Nope, it still only shows one column.

- 11 months, 3 weeks ago

put a variable (x) on the x column, $y$ on the $y$ column ABOVE the columns; click on $x$, hold, and drag it all the way down to the end and click on the smooth line chart.

- 11 months, 3 weeks ago

You should have names above each column. The column on the left will automatically be identified as the independent variable, and the right the dependent.

- 11 months, 3 weeks ago

Click on the left column's name and drag it down, highlighting both columns.

- 11 months, 3 weeks ago

@Krishna Karthik thanks sir but why image above is more clear than my pC image

- 11 months, 3 weeks ago

You can re-size the plot and make the lines thinner

- 11 months, 3 weeks ago

Ah, I was having the same problem too with thick lines. Thanks sir!

- 11 months, 3 weeks ago

@Steven Chase sir which option should i choose to make it thin

- 11 months, 3 weeks ago

Hey, do you use Windows 7 or 10?

- 11 months, 3 weeks ago

- 11 months, 3 weeks ago

Yeah, I thought so. Is that a Dell laptop?

- 11 months, 3 weeks ago

You should upgrade it. I kinda miss Windows 7 though lol now that I upgraded my PC... =..(

- 11 months, 3 weeks ago

@Krishna Karthik windows 10 have more features than 7?
if yes how can i upgrade

- 11 months, 3 weeks ago

Windows 7 is really outdated now; but Windows 10 is expensive. It's not extremely worth it or anything, but next time you get a PC you will automatically have Windows 10 with it =)

- 11 months, 3 weeks ago

@Steven Chase yeah now it is coming

- 11 months, 3 weeks ago

Perfect! Good stuff mate.

- 11 months, 3 weeks ago

Yeah, the reason we are seeing the visible damping in x and y is because of the spiral.

- 11 months, 3 weeks ago

@Steven Chase sir how do you export that image ???

- 11 months, 3 weeks ago

Hit the print screen button and then paste it into MS Paint. Then you can crop out the stuff you don't want

- 11 months, 3 weeks ago

Ah, that is much better than taking a cropped screenshot. It gets so low res for me when I take a cropped screenshot. Thanks for suggesting me the better alternative. Will use MS paint.

- 11 months, 3 weeks ago

Yeah, that's what I was wondering as well. I just take screenshots.

- 11 months, 3 weeks ago

@Krishna Karthik taking screenshot loses the quality if image

- 11 months, 3 weeks ago

You can put it onto MS Paint and crop out the rubbish. That's a better way. No losing of res.

- 11 months, 3 weeks ago