/examples/trails/source.scm

http://github.com/dharmatech/abstracting · Scheme · 72 lines · 36 code · 29 blank · 7 comment · 0 complexity · 4603153e5d8d0f6d91738d4230dec606 MD5 · raw file

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. (define *mouse-position* (vec 0.0 0.0))
  3. (define (passive-motion-func x y)
  4. (set! *mouse-position* (vec (inexact x) (inexact y))))
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. (define *length* 100)
  7. (define *points*
  8. (circular-list-tabulate *length*
  9. (lambda (i)
  10. (vec 0.0 0.0))))
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12. (define (idle-func)
  13. (set-car! *points* *mouse-position*)
  14. (set! *points* (cdr *points*))
  15. (glutPostRedisplay))
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. (glutInitDisplayMode GLUT_DOUBLE)
  18. (glutInitWindowPosition 100 100)
  19. (glutInitWindowSize 500 500)
  20. (glutInit (vector 0) (vector ""))
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. (let ((win (create-window "Trails")))
  23. (-> win 'ortho-standard)
  24. ((-> win 'display-function)
  25. (let ((pen (pen)))
  26. ((-> pen 'set-stroke-color) (rgba 0.0 0.0 0.0 0.0)) ; no stroke
  27. ((-> pen 'set-fill-color) (rgba 1.0 1.0 1.0 0.1)) ; White with transparency
  28. (let ((move-to (-> pen 'move-to))
  29. (circle (-> pen 'circle)))
  30. (lambda ()
  31. (background black)
  32. (circular-list-each-index
  33. (lambda (i point)
  34. (move-to point)
  35. (let ((fraction (/ i *length*)))
  36. (circle (max 5.0 (* fraction 25.0)))))
  37. *points*)
  38. (glutSwapBuffers))))))
  39. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  40. (glutPassiveMotionFunc passive-motion-func)
  41. (glutIdleFunc idle-func)
  42. (glutMainLoop)
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;