Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;; Name: eLOGO
- ;;;; Author: Ryan Burnside
- ;;;; Date: 2014-03-06
- ;;;; Released under GPL v4
- ;;; This is the beginning of a LOGO like module to draw vector shapes
- ;;; Historically the cursor is called a "turtle"
- ;;; It has a small set of commands to draw primative line graphics
- ;;; Global variables for turtle maintenance
- (defvar *x-pos* 0)
- (defvar *y-pos* 0)
- (defvar *previous-x-pos* 0)
- (defvar *previous-y-pos* 0)
- (defvar *direction* 0)
- (defvar *step* 0)
- (defvar *is-drawing* t)
- (defvar *color* '(0 0 0))
- (defvar *line-list* '()) ; Elements are (x y x2 y2 '(R G B))
- ;;; Turtle manipulation commands
- (defun move ()
- "Move at the current angle and step size, save line to list if *is-drawing*"
- (if *is-drawing*
- (setf *line-list*
- (cons (list *previous-x-pos* *previous-y-pos* *x-pos* *y-pos* *color*)
- *line-list*)))
- (setf *previous-x-pos* *x-pos*)
- (setf *previous-y-pos* *y-pos*))
- (defun rt (dir)
- "Turn the turtle right in degrees"
- (incf *direction* dir))
- (defun lt (dir)
- "Turn the turtle left in degrees"
- (decf *direction* dir))
- (defun fd (length)
- "Move forward in pixels at current heading"
- (setf *step* length)
- (setf *x-pos* (+ *x-pos* (* (cos (degrees-to-radians *direction*)) *step*)))
- (setf *y-pos* (+ *y-pos* (* (sin (degrees-to-radians *direction*)) *step*)))
- (move))
- (defun set-pen-color (red green blue)
- "Set the RGB triplet for the turtle's line color"
- (setf *color* (list red green blue)))
- (defun tail-up ()
- "Don't draw following step commands"
- (setf *is-drawing* nil))
- (defun tail-down ()
- "Start drawing following step commands"
- (setf *is-drawing* t))
- (defun clear-drawing ()
- "Reset the global line list"
- (setf *line-list* '()))
- ;;; We'll need to impliment a very small subset of XML file writing below
- ;;; We can easily do this with the *line-list* the turtle makes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement