Code Monkey home page Code Monkey logo

code_reference's Introduction

Code Reference

Examples of little ideas that I play with in various languages

  • The Dragon Fractal is a little project that I like to reimplement in new languages to try out syntax and features of languages.

Dragon Fractal

As a simple introduction, take a strip of paper and fold it in half. Fold it in half again in the same direction. Again, again, and again.

If you opened all the folds, and made each one a right angle, what shape would you get after folding it X times?

Vi Hart's exploration

Continues from previous project

Turn lists

The first thing I looked when I discovered this puzzle as a kid was to look at weather the paper turns left or right at a given crease.

Every time you fold the strip, it doubles all the existing folds while inverting them and adds a single fold to the middle. The nature of the folding makes the whole thing an inverted palandrome.

First iteration is just a single Left. Second iteration is Left, left, right.

3rd: llr l lrr 4th: llrllrr l llrrlrr 5th: llrllrrlllrrlrr l llrllrrrllrrlrr ... etc

Notice, every next iteration contains the previous, so perhaps an optimiation in the calculation would be to store just the new portion in a list of lists.

1st: l 2nd: l r 3rd: l lrr 4th: l llrrlrr 5th: l llrllrrrllrrlrr

Since this gets larger exponentially, it'll more often be faster to read from memory than to recalcuate higher iteration levels. Writing to disk gives good opertunities to sanity test previous runs, overwrite mistakes, or pickup from last run.

Plotting the folds

Next you get to do a little trigonometry on your array of turns.

x = R * cos ( theta )
y = R * sin ( theta )

code_reference's People

Contributors

dothtm avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.