2020-07-11 03:50:25 +08:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2022-09-08 08:17:03 +08:00
< html xmlns = "http://www.w3.org/1999/xhtml" lang = "en-US" >
2020-07-11 03:50:25 +08:00
< head >
< meta http-equiv = "Content-Type" content = "text/xhtml;charset=UTF-8" / >
2021-10-26 03:34:27 +08:00
< meta http-equiv = "X-UA-Compatible" content = "IE=11" / >
2022-09-08 08:17:03 +08:00
< meta name = "generator" content = "Doxygen 1.9.5" / >
2020-07-11 03:50:25 +08:00
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< title > Algorithms_in_C: graphics/spirograph.c File Reference< / title >
< link href = "../../tabs.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../jquery.js" > < / script >
< script type = "text/javascript" src = "../../dynsections.js" > < / script >
< link href = "../../navtree.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../resize.js" > < / script >
< script type = "text/javascript" src = "../../navtreedata.js" > < / script >
< script type = "text/javascript" src = "../../navtree.js" > < / script >
< link href = "../../search/search.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../search/searchdata.js" > < / script >
< script type = "text/javascript" src = "../../search/search.js" > < / script >
< script type = "text/x-mathjax-config" >
2021-10-26 03:34:27 +08:00
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
2020-07-11 03:50:25 +08:00
});
< / script >
< script type = "text/javascript" async = "async" src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js" > < / script >
< link href = "../../doxygen.css" rel = "stylesheet" type = "text/css" / >
< / head >
< body >
< div id = "top" > <!-- do not remove this div, it is closed by doxygen! -->
< div id = "titlearea" >
< table cellspacing = "0" cellpadding = "0" >
< tbody >
2022-01-15 04:11:27 +08:00
< tr id = "projectrow" >
< td id = "projectalign" >
2021-10-26 03:34:27 +08:00
< div id = "projectname" > Algorithms_in_C< span id = "projectnumber" >   1.0.0< / span >
2020-07-11 03:50:25 +08:00
< / div >
< div id = "projectbrief" > Set of algorithms implemented in C.< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2022-09-08 08:17:03 +08:00
<!-- Generated by Doxygen 1.9.5 -->
2020-07-11 03:50:25 +08:00
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2022-09-08 08:17:03 +08:00
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
2020-07-11 03:50:25 +08:00
/* @license-end */
< / script >
< script type = "text/javascript" src = "../../menudata.js" > < / script >
< script type = "text/javascript" src = "../../menu.js" > < / script >
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2020-07-11 03:50:25 +08:00
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
2021-10-26 03:34:27 +08:00
/* @license-end */
< / script >
2020-07-11 03:50:25 +08:00
< div id = "main-nav" > < / div >
< / div > <!-- top -->
< div id = "side-nav" class = "ui-resizable side-nav-resizable" >
< div id = "nav-tree" >
< div id = "nav-tree-contents" >
< div id = "nav-sync" class = "sync" > < / div >
< / div >
< / div >
< div id = "splitbar" style = "-moz-user-select:none;"
class="ui-resizable-handle">
< / div >
< / div >
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2020-07-11 03:50:25 +08:00
$(document).ready(function(){initNavTree('d7/d98/spirograph_8c.html','../../'); initResizable(); });
/* @license-end */
< / script >
< div id = "doc-content" >
<!-- window showing the filter options -->
< div id = "MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
< / div >
<!-- iframe showing the search results (closed by default) -->
< div id = "MSearchResultsWindow" >
2022-09-08 08:17:03 +08:00
< div id = "MSearchResults" >
< div class = "SRPage" >
< div id = "SRIndex" >
< div id = "SRResults" > < / div >
< div class = "SRStatus" id = "Loading" > Loading...< / div >
< div class = "SRStatus" id = "Searching" > Searching...< / div >
< div class = "SRStatus" id = "NoMatches" > No Matches< / div >
< / div >
< / div >
< / div >
2020-07-11 03:50:25 +08:00
< / div >
< div class = "header" >
< div class = "summary" >
< a href = "#define-members" > Macros< / a > |
< a href = "#func-members" > Functions< / a > < / div >
2021-10-26 03:34:27 +08:00
< div class = "headertitle" > < div class = "title" > spirograph.c File Reference< / div > < / div >
2020-07-11 03:50:25 +08:00
< / div > <!-- header -->
< div class = "contents" >
2021-10-26 03:34:27 +08:00
< p > Implementation of < a href = "https://en.wikipedia.org/wiki/Spirograph" target = "_blank" > Spirograph< / a >
2020-07-11 03:50:25 +08:00
< a href = "#details" > More...< / a > < / p >
< div class = "textblock" > < code > #include < math.h> < / code > < br / >
< code > #include < stdbool.h> < / code > < br / >
< code > #include < stdio.h> < / code > < br / >
< code > #include < stdlib.h> < / code > < br / >
< code > #include < time.h> < / code > < br / >
< / div > < div class = "textblock" > < div class = "dynheader" >
Include dependency graph for spirograph.c:< / div >
< div class = "dyncontent" >
2022-09-08 08:17:03 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../da/dd5/spirograph_8c__incl.svg" width = "430" height = "110" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2020-07-11 03:50:25 +08:00
< / div >
< / div >
< / div > < table class = "memberdecls" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "define-members" name = "define-members" > < / a >
2020-07-11 03:50:25 +08:00
Macros< / h2 > < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a525335710b53cb064ca56b936120431e" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a525335710b53cb064ca56b936120431e" name = "a525335710b53cb064ca56b936120431e" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < b > _USE_MATH_DEFINES< / b > < / td > < / tr >
2020-07-11 03:50:25 +08:00
< tr class = "memdesc:a525335710b53cb064ca56b936120431e" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > required for MSVC compiler < br / > < / td > < / tr >
< tr class = "separator:a525335710b53cb064ca56b936120431e" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "func-members" name = "func-members" > < / a >
2020-07-11 03:50:25 +08:00
Functions< / h2 > < / td > < / tr >
2020-07-17 04:36:47 +08:00
< tr class = "memitem:a0daa148091ec953809fc172289f773d3" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d98/spirograph_8c.html#a0daa148091ec953809fc172289f773d3" > spirograph< / a > (double *x, double *y, double l, double k, size_t N, double rot)< / td > < / tr >
2020-07-11 03:50:25 +08:00
< tr class = "memdesc:a0daa148091ec953809fc172289f773d3" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Generate spirograph curve into arrays < code > x< / code > and < code > y< / code > such that the i^th point in 2D is represented by < code > (x[i],y[i])< / code > . < a href = "../../d7/d98/spirograph_8c.html#a0daa148091ec953809fc172289f773d3" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a0daa148091ec953809fc172289f773d3" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a708a4c1a4d0c4acc4c447310dd4db27f" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d98/spirograph_8c.html#a708a4c1a4d0c4acc4c447310dd4db27f" > test< / a > (void)< / td > < / tr >
< tr class = "memdesc:a708a4c1a4d0c4acc4c447310dd4db27f" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Test function to save resulting points to a CSV file. < a href = "../../d7/d98/spirograph_8c.html#a708a4c1a4d0c4acc4c447310dd4db27f" > More...< / a > < br / > < / td > < / tr >
2020-07-11 03:50:25 +08:00
< tr class = "separator:a708a4c1a4d0c4acc4c447310dd4db27f" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memItemLeft" align = "right" valign = "top" > int  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d98/spirograph_8c.html#a3c04138a5bfe5d72780bb7e82a18e627" > main< / a > (int argc, char **argv)< / td > < / tr >
< tr class = "memdesc:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Main function. < a href = "../../d7/d98/spirograph_8c.html#a3c04138a5bfe5d72780bb7e82a18e627" > More...< / a > < br / > < / td > < / tr >
2020-07-11 03:50:25 +08:00
< tr class = "separator:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
2021-10-26 03:34:27 +08:00
< div class = "textblock" > < p > Implementation of < a href = "https://en.wikipedia.org/wiki/Spirograph" target = "_blank" > Spirograph< / a > < / p >
2022-09-08 08:17:03 +08:00
< dl class = "section author" > < dt > Author< / dt > < dd > < a href = "https://github.com/kvedala" target = "_blank" > Krishna Vedala< / a > < / dd > < / dl >
2020-07-11 03:50:25 +08:00
< p > Implementation of the program is based on the geometry shown in the figure below:< / p >
2021-10-26 03:34:27 +08:00
< p > < a href = "https://commons.wikimedia.org/wiki/File:Resonance_Cascade.svg" > < img src = "https://upload.wikimedia.org/wikipedia/commons/3/39/Resonance_Cascade.svg" alt = "Spirograph geometry from Wikipedia" style = "pointer-events: none; width: 250px" class = "inline" / > < / a > < / p >
2020-07-11 03:50:25 +08:00
< / div > < h2 class = "groupheader" > Function Documentation< / h2 >
2021-10-26 03:34:27 +08:00
< a id = "a3c04138a5bfe5d72780bb7e82a18e627" name = "a3c04138a5bfe5d72780bb7e82a18e627" > < / a >
2022-09-08 08:17:03 +08:00
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a3c04138a5bfe5d72780bb7e82a18e627" > ◆   < / a > < / span > main()< / h2 >
2021-10-26 03:34:27 +08:00
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > int main < / td >
< td > (< / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > argc< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > char **  < / td >
< td class = "paramname" > < em > argv< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Main function. < / p >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 272< / span > {< / div >
< div class = "line" > < span class = "lineno" > 273< / span > < a class = "code hl_function" href = "../../d7/d98/spirograph_8c.html#a708a4c1a4d0c4acc4c447310dd4db27f" > test< / a > ();< / div >
< div class = "line" > < span class = "lineno" > 274< / span > < / div >
< div class = "line" > < span class = "lineno" > 275< / span > < span class = "preprocessor" > #ifdef USE_GLUT< / span > < / div >
< div class = "line" > < span class = "lineno" > 276< / span > glutInit(& argc, argv);< / div >
< div class = "line" > < span class = "lineno" > 277< / span > glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);< / div >
< div class = "line" > < span class = "lineno" > 278< / span > glutCreateWindow(< span class = "stringliteral" > " Spirograph" < / span > );< / div >
< div class = "line" > < span class = "lineno" > 279< / span > glutInitWindowSize(400, 400);< / div >
< div class = "line" > < span class = "lineno" > 280< / span > < span class = "comment" > // glutIdleFunc(glutPostRedisplay);< / span > < / div >
< div class = "line" > < span class = "lineno" > 281< / span > glutTimerFunc(animation_speed, timer_cb, 0);< / div >
< div class = "line" > < span class = "lineno" > 282< / span > glutKeyboardFunc(keyboard_cb);< / div >
2022-09-08 08:17:03 +08:00
< div class = "line" > < span class = "lineno" > 283< / span > glutDisplayFunc(< a class = "code hl_function" href = "../../d6/d76/k__means__clustering_8c.html#a0283886819c7c140a023582b7269e2d0" > test2< / a > );< / div >
2022-01-15 04:11:27 +08:00
< div class = "line" > < span class = "lineno" > 284< / span > glutMainLoop();< / div >
< div class = "line" > < span class = "lineno" > 285< / span > < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < span class = "lineno" > 286< / span > < / div >
< div class = "line" > < span class = "lineno" > 287< / span > < span class = "keywordflow" > return< / span > 0;< / div >
< div class = "line" > < span class = "lineno" > 288< / span > }< / div >
2022-09-08 08:17:03 +08:00
< div class = "ttc" id = "ak__means__clustering_8c_html_a0283886819c7c140a023582b7269e2d0" > < div class = "ttname" > < a href = "../../d6/d76/k__means__clustering_8c.html#a0283886819c7c140a023582b7269e2d0" > test2< / a > < / div > < div class = "ttdeci" > void test2()< / div > < div class = "ttdef" > < b > Definition:< / b > k_means_clustering.c:356< / div > < / div >
2021-10-26 03:34:27 +08:00
< div class = "ttc" id = "aspirograph_8c_html_a708a4c1a4d0c4acc4c447310dd4db27f" > < div class = "ttname" > < a href = "../../d7/d98/spirograph_8c.html#a708a4c1a4d0c4acc4c447310dd4db27f" > test< / a > < / div > < div class = "ttdeci" > void test(void)< / div > < div class = "ttdoc" > Test function to save resulting points to a CSV file.< / div > < div class = "ttdef" > < b > Definition:< / b > spirograph.c:74< / div > < / div >
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2022-09-08 08:17:03 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d7/d98/spirograph_8c_a3c04138a5bfe5d72780bb7e82a18e627_cgraph.svg" width = "462" height = "135" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2021-10-26 03:34:27 +08:00
< / div >
< / div >
< / div >
< / div >
< a id = "a0daa148091ec953809fc172289f773d3" name = "a0daa148091ec953809fc172289f773d3" > < / a >
2022-09-08 08:17:03 +08:00
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a0daa148091ec953809fc172289f773d3" > ◆   < / a > < / span > spirograph()< / h2 >
2020-07-11 03:50:25 +08:00
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void spirograph < / td >
< td > (< / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > x< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > y< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double  < / td >
< td class = "paramname" > < em > l< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double  < / td >
< td class = "paramname" > < em > k< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > size_t  < / td >
< td class = "paramname" > < em > N< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double  < / td >
< td class = "paramname" > < em > rot< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Generate spirograph curve into arrays < code > x< / code > and < code > y< / code > such that the i^th point in 2D is represented by < code > (x[i],y[i])< / code > . < / p >
2022-09-08 08:17:03 +08:00
< p > The generating function is given by: < / p > < p class = "formulaDsp" >
2022-06-08 02:13:03 +08:00
\begin{eqnarray*}
x & =& R\left[ (1-k) \cos (t) + l\cdot k\cdot\cos \left(\frac{1-k}{k}t\right)
\right]\\
y & =& R\left[ (1-k) \sin (t) - l\cdot k\cdot\sin \left(\frac{1-k}{k}t\right)
\right] \end{eqnarray*}
2020-07-11 03:50:25 +08:00
< / p >
< p > where< / p > < ul >
< li > \(R\) is the scaling parameter that we will consider \(=1\)< / li >
< li > \(l=\frac{\rho}{r}\) is the relative distance of marker from the centre of inner circle and \(0\le l\le1\)< / li >
< li > \(\rho\) is physical distance of marker from centre of inner circle< / li >
< li > \(r\) is the radius of inner circle< / li >
< li > \(k=\frac{r}{R}\) is the ratio of radius of inner circle to outer circle and \(0< k< 1\)< / li >
< li > \(R\) is the radius of outer circle< / li >
< li > \(t\) is the angle of rotation of the point i.e., represents the time parameter< / li >
< / ul >
2021-10-26 03:34:27 +08:00
< p > Since we are considering ratios, the actual values of \(r\) and \(R\) are immaterial.< / p >
2020-07-11 03:50:25 +08:00
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [out]< / td > < td class = "paramname" > x< / td > < td > output array containing absicca of points (must be pre-allocated) < / td > < / tr >
< tr > < td class = "paramdir" > [out]< / td > < td class = "paramname" > y< / td > < td > output array containing ordinates of points (must be pre-allocated) < / td > < / tr >
< tr > < td class = "paramdir" > < / td > < td class = "paramname" > l< / td > < td > the relative distance of marker from the centre of inner circle and \(0\le l\le1\) < / td > < / tr >
< tr > < td class = "paramdir" > < / td > < td class = "paramname" > k< / td > < td > the ratio of radius of inner circle to outer circle and \(0< k< 1\) < / td > < / tr >
< tr > < td class = "paramdir" > < / td > < td class = "paramname" > N< / td > < td > number of sample points along the trajectory (higher = better resolution but consumes more time and memory) < / td > < / tr >
< tr > < td class = "paramdir" > < / td > < td class = "paramname" > num_rot< / td > < td > the number of rotations to perform (can be fractional value) < / td > < / tr >
< / table >
< / dd >
< / dl >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 58< / span > {< / div >
< div class = "line" > < span class = "lineno" > 59< / span > < span class = "keywordtype" > double< / span > dt = rot * 2.f * M_PI / N;< / div >
< div class = "line" > < span class = "lineno" > 60< / span > < span class = "keywordtype" > double< / span > t = 0.f, R = 1.f;< / div >
< div class = "line" > < span class = "lineno" > 61< / span > < span class = "keyword" > const< / span > < span class = "keywordtype" > double< / span > k1 = 1.f - k;< / div >
< div class = "line" > < span class = "lineno" > 62< / span > < / div >
< div class = "line" > < span class = "lineno" > 63< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > dk = 0; dk < N; dk++, t += dt)< / div >
< div class = "line" > < span class = "lineno" > 64< / span > {< / div >
< div class = "line" > < span class = "lineno" > 65< / span > x[dk] = R * (k1 * cos(t) + l * k * cos(k1 * t / k));< / div >
< div class = "line" > < span class = "lineno" > 66< / span > y[dk] = R * (k1 * sin(t) - l * k * sin(k1 * t / k));< / div >
< div class = "line" > < span class = "lineno" > 67< / span > }< / div >
< div class = "line" > < span class = "lineno" > 68< / span > }< / div >
2020-07-11 03:50:25 +08:00
< / div > <!-- fragment -->
2021-10-26 03:34:27 +08:00
< / div >
< / div >
< a id = "a708a4c1a4d0c4acc4c447310dd4db27f" name = "a708a4c1a4d0c4acc4c447310dd4db27f" > < / a >
2022-09-08 08:17:03 +08:00
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a708a4c1a4d0c4acc4c447310dd4db27f" > ◆   < / a > < / span > test()< / h2 >
2021-10-26 03:34:27 +08:00
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void test < / td >
< td > (< / td >
< td class = "paramtype" > void  < / td >
< td class = "paramname" > < / td > < td > )< / td >
< td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Test function to save resulting points to a CSV file. < / p >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 75< / span > {< / div >
< div class = "line" > < span class = "lineno" > 76< / span > < span class = "keywordtype" > size_t< / span > N = 500;< / div >
< div class = "line" > < span class = "lineno" > 77< / span > < span class = "keywordtype" > double< / span > l = 0.3, k = 0.75, rot = 10.;< / div >
< div class = "line" > < span class = "lineno" > 78< / span > < span class = "keywordtype" > char< / span > fname[50];< / div >
< div class = "line" > < span class = "lineno" > 79< / span > snprintf(fname, 50, < span class = "stringliteral" > " spirograph_%.2f_%.2f_%.2f.csv" < / span > , l, k, rot);< / div >
< div class = "line" > < span class = "lineno" > 80< / span > FILE *fp = fopen(fname, < span class = "stringliteral" > " wt" < / span > );< / div >
< div class = "line" > < span class = "lineno" > 81< / span > < span class = "keywordflow" > if< / span > (!fp)< / div >
< div class = "line" > < span class = "lineno" > 82< / span > {< / div >
< div class = "line" > < span class = "lineno" > 83< / span > perror(fname);< / div >
< div class = "line" > < span class = "lineno" > 84< / span > exit(EXIT_FAILURE);< / div >
< div class = "line" > < span class = "lineno" > 85< / span > }< / div >
< div class = "line" > < span class = "lineno" > 86< / span > < / div >
< div class = "line" > < span class = "lineno" > 87< / span > < span class = "keywordtype" > double< / span > *x = (< span class = "keywordtype" > double< / span > *)< a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee" > malloc< / a > (N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > ));< / div >
< div class = "line" > < span class = "lineno" > 88< / span > < span class = "keywordtype" > double< / span > *y = (< span class = "keywordtype" > double< / span > *)< a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee" > malloc< / a > (N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > ));< / div >
< div class = "line" > < span class = "lineno" > 89< / span > < / div >
< div class = "line" > < span class = "lineno" > 90< / span > < a class = "code hl_function" href = "../../d7/d98/spirograph_8c.html#a0daa148091ec953809fc172289f773d3" > spirograph< / a > (x, y, l, k, N, rot);< / div >
< div class = "line" > < span class = "lineno" > 91< / span > < / div >
< div class = "line" > < span class = "lineno" > 92< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < N; i++)< / div >
< div class = "line" > < span class = "lineno" > 93< / span > {< / div >
< div class = "line" > < span class = "lineno" > 94< / span > fprintf(fp, < span class = "stringliteral" > " %.5g, %.5g" < / span > , x[i], y[i]);< / div >
< div class = "line" > < span class = "lineno" > 95< / span > < span class = "keywordflow" > if< / span > (i < N - 1)< / div >
< div class = "line" > < span class = "lineno" > 96< / span > {< / div >
< div class = "line" > < span class = "lineno" > 97< / span > fputc(< span class = "charliteral" > ' \n' < / span > , fp);< / div >
< div class = "line" > < span class = "lineno" > 98< / span > }< / div >
< div class = "line" > < span class = "lineno" > 99< / span > }< / div >
< div class = "line" > < span class = "lineno" > 100< / span > < / div >
< div class = "line" > < span class = "lineno" > 101< / span > fclose(fp);< / div >
< div class = "line" > < span class = "lineno" > 102< / span > < / div >
< div class = "line" > < span class = "lineno" > 103< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (x);< / div >
< div class = "line" > < span class = "lineno" > 104< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (y);< / div >
< div class = "line" > < span class = "lineno" > 105< / span > }< / div >
2021-10-26 03:34:27 +08:00
< div class = "ttc" id = "amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee" > < div class = "ttname" > < a href = "../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee" > malloc< / a > < / div > < div class = "ttdeci" > #define malloc(bytes)< / div > < div class = "ttdoc" > This macro replace the standard malloc function with malloc_dbg.< / div > < div class = "ttdef" > < b > Definition:< / b > malloc_dbg.h:18< / div > < / div >
< div class = "ttc" id = "amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768" > < div class = "ttname" > < a href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > < / div > < div class = "ttdeci" > #define free(ptr)< / div > < div class = "ttdoc" > This macro replace the standard free function with free_dbg.< / div > < div class = "ttdef" > < b > Definition:< / b > malloc_dbg.h:26< / div > < / div >
< div class = "ttc" id = "aspirograph_8c_html_a0daa148091ec953809fc172289f773d3" > < div class = "ttname" > < a href = "../../d7/d98/spirograph_8c.html#a0daa148091ec953809fc172289f773d3" > spirograph< / a > < / div > < div class = "ttdeci" > void spirograph(double *x, double *y, double l, double k, size_t N, double rot)< / div > < div class = "ttdoc" > Generate spirograph curve into arrays x and y such that the i^th point in 2D is represented by (x[i],...< / div > < div class = "ttdef" > < b > Definition:< / b > spirograph.c:57< / div > < / div >
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2022-09-08 08:17:03 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d7/d98/spirograph_8c_a708a4c1a4d0c4acc4c447310dd4db27f_cgraph.svg" width = "186" height = "36" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2021-10-26 03:34:27 +08:00
< / div >
< / div >
2020-07-11 03:50:25 +08:00
< / div >
< / div >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
<!-- start footer part -->
< div id = "nav-path" class = "navpath" > <!-- id is needed for treeview function! -->
< ul >
< li class = "navelem" > < a class = "el" href = "../../dir_e79632891301b850df87e9c0030293fa.html" > graphics< / a > < / li > < li class = "navelem" > < a class = "el" href = "../../d7/d98/spirograph_8c.html" > spirograph.c< / a > < / li >
2022-09-08 08:17:03 +08:00
< li class = "footer" > Generated by < a href = "https://www.doxygen.org/index.html" > < img class = "footer" src = "../../doxygen.svg" width = "104" height = "31" alt = "doxygen" / > < / a > 1.9.5 < / li >
2020-07-11 03:50:25 +08:00
< / ul >
< / div >
< / body >
< / html >