-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsketch.lisp
More file actions
34 lines (28 loc) · 929 Bytes
/
Copy pathsketch.lisp
File metadata and controls
34 lines (28 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(defpackage :nature-of-code.vectors.example-4
(:export :start-sketch)
(:use :cl :trivial-gamekit))
(in-package :nature-of-code.vectors.example-4)
(defvar *width* 800)
(defvar *height* 600)
(defvar *black* (vec4 0 0 0 1))
(defgame sketch ()
((center
:initform (vec2 (/ *width* 2) (/ *height* 2))
:accessor center)
(mouse-position
:initform (vec2 0 0)
:accessor mouse-position))
(:viewport-width *width*)
(:viewport-height *height*)
(:viewport-title "Multiplying a vector"))
(defmethod post-initialize ((this sketch))
(bind-cursor (lambda (x y)
(setf (mouse-position this) (vec2 x y)))))
(defmethod draw ((this sketch))
(let* ((center (center this))
(sub (subt (mouse-position this) center)))
(translate-canvas (x center) (y center))
(setf sub (mult sub 0.5))
(draw-line (vec2 0 0) sub *black* :thickness 2)))
(defun start-sketch ()
(start 'sketch))