Colored Cyclic-Harmonic Curve
This page shows some examples of colored cyclic-harmonic curves applied the golden ratio. This page also publishes the SageMath script to create the example figures.
(There is the Japanese(日本語) page.)
(Last updated date: February 21, 2021)
Preface
I colored the curves introduced on the Cyclic-harmonic curve page. Some examples are shown below.
In addition, the SageMath script to create the example figures is shown in the last half of this page.
Colored cyclic-harmonic curves
The formula of cyclic-harmonic curve to draw the figures is shown below.
\[r = \cos \left( \frac{n}{d} \, \theta \right) + \sqrt{5} -2\]
By substituting various positive integers for \(n\) and \(d\) in this formula ( \(n \geq d\) ) , the figures of cyclic-harmonic curves applied the golden ratio can be drawn. For details about this formula, see the Cyclic-harmonic curve page.
The examples of cyclic-harmonic curves filled with color are shown below.
Example 1 : \(n=3\) , \(d=1\)
In the script created this time, for each petal, the individual color and alpha channel (transparency) can be specified.
In this example, ‘orange’ is specified to all petal colors, 0.3 to the alpha of the large petals, and 0.45 to the alpha of the small petals.
In this example, all of the small petals overlap the large petals. As a result, the color of the small petals appears to be darker than the specified alpha (transparency).
Example 2 : \(n=5\) , \(d=3\)
- The color of all petals: ‘springgreen’
- The alpha of the large petals: 0.25
- The alpha of the small petals: 0.5
Example 3 : \(n=17\) , \(d=3\)
- The color of all petals: ‘magenta’
- The alpha of the large petals: 0.3
- The alpha of the small petals: 0.35
Example 4 : \(n=17\) , \(d=6\)
- The color of all petals: ‘deepskyblue’
- The alpha of the large petals: 0.2
- The alpha of the small petals: 0.35
Example 5 : \(n=17\) , \(d=13\)
- The color of all petals: ‘blue’
- The alpha of the large petals: 0.1
- The alpha of the small petals: 0.12
Example 6 : \(n=28\) , \(d=5\)
In this example, ‘red’ and ‘magenta’ are alternately specified to the color of the petals. It be similarly done for both large and small petals. Then, 0.3 is specified to the alpha of the large petals, and 0.35 to the alpha of the small petals.
Example 7 : \(n=34\) , \(d=5\)
- The color of both large and small petals: the alternate ‘gold’ and ‘lime’
- The alpha of the large petals: 0.35
- The alpha of the small petals: 0.6
Example 8 : \(n=49\) , \(d=6\)
In this example, the seven colors of the rainbow are used. In SageMath, there is the ‘rainbow’ function that creates a list of rainbow colors. The argument of this function is the number of colors to output. An example of executing this function is shown below.
sage: rainbow(7)
['#ff0000', '#ffda00', '#48ff00', '#00ff91', '#0091ff', '#4800ff', '#ff00da']
The seven colors output in this execution example are repeatedly specified in this order to the colors of the large petals. Similarly, the seven colors are basically specified to the colors of the small petals, but some colors are modified to balance the apparent intensity between the colors. For the same reason, the adjusted values are individually specified to the alpha of the large and small petals.
The table below lists the colors and alpha values specified in this example.
color of large petal | ff0000 | ffda00 | 48ff00 | 00ff91 | 0091ff | 4800ff | ff00da |
alpha of large petal | 0.15 | 0.35 | 0.35 | 0.35 | 0.15 | 0.15 | 0.15 |
color of small petal | ff0000 | f5d100 | 41e600 | 00e884 | 0091ff | 4800ff | ff00da |
alpha of small petal | 0.3 | 0.75 | 0.75 | 0.75 | 0.3 | 0.3 | 0.3 |
Script to create figures of colored cyclic-harmonic curves
The following is the SageMath script to create all the figures above.
# This file is tested with SageMath 9.1.
# Create a symbolic variable 'θ'
var('θ')
def make_chc(numer, denom, get_petal_color):
'''Make the Cyclic-Harmonic Curve filled with color
:param numer: numerator
:param denom: denominator
'''
# The number of petals
# (The number of large and small petals is the same.)
petal_num = numer / gcd(numer, denom)
# The interval of petals
petal_inter = (2*denom*pi) / petal_num
# The first answer of Cyclic-Harmonic Curve equation (self = 0)
first_ans = arccos(-sqrt(5)+2) / (numer/denom)
# Make graphics objects
g = Graphics()
for k in srange(petal_num):
# The starting and ending values of the kth large petal
large_start = (k * petal_inter) - first_ans
large_end = (k * petal_inter) + first_ans
# The starting and ending values of the kth small petal
small_start = large_end
small_end = ((k + 1) * petal_inter) - first_ans
# The color and alpha (transparency) of large and small petals
large_color, large_alpha, small_color, small_alpha = get_petal_color(k)
def get_petal_plot(petal_start, petal_end, petal_color, petal_alpha):
'''Get the plotting object of the petal
'''
return polar_plot( cos((numer/denom)*θ)+sqrt(5)-2, \
(θ, petal_start, petal_end), axes=False, thickness=0, \
fill=True, fillcolor=petal_color, fillalpha=petal_alpha)
# Plotting the kth large and small petals
g+= get_petal_plot(large_start, large_end, large_color, large_alpha)
g+= get_petal_plot(small_start, small_end, small_color, small_alpha)
# Save the figure file
g.save('chc-' + str(numer) + '-' + str(denom) + '.svg')
# Make some Cyclic-Harmonic Curves filled with color
make_chc( 3, 1, lambda k: ('orange' , 0.3 , 'orange' , 0.45))
make_chc( 5, 3, lambda k: ('springgreen', 0.25, 'springgreen', 0.5 ))
make_chc(17, 3, lambda k: ('magenta' , 0.3 , 'magenta' , 0.35))
make_chc(17, 6, lambda k: ('deepskyblue', 0.2 , 'deepskyblue', 0.35))
make_chc(17, 13, lambda k: ('blue' , 0.1 , 'blue' , 0.12))
make_chc(28, 5, lambda k: (['red' , 'magenta'][k % 2], 0.3 , \
['red' , 'magenta'][k % 2], 0.35))
make_chc(34, 5, lambda k: (['gold', 'lime' ][k % 2], 0.35, \
['gold', 'lime' ][k % 2], 0.6 ))
# Make the Cyclic-Harmonic Curve filled with rainbow colors
# (The first array is made from the function `rainbow(7)`.)
make_chc(49, 6, lambda k: ( \
['#ff0000', '#ffda00', '#48ff00', '#00ff91', '#0091ff', '#4800ff', \
'#ff00da'][k % 7], \
[0.15, 0.35, 0.35, 0.35, 0.15, 0.15, 0.15][k % 7], \
['#ff0000', '#f5d100', '#41e600', '#00e884', '#0091ff', '#4800ff', \
'#ff00da'][k % 7], \
[0.3 , 0.75, 0.75, 0.75, 0.3 , 0.3 , 0.3 ][k % 7]))
The formula used in this script is the same as the one described on the Cyclic-harmonic curve page.
In the SageMath script on the Cyclic-harmonic curve page, the entire curve is drawn at once. On the other hand, in this script, in order to specify the individual color and alpha value for each petal, the entire curve is not drawn at once, but the petals are drawn one by one.
Comments
Post a Comment