Code Monkey home page Code Monkey logo

fp1's Introduction

My Library: (graphics/turtles)

#####My name: Adam Melle

I used the turtle graphics library to create a recursive pattern function.

(define (recursive-pattern dist angle turns iterations)
  (turn-turtle dist angle turns)
  (if(> iterations 0)
     (recursive-pattern (- dist (* .10 dist)) angle turns (- iterations 1))(home)))

The function accepts four parameters, dist, angle, turns, and iterations, and then recursively draws the pattern using the values. The function works by calling another function named turn-turtle that accepts parameters, dist, angle, and turns, and then draws a line, turns the turtle depending on angle, and then draws another line.

(define (turn-turtle dist angle turns)
  (draw dist)
  (turn angle)
  (draw dist)
  (if(> turns 0)(turn-turtle (* dist .83) (* .91 angle) (- turns 1))0))

This function is called recursively, each time decrementing turns and decaying values by a random amount, until turns is 0. Back inside the recursive-pattern function, an if statement checks the number of iterations and recursively calls the function depending on the value of iterations. The dist parameter is decayed by a random amount(10% in this case) everytime the function is called recursively. Using this function I was able to generate some very interesting fractal like patterns. I also created another function called save-pattern that accepts a path and an extension for saving the pattern as an image.

(define (save-pattern path extension)
 (if(save-turtle-bitmap path extension)(display "save successful")(display "save unsuccessful")))

My function utilizes the save-turtle-bitmap function, but sends back confirmation that the file saved successfully or unsuccessfully. The extension parameter accepts the following values 'png 'jpeg 'xbm 'xpm 'bmp.

Here are some of the patterns I created.

fp1's People

Contributors

marksherman avatar adam-melle avatar

Watchers

 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.