Logo

StickFigure Graphic Productions


Educational Code Resources

Simple Animation in JavaGenetic Algorithms in PythonDesktop Security Demo

Licensing

Creative Commons License GNU General Public License v3
  • The source code for these projects is licensed under the GNU General Public License v3 unless otherwise noted.
  • Any artistic content is licensed under the terms of the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

JAnimationPanel & Fireworks Demo

  • Description
     Provides a relatively beginner friendly API for creating animated scenes embedded in a Swing UI.
     Includes a demo that displays a sunset, followed by Fireworks, and can be adapted into a fun classroom or lab exercise. Write some new classes to extend AnimObject (or either of the two example classes I provided - SimpleFirework and SimpleSparklingFirework). You should probably only have to modify the worldTick method in FireworksWorld.java to add your new effects, but you're also welcome to write your own class that extends either FireworksWorld or AnimationWorld and a new main class to go along with it.


    (Apologies for any artifacting in the captured video)
  • Code
  • Documentation

Genetic Algorithm

  • Description
     This program implements, in Python, a genetic algorithm to optimize the assignment of pellet stoves to low-income clients based on a state grant. It was developed to show one potential real-world application of genetic algorithms (based on the work described here). This implementation is well documented and in most ways closely matches a textbook description of genetic algorithms.

     By way of explanation, the total sum of the final column in the output spreadsheet should end up being the same as the maximum fitness for the final generation (use the import function if you want to look at it in Excel, since I saved these as .csv for ease of programming). All of my assumptions about the model are documented in the source file (# is the comment character in Python). You can use the Python terminal to generate a new input file if you want to test the robustness of the code.
  • Sample Usage
    • To generate a random set of clients enter the following in a Python terminal:
          import os
          # The r before the opening quotes is important,
          # unless you want to double your \'s
          os.chdir(r"C:\PATH\TO\FILE\DIRECTORY\GOES\HERE")
          from evolve_stoves import write_client_data, random_client_data
          write_client_data("PUT_A_FILENAME_HERE.CSV",
      	                   random_client_data(DATA_SIZE_HERE))
      

    • To execute the program, execute the following on your commandline:
      python evolve_stoves.py stove_data.csv POPULATION GENERATIONS

       In this example, "stove_data.csv" should be replaced by the path to your input file, and "POPULATION" and "GENERATIONS" should be replaced by integers. The potential solution will be output (based on this command line) to "stove_data_answer.csv".

       It is likely that the assumptions behind the model will break under a dataset which is significantly smaller than the examples provided (unless MIN_B is redefined accordingly). The program will warn you if it is having trouble generating an initial population under the current constraints with the "Warning, we're starting with a genome that may not satisfy the constraints". Mutations will fail quietly if they fail at all (but the program works well so they evidently do not fail often). The other warning which may appear is if the roulette wheel selects parents who can't breed under the current set of constraints, but this also appears to be fairly harmless (though if it appears too frequently beyond the first few rounds it may be a sign that the constraints are too tight for the size of the dataset).

      Developed with Python 2.7, so use that for best results (though no obvious backward incompatibilities come to mind for 2.6 or 2.5).
  • Code

Desktop Security & Linux

  • Description
    Demonstrate to your students the dangers of trusting unknown files and an overly "helpful" desktop environment. This demo should be compatible with Linux (or other Unix-like) machines running a KDE, Gnome, or Xfce desktop session. A standards-compliant .desktop launcher file presents itself as a harmless Open Document Text (.odt) file, but when opened fetches a Python script that conceals itself, configures an auto-launcher, and launches random XKCD comics in Firefox at a short intervals.
  • Code