Home     Portfolio     Contact


Portfolio:

*Note: Clicking on the links for “Code” will open a new tab.


Decoding MIPS Instructions from a Binary File
xoroshiro64
Approximating Pi Using XMM Registers
Segmented Mirror/Solar Furnace
Keno/Hot Spot Analysis Tool
Text-Based Adventure Game


6. Decoding MIPS Instructions from a Binary File

Code: https://patclarke.com/decoding-mips-instructions-from-a-binary-file/

Date: Spring 2023

Why: This was a project for my CSCI 241 Computer Organization and Assembly Language Programming class.

What:

            This C++ program reads from a binary file, retrieves individual bytes, and then decodes what each MIPS instruction means. Each MIPS instruction is 32 bits long and is either I, J, or R format. I do not believe that there were any J format instructions in the binary file, however if there were the program would have produced the appropriate output.



5. xoroshiro64

Code: https://patclarke.com/xoroshiro64/

Date: Spring 2023

Why: This was another project for my CSCI 241 Computer Organization and Assembly Language Programming class.

What:

            This program produces random numbers from a pseudo random number generator by using a seed, bitwise operations, shifts, and rotations.

            No gif was created for the homepage because I used a statistical analysis tool that runs tests on the program, and if the program works correctly then the output is very uneventful. It just says, “No anomalies detected…” and a time as well. However, if it does not work then the output reads “FAIL!!!FAIL!!!FAIL!!!…”.

            I liked this program because I am interested in pseudo random number generators (PRNG), and random number generators (RNG), and I had read about things like this before taking the course. I was happy to finally be able to create something like it on my own.            

In the future it would be cool to try and create a feature where you could actually see the output that the program is producing. If you try to run this program without the statistics tool, then it will just print a bunch of garbage. Another thing that I think would be cool to investigate is if you could adapt the program to accept additional parameters. For example, give x many numbers within a range of y to z. Could something like that be done on a program like this, or would that destroy the random qualities that the analysis tool is checking for?



4. Approximating Pi Using XMM Registers

Code: https://patclarke.com/approximating-pi-using-x86-64/

Date: Spring 2023

Why: This was another project for my CSCI 241 Computer Organization and Assembly Language Programming class.

What:

            This program is self-explanatory, but it asks a user to specify how many decimal places of pi they would like, and then produces the appropriate output. The value is calculated using xmm registers.

            I had some trouble with the part that asks the user for input. I wanted to be able to ask for up to 50 decimal places of pi, but I ended up stopping at 10 due to a bug that I was not able to figure out with the time that I had. If I were to write this program again this is one thing that I would change.



3. Segmented Mirror/Solar Furnace

Date: Summer 2022 – Summer 2023

Why:

            I wanted to see if I could create a device capable of focusing sunlight and producing high temperatures (~900 C) using cheap materials.

Examples of how to not build “cross sections” for the first version of the design.

What:

            I was looking online to see if there was a way to release CO2 from calcium carbonate for an unrelated project. I found some “solar concentrators” on Amazon that would have worked. Unfortunately, these concentrators were out of my price range.

            I figured that probably many people had attempted to create solar furnaces, and that there was likely a lot of good information online. I found many DIY videos/articles. A lot of them involved using some combination of mylar and fiberglass resin. Others involved putting mylar over a hollow cylinder, and then temporarily evacuating air from the cylinder with a vacuum to produce the desired effect. I also found some awesome videos on hydroforming using grease guns. My goal was to keep the project as inexpensive as possible so this would not have worked for me.

            A common theme in most of the videos, excluding those on DIY hydroforming, was a lack of technical information. Like in my case, I had a very specific temperature range that I was trying to achieve, and so far, I had not found anything on how to go about creating something based on that. A lot of the videos would show the reflector being built, and then cut to something being burnt with it. Another thing that was unsettling to me was that none of the videos/articles I came across involved segmented mirrors. Why had nobody done a DIY video on this?

            I decided to create my own design. My first step was to use a tool on Desmos to get an idea of how to segment a parabola: how could I approximate a curve using straight edges? It is worth noting here that in industrial applications the mirror segments that are used do have some curvature to them. They are not flat. In my project they are flat, and as you will soon see, that proved to be enough of a challenge for me.

            The equation for the parabola depends on how high you would like the focal point (or “focus”) to be. I knew that the parabola would likely need to be shallow. I also knew that there needed to be a relationship between the surface area of the paraboloid (traced out after the parabola was revolved about an axis – the axis that divides it symmetrically) and the amount of thermal power the reflector can produce.

            I found the answers I was looking for on the Stack Exchange for physics. What I found is that under ideal conditions (clear sky, at the equator, at noon) one square meter is capable of producing approximately 1kW. From here I was able to determine my bounds of integration for the surface area integral that I would need to compute.

            After I had that down I was set! I would just draw this thing on Fusion360 real quick, print out the template, make my 1:10 replica, scale it up, and I would be separating CO2 from calcium carbonate in like a month … max! Yeah, that did not happen. Not even close.

            Hurdle #1:

            There were quite a few design iterations early on when trying to figure out how to get all the cross sections to fit together. There were 6 frame pieces glued directly on top of a base piece in the first version of this design. I decided that instead of gluing all of the “mirrors” together that it would be best to create some other structure beneath it that the mirrors could be glued onto directly. I called these “cross sections” because the “cross” each section of the mirror. The mirrors were created by attaching inexpensive aluminum tape to a piece of balsa wood, polishing the strips using metal polish and a microfiber towel, placing a template over the strips, and then cutting them out with an X-acto knife.

            The first major mistake I made was that I did not account for the thickness of the material in some of my very first drawings. This resulted in the paraboloid’s surface being about 2mm higher than it should have been. I tried reproducing a parabola in Desmos to see if it was just a translational problem (had the entire curve just been shifted up?), however I was not able to produce an equation that fit with translations.

            To fix this I recessed the line segments that made up my parabola in Fusion360 by 2mm. When I did this, it changed some things. If you can imagine you have a point where two edges come together – how do you even “recess” something like that in a way that makes sense?

            What I did was I selected the point between the two segments and made a line perpendicular to one edge by 2mm and repeated the process for the other edge. Next, I made a projection perpendicular from the line I just created, parallel to the original edge now, in the direction of the other 2mm line I had just created. I repeated the process for the other edge and marked where these two lines intersected. That became the new point between the two rows of cross sections (in my drawings I called these “tiers” and labeled them with roman numerals).

            I think that this warrants an explanation because for me, and maybe for you too, it is not very intuitive. I know that at first, I thought, “Oh, okay, just divide the parabola up into straight segments.” What I found though, is because the curvature of the parabola varies at different points then so will the lengths of the segments. The most curved region is near the vertex of the parabola. As we will see shortly this has some very important consequences for the design assuming that you want all of the mirrors to be the same size.

            If you were to look at the line segment lengths that were determined by looking at the parabola, and the length segments on the drawing before they are recessed, then you would find that they are different for the reason mentioned above. After you recess them by the width of the material then they will appear to be even more different from the original lengths determined by using the parabola tool on Desmos. This could be confusing if you were anticipating that all the lengths would be the same because all of the mirror lengths are the same.

            That was the first major hurdle.

            Hurdle #2:

            I mentioned the cross sections above earlier. How do you get them all to fit together? Initially I thought that it would be as simple as taking the length of mirror, and cutting rectangular segments so that the mirrors could be glued on top of them. For the cross section pieces that would come into contact with the frame, I made those triangles. That did not work.

            To get all the cross sections to fit together I created a template where they could all be placed together, and with a small amount of wood glue, I found that they would stay in position (for the most part) when removed from the template.

            What ended up happening is I created about twelve different drawings before I figured out how to get the cross sections meeting with the frame. This is another problem with this design that for me was not very intuitive. I would create a drawing with some minor modification, cut out the template, tape it to balsa wood, cut the pieces using X-acto knives, cut the new template (if the pieces differed enough in length), glue the pieces using the template, and then finally try to see if it would fit between the frames.

            I found that to really know if I was doing it correctly, that I should do the tests on tiers with more cross sections. Why? Wouldn’t I want to use a tier with as few pieces as possible to be efficient? That was my approach at first, but what ended up happening is I found myself wondering, “Is this off because of the frame, because of my cuts, or because of the design?” When I worked on tiers with more cross sections I did not have this issue because it was extremely apparent when something was wrong.

            There are six individual frame pieces which means that the angle between each frame piece is (ideally) sixty degrees. If, for example, you were in tier II, then there would need to be 3 cross section pieces (1 rectangle and 2 triangles on the ends). This means that there will be 2 “breaks” between the 3 pieces. One thought I had was that the angle between the cross section pieces would simply be sixty divided by 2 in this case. That won’t work here though. That would work for a cylinder. The problem is that each segment has some incline angle to it depending on which tier it is, in addition to the angle that I just described. That combination of angles is what was throwing me off.

            To find this angle I reproduced two triangles in Fusion360 that represented the inclined tiers of the frame. Next, I put the angle that I mentioned above between them, in this case 60/2 = 30 degrees. After that, I made an orthogonal projection from the midpoint of each segment. (Note: It did not have to be the midpoint. It could have been the same point anywhere on the two segments. I chose the midpoint out of convenience, because Fusion360 makes it easy to see when the mouse cursor is at a midpoint.) I made the projections long enough to where they would intersect in space – just some relatively huge number like 50cm. Next, I used the measurement tool to determine the angle between the intersecting projections. That is how I was able to determine the angle between the cross sections.

            There were a few more little surprises when getting the lengths of the cross sections correct. I do not think that writing them here would be very appropriate as there are a lot of little details. I think an explanation would be better suited for a video. I will mention though that there is a little routine that you need to go through to get the triangular cross section pieces fitting correctly, and if there are many tiers this can take some time.

            By the time I finally got everything figured out I only had enough building materials to construct one of the six sections of a replica. Fall semester started and I had no time to work on this project. Which was fortunate because there was another big problem with the design that I had not found yet.

            Hurdle #3:

            The main problem with my first version (the “pizza slice” 1/6th of a paraboloid looking thing on the home page) is that I did not consider the wavelength of the sun’s light that I was taking advantage of. It would have worked, but it would have been inefficient. The focal point would have been very large, because I did not account for error tolerance within the design of the segmented mirror.

            I learned, from a question asked on Stack Exchange, that this tolerance can be no greater than one fourth of wavelength of the electromagnetic spectrum that the instrument is trying to use. In my case, the design would have to be precise to 2.5mm (one quarter of a centimeter). When I created the line segments to fit the equation of the parabola, I did not account for this. I chose end points based on the desired surface area, and from there divided them up as evenly as possible for my own convenience.  

            I needed to fix this to have the design working optimally.

            I decided that I would need to base the mirror size off the most curved portion of the parabola (near the vertex). I found the length by creating a straight-line tangent to the vertex. I stopped when the curve of the parabola deviated from the straight line by more than 2mm (a safe 0.5mm cushion in case any adjustments needed to be made later). I did the same thing for each tier. Then I compared them all in Excel, and I had to do a little bit of work because, like I mentioned before, the line lengths will not all be the same. I have read where a formal error analysis of segmented mirrors is actually very involved, and my “fix” is probably crude by comparison, but I think for this personal project that this treatment was sufficient.

            Building the second version of this design was very smooth by compared to the first version. I had worked out all of the more challenging aspects of the design the first time through. I made some other additions too. I sanded the edges of frame pieces to where they would all meet nicely at a point in the center of the hexagonal base. I created little jigsaw teeth so that I could fit the frame pieces into the base instead of just relying on my eyes and Gorilla Glue. I also cut large sections out of the base and frame to reduce the weight of the mirror.

            So, after a year of work on the design the 1:10 model must have been completely devoid of error, right? Hah!

            One large source of error was my own craftsmanship. I tried to cut and glue as carefully as I could, but if I was off by a little here and then a little there, then soon things were not fitting together correctly. Another source of error was the wood that I was using. I did not store the balsa wood correctly and unfortunately it did warp a little bit. I also bought the cheapest balsa wood available which may have also been a mistake. I did not think that this would have much of an effect on the model, but looking back on it I should have bought new wood.

            What ended up happening is that some of the mirror pieces did not want to fit in their places on top of the cross sections. When I realized this, I seriously considered scrapping the whole thing and building a new one, but I decided to keep it the way it was. I ended up shaving little slivers from each mirror piece that was giving me trouble. If you were to look at the gif on the homepage long enough, you will see what I am talking about. The size difference in some of the hexagons is very apparent. If I were to repeat the process with a laser cutter, in a well-ventilated area so that I am not inhaling formaldehyde vapors, and wood that was not warped, then things would fit together much better.

            I made another mistake with the second version of this design, but this mistake was probably a good thing. This was supposed to be a 1:10 scale replica. I made a careless mistake while calculating one of the lengths on the mirror pieces. Unfortunately, this error propagated throughout the entirety of the design, and the replica is now ~1:8 scale.

            This scaling error ended up being a good thing. Even at this ~1:8 scale the pieces were small and at times difficult to work with. For example, on the frame pieces, I needed to mark where one tier ended and another tier began, because the difference in some cases was 3 degrees or so. It would have been difficult to see where to glue the cross sections otherwise. It is difficult to imagine things going more smoothly at a smaller scale.

            I have not had time to take the model outside and see how much thermal power it can produce. I have a couple of ideas in mind for measuring that, and I will post them in the future.

            This was not a software project, but I think it was a good project for me to work on regardless. I learned a lot about segmented mirrors. Thinking back on it I used concepts from just about every math class I have taken so far (up through multivariable calculus).

            I imagine there are easier ways to do this. For instance, I chose to use cross sections because I did not want to worry about getting glue on a mirror, and possibly reducing the power output, but I’m sure there is a less painful way to approach this. I just went with what was most apparent to me at the time.

            Another consideration that may affect power output is the edges of the aluminum foil on the mirrors. Plenty of adhesive attached itself to the X-acto knife while making the cuts, and I had to clean the knife frequently. This would sometimes pull the foil up and away from the wooden hexagon that it was supposed to be attached to. I did my best to ensure that the edges stayed as close to the wood as possible, and that they remained pushed down, if anything, and not up. I think that this could cause some loss of power if the edges of the mirrors caused the light to reflect in an unintended way.

            A final consideration is the smoothness of the mirrors. I should have sanded the balsa wood for the mirrors a little bit with a fine grain piece of sandpaper. I noticed after I polished the aluminum tape that pushing the foil into the piece of wood caused some grooves in the balsa wood to be exposed. I think that this could be another potential source of inefficiency.

            Remember earlier when I mentioned that I wondered why I could not find any DIY projects on solar furnaces with segmented mirrors? Now I know why! I do not regret this. This was not a software project, but it was a cool project. It could easily become an electronics project by implementing a tracking system. That could be an addition for a future project.

I made sure to carefully align the mirrors in rows along the frame pieces first, and then to fill in the rest from there.


2. Keno/Hot Spot Analysis Tool

Code: Please message me if you would like this code.

Date: Summer 2022

Why:

            I was mesmerized by Keno when I was a kid. Every time my family went out to eat it seemed like there was always a TV somewhere with this “show” on. I also knew that this had something to do with the slips of paper and small pencils on each table. I was absolutely forbidden from touching them which of course only made it more interesting. As an adult I know that gamblers do not like Keno due to its low payouts. I wanted to investigate a couple of “strategies” that I had either read about or heard of.

            The first is the Monte Carlo Fallacy (or the Gambler’s Fallacy). It is the idea that if some event in a game has not occurred for some time that it is “due” to happen soon. For Keno, this would be something like, “I have been watching, and 21 has not come up for the last 10 games so I will include that with my picks.”

            The second is the idea of “hot” numbers. This would be something like, “I have been watching, and 42 has come up in the last 4 games! It must come up again.”

What:

            I created a web scraper using JavaScript to get data from the Hot Spot website. This web scraper would output the game results in a format for a C++ class that I created. I then copy and pasted the games into my C++ program until I had a day’s worth of information. I read where my IP could potentially be blocked if I made too many requests, and if I remember correctly, at one point I was doing two requests at a time with the web scraper but no more than that. (There was a plan in place to use a proxy server to pull a huge amount of game data, however preliminary results suggested that this may not be a good use of my time.)

            I then created a program in C++ that would go through different sets of games and make predictions for the next x-amount of games. Initially, I was making predictions for 10 spot (where you pick 10 numbers). However, when I did the math in an Excel sheet, I found that the best pay outs were for 4 spot. (An approximate payout of $0.66 per dollar spent. This is why gamblers generally dislike Keno. The worst was 1 spot with a payout of $0.50 per dollar spent.)

Expected pay out per dollar spent on different Hot Spot variations. The number in bold is the number of spots picked. BE stands for “Bullseye”. Both is playing regular Hot Spot and betting the BE as well.

            Note that there is a feature called the Bulls Eye (BE on the spreadsheet). However, from a probability perspective, it does not make sense to use this feature to increase payouts.

            My first attempts looked at the past hour and then made predictions for the next hour. I had some very reassuring initial results. If I had not had these I probably would not have worked on this project for as long as I did. I forget which fallacy I was testing, but on 10 spot one of the algorithms would have made $300+ for one hour. I was thrilled. I was going to be rich! How could anyone have not done this before?

            Of course, the problem is that it never happened again. Any gains made would have been lost paying for future games. This was an important lesson though. I could have been an example in Fooled by Randomness by Nassim Taleb. I can’t remember verbatim what he writes, but it goes like even in a random system there are times when it seems predictable. Which is exactly what had happened.

            After varying the size of the sample games (games a prediction would be made from), and future games (games the prediction would be tested against), I was able to produce no evidence that either of the common Keno strategies mentioned above would work. Despite all my efforts I was never able to produce a consistent outcome above the $0.66 per dollar mark. This means that the second-best way to play Keno is to use a random number generator to pick numbers. I would be reluctant to use the one that Hot Spot provides for players, but maybe this could be a future project.

            What is the best way to play Keno? To not play at all! From a probability perspective you will “make” more money that way.

            I have included my code above if you would like to conduct this experiment for yourself. One improvement that could have been made but was not would have been putting the information for the games in a separate data file.


1. Text-Based Adventure Game

Code: https://patclarke.com/text-based-adventure-game/

Date: Spring 2022

A visual representation of how I imagine this game would actually look. Circled numbers are area names, squares are object names, and triangles are puzzles than can be solved.

Why:

            This was a requirement for my CSCI 123 Intro to Programming Concepts in C++

What:

             This is a text-based adventure game that my class was instructed to work on throughout the semester. The project was broken up into three stages. I have included my program for the final stage above.

            The first stage was to create one area with one object that the player could pick up, drop, and just interact with in general. The second stage was to incorporate vectors into the game, and the third was to incorporate classes.

            I have read online where I should not include coursework in a portfolio, but I do not really view this as a straight up “homework assignment”. This project allowed a lot of creative freedom, and I tried to take full advantage of that.

            I wanted my game to be like a dungeon that you might find in Act 1 of Diablo 2. I have spent more time than I would like to admit in this area, especially as a kid, and I wanted to pay tribute to it in a way. It is worth noting that if you play through Act 1 you will not find any dungeons like the one in the game. There are no “fungal beasts” in Act 1 (although there are some swamp creatures in Act 3 that would probably be equally terrifying to run into in real life).

            Diablo 2 is one of the first games I really got into. I also wanted to incorporate puzzles into my game. There really is not anything in the Diablo series that I would call a puzzle. There are some things in Diablo 2 (like the stones for finding Deckard Cain in Act 1, and then finding Tal Rasha’s tomb in Act 2) that could be regarded as a puzzle of sorts. Really the only type of puzzle I have seen so far is one featuring exploding tiles in Diablo 4. Maybe there are more, as I have not played through the whole game, but my point is that puzzles are not emphasized in this series.

            To do that I drew inspiration from another game I spent way too much time on as a kid: Myst. The entire Myst game is just a whole bunch of puzzles. I incorporated 3 puzzles into this game total. Two of them involve a series of 3 levers with 3 possible positions that must be oriented correctly to cause an orb to appear. You need both orbs to appear in order to get into the final room (the green room). I named the rooms based off the colors in a pixel (red, green, and blue).

            The final “puzzle” is more like what to do with the fungal beast. How you win is by giving the creature the “large mushroom” found in the “The Hall of Roots”. This can be seen in the gif on the homepage. You can lose in more than one way. If you did not bother taking the large mushroom, then this puzzle cannot be completed. If you give the fungal beast the rock … you learn that fungal beasts do not like rocks.

            This project was something that I was not looking forward to at first, but I ended up getting really into it. One thing I was not able to work out while I was working on the game was that I wanted the player to have both orbs in their bag in order to get into the green room. I was not able to figure out a good fix for this and have not attempted to produce one since. What I ended up doing was just saying if you had made both orbs appear then that was good enough. So technically you could pick both orbs up and drop them in any of the three rooms that you can access at that point, and the green room will still open. This seems unrealistic, even by “Fever Dream” standards, and is something that I would improve if I ever did this project again.


Thank you for stopping by!

The best way to contact me is right here:

Please enable JavaScript in your browser to complete this form.
Name