SHOW:
|
|
- or go back to the newest paste.
| 1 | ;;;; Name: eLOGO | |
| 2 | ;;;; Author: Ryan Burnside | |
| 3 | ;;;; Date: 2014-03-06 | |
| 4 | ;;;; Released under GPL v4 | |
| 5 | ||
| 6 | ;;; This is the beginning of a LOGO like module to draw vector shapes | |
| 7 | ;;; Historically the cursor is called a "turtle" | |
| 8 | ;;; It has a small set of commands to draw primative line graphics | |
| 9 | ||
| 10 | ;;; Global variables for turtle maintenance | |
| 11 | ||
| 12 | (defvar *x-pos* 0) | |
| 13 | (defvar *y-pos* 0) | |
| 14 | (defvar *previous-x-pos* 0) | |
| 15 | (defvar *previous-y-pos* 0) | |
| 16 | ||
| 17 | (defvar *direction* 0) | |
| 18 | (defvar *step* 0) | |
| 19 | (defvar *is-drawing* t) | |
| 20 | (defvar *color* '(0 0 0)) | |
| 21 | (defvar *line-list* '()) ; Elements are (x y x2 y2 '(R G B)) | |
| 22 | ||
| 23 | ;;; Turtle manipulation commands | |
| 24 | (defun move () | |
| 25 | "Move at the current angle and step size, save line to list if *is-drawing*" | |
| 26 | (if *is-drawing* | |
| 27 | (setf *line-list* | |
| 28 | (cons (list *previous-x-pos* *previous-y-pos* *x-pos* *y-pos* *color*) | |
| 29 | *line-list*))) | |
| 30 | (setf *previous-x-pos* *x-pos*) | |
| 31 | (setf *previous-y-pos* *y-pos*)) | |
| 32 | ||
| 33 | (defun rt (dir) | |
| 34 | "Turn the turtle right in degrees" | |
| 35 | (incf *direction* dir)) | |
| 36 | ||
| 37 | (defun lt (dir) | |
| 38 | "Turn the turtle left in degrees" | |
| 39 | (decf *direction* dir)) | |
| 40 | ||
| 41 | (defun fd (length) | |
| 42 | "Move forward in pixels at current heading" | |
| 43 | (setf *step* length) | |
| 44 | (setf *x-pos* (+ *x-pos* (* (cos (degrees-to-radians *direction*)) *step*))) | |
| 45 | (setf *y-pos* (+ *y-pos* (* (sin (degrees-to-radians *direction*)) *step*))) | |
| 46 | (move)) | |
| 47 | ||
| 48 | (defun set-pen-color (red green blue) | |
| 49 | (setf *color* (list red green blue))) | |
| 50 | ||
| 51 | (defun tail-up () | |
| 52 | "Don't draw following step commands" | |
| 53 | (setf *is-drawing* nil)) | |
| 54 | ||
| 55 | (defun tail-down () | |
| 56 | "Start drawing following step commands" | |
| 57 | (setf *is-drawing* t)) | |
| 58 | ||
| 59 | (defun clear-drawing () | |
| 60 | "Reset the global line list" | |
| 61 | (setf *line-list* '())) | |
| 62 | ||
| 63 | ||
| 64 | ;;; We'll need to impliment a very small subset of XML file writing below | |
| 65 | ;;; We can easily do this with the *line-list* the turtle makes | |
| 66 | ;;;; Date: 2014-03-06 | |
| 67 | ;;;; Released under GPL v4 | |
| 68 | ||
| 69 | ;;; This is the beginning of a LOGO like module to draw vector shapes | |
| 70 | ;;; Historically the cursor is called a "turtle" | |
| 71 | ;;; It has a small set of commands to draw primative line graphics | |
| 72 | ||
| 73 | ;;; Global variables for turtle maintenance | |
| 74 | ||
| 75 | (defvar *x-pos* 0) | |
| 76 | (defvar *y-pos* 0) | |
| 77 | (defvar *previous-x-pos* 0) | |
| 78 | (defvar *previous-y-pos* 0) | |
| 79 | ||
| 80 | (defvar *direction* 0) | |
| 81 | (defvar *step* 0) | |
| 82 | (defvar *is-drawing* t) | |
| 83 | (defvar *color* '(0 0 0)) | |
| 84 | (defvar *line-list* '()) ; Elements are (x y x2 y2 '(R G B)) | |
| 85 | ||
| 86 | ;;; Turtle manipulation commands | |
| 87 | (defun move () | |
| 88 | "Move at the current angle and step size, save line to list if *is-drawing*" | |
| 89 | (if *is-drawing* | |
| 90 | (setf *line-list* | |
| 91 | (cons (list *previous-x-pos* *previous-y-pos* *x-pos* *y-pos* *color*) | |
| 92 | *line-list*))) | |
| 93 | (setf *previous-x-pos* *x-pos*) | |
| 94 | (setf *previous-y-pos* *y-pos*)) | |
| 95 | ||
| 96 | (defun rt (dir) | |
| 97 | "Turn the turtle right in degrees" | |
| 98 | (incf *direction* dir)) | |
| 99 | ||
| 100 | (defun lt (dir) | |
| 101 | "Turn the turtle left in degrees" | |
| 102 | (decf *direction* dir)) | |
| 103 | ||
| 104 | (defun fd (length) | |
| 105 | "Move forward in pixels at current heading" | |
| 106 | (setf *step* length) | |
| 107 | (setf *x-pos* (+ *x-pos* (* (cos (degrees-to-radians *direction*)) *step*))) | |
| 108 | (setf *y-pos* (+ *y-pos* (* (sin (degrees-to-radians *direction*)) *step*))) | |
| 109 | (move)) | |
| 110 | ||
| 111 | (defun tail-up () | |
| 112 | "Don't draw following step commands" | |
| 113 | (setf *is-drawing* nil)) | |
| 114 | ||
| 115 | (defun tail-down () | |
| 116 | "Start drawing following step commands" | |
| 117 | (setf *is-drawing* t)) | |
| 118 | ||
| 119 | (defun clear-drawing () | |
| 120 | "Reset the global line list" | |
| 121 | (setf *line-list* '())) | |
| 122 | ||
| 123 | ||
| 124 | ;;; We'll need to impliment a very small subset of XML file writing below | |
| 125 | ;;; We can easily do this with the *line-list* the turtle makes |