Video Demo: <URL HERE>
The name of my project is snowflake generator, and it is a command line program written in c. As the name suggests, this program was designed to generate random snowflake designs, which are displayed on a bitmap image. To run this porgram, the user has to type the command ./snow. The program will generate a random design. The user can then view the design by opening the bitmap image
Please note that I am a beginner and currently in the process of learning and improving my coding skills, so some of the code in this repository may be messy, inefficient, or not follow best practices. I am actively working to refine my skills and improve the code over time, so any feedback or suggestions are welcome!
The actual snowflake is generated by calling a function in snow.c called makeflake(). This is a recursive function that creates snowflake brances. each call generates a main branch with at least one sub brunch. pattern by drawing a series of lines at different lengths and angles, with the help of the drawline() function. the drawline function takes a struct called point as one of its arguments and returns another point, the endpoint of the generated line. The drawline function also has an angle argument. This allows makeflake to create a sub branch at any angle (in this case 60 degrees) from the main branch. Makeflake generates a single main branch, and then rotates every generated point 60 degrees to create a complete snowflake.
To generate the snowflake, makeflake calls the function drawline. Drawline draws lines by coloring pixels that satisfy the equation. drawline generates lines given a specific angle and length. In this case, all the angles are a multiple of 60. Drawline uses two structs, formula and point. Point stores the coordinates of points on the pixel array and formula stores m and c (y = mx + c)
given a starting point and an angle, drawline uses the function lineforml which generates the formula for a line at a given angle that passes through a certain point.
dist just calculates the distance between two points (or pixels). it is used by drawline so it knows when to stop deawing (when the line reaches the required length)
lineforml function generates a fomula for a straight line passing through a certain point at a certain angle. It outputs a struct called formula, which is then used by drawline to draw a line at the desired angle.
the rotate function uses the standard formula for rotating points on a 2d plane to rotate a given point at a given angle. This function is called by the function six() in a loop that rotates each point at an angle that is multiple of six until every point is rotated 6 times to mimic the symmetry of a snowflake. The makeflake function only really makes one of the six branches, and the rest are just copies of that first branch.
I stylised the image to give the fractal a more polished look. first i used the fill() function to fill a certain area of pixels around each point on the lines to make the lines bolder and more visible. Then, to create a crystal like effect i reused edge detection code I wrote for the filter problem, but changed the color values so the edges are blue instead of white.