[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs 40a3d00209 367/472: Implement glowing walls (#138)
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs 40a3d00209 367/472: Implement glowing walls (#138) |
Date: |
Thu, 6 Jan 2022 21:59:40 -0500 (EST) |
branch: elpa/pacmacs
commit 40a3d002098e3d0a4141c1acefad6811226b1161
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Implement glowing walls (#138)
---
pacmacs-image.el | 142 ++++++++++++++++++++++++++++++++------------
pacmacs-utils.el | 6 --
pacmacs-vector.el | 6 ++
test/pacmacs-utils-test.el | 4 +-
test/pacmacs-vector-test.el | 4 ++
5 files changed, 114 insertions(+), 48 deletions(-)
diff --git a/pacmacs-image.el b/pacmacs-image.el
index 81c9635d92..067f1a4781 100644
--- a/pacmacs-image.el
+++ b/pacmacs-image.el
@@ -35,6 +35,11 @@
(require 'dash)
(require 'color)
+(require 'pacmacs-vector)
+
+(defconst pacmacs--wall-gradient-color-start "#181818")
+(defconst pacmacs--wall-gradient-color-stop "#5555ff")
+
(defvar pacmacs--wall-blocks
(make-hash-table))
@@ -44,20 +49,20 @@
(defun pacmacs-insert-image (resource resource-vector)
(insert-image resource " " nil resource-vector))
-(defun pacmacs--put-bits-dot (bits row column weight)
+(defun pacmacs--put-bits-dot (bits row column weight weights-to-color)
(dotimes (i weight)
(dotimes (j weight)
- (aset (aref bits (+ i row)) (+ j column) 0))))
+ (aset (aref bits (+ i row)) (+ j column) (funcall weights-to-color i
j)))))
-(defun pacmacs--put-vertical-bar (bits column height weight)
+(defun pacmacs--put-vertical-bar (bits column height weight weight-to-color)
(dotimes (w weight)
(dotimes (i height)
- (aset (aref bits i) (+ column w) w))))
+ (aset (aref bits i) (+ column w) (funcall weight-to-color w)))))
-(defun pacmacs--put-horizontal-bar (bits row width weight)
+(defun pacmacs--put-horizontal-bar (bits row width weight weight-to-color)
(dotimes (w weight)
(dotimes (i width)
- (aset (aref bits (+ row w)) i w))))
+ (aset (aref bits (+ row w)) i (funcall weight-to-color w)))))
(defun pacmacs--bit-list-to-integer (bit-list)
(let ((result 0))
@@ -111,6 +116,88 @@
(and left-bottom (not left) (not bottom))
(and right-bottom (not right) (not bottom)))))
+(defun pacmacs--inverted-weight-to-color (weight)
+ (-lambda (w) (- weight w 1)))
+
+(defun pacmacs--two-weights-to-color (row-inverted column-inverted
color-inverted weight)
+ (-lambda (row-weight column-weight)
+ (let ((color (->> (pacmacs--squared-distance
+ 0 0
+ (if row-inverted
+ (- weight row-weight 1)
+ row-weight)
+ (if column-inverted
+ (- weight column-weight 1)
+ column-weight))
+ (sqrt)
+ (floor)
+ (min (1- weight)))))
+ (if color-inverted
+ (- weight color 1)
+ color))))
+
+(defun pacmacs--wall-bits-get-corners (wall-bits)
+ (-drop 4 wall-bits))
+
+(defun pacmacs--wall-bits-get-bars (wall-bits)
+ (-take 4 wall-bits))
+
+(defun pacmacs--put-inner-corners (wall-block width height weight wall-bits)
+ (-let (((left-upper right-upper left-bottom right-bottom)
+ (pacmacs--wall-bits-get-corners wall-bits)))
+ (when left-upper
+ (pacmacs--put-bits-dot wall-block 0 0 weight
+ (pacmacs--two-weights-to-color nil nil nil
weight)))
+
+ (when right-upper
+ (pacmacs--put-bits-dot wall-block 0 (- width weight) weight
+ (pacmacs--two-weights-to-color nil t nil weight)))
+
+ (when left-bottom
+ (pacmacs--put-bits-dot wall-block (- height weight) 0 weight
+ (pacmacs--two-weights-to-color t nil nil weight)))
+
+ (when right-bottom
+ (pacmacs--put-bits-dot wall-block (- height weight) (- width weight)
weight
+ (pacmacs--two-weights-to-color t t nil weight)))))
+
+(defun pacmacs--put-bars (wall-block width height weight wall-bits)
+ (-let (((bottom right top left)
+ (pacmacs--wall-bits-get-bars wall-bits)))
+ (when left
+ (pacmacs--put-vertical-bar wall-block 0 height weight #'identity))
+
+ (when right
+ (pacmacs--put-vertical-bar wall-block (- width weight) height weight
+ (pacmacs--inverted-weight-to-color weight)))
+
+ (when top
+ (pacmacs--put-horizontal-bar wall-block 0 width weight #'identity))
+
+ (when bottom
+ (pacmacs--put-horizontal-bar wall-block (- height weight) width weight
+ (pacmacs--inverted-weight-to-color
weight)))))
+
+(defun pacmacs--put-outer-corners (wall-block width height weight wall-bits)
+ (-let (((bottom right top left)
+ (pacmacs--wall-bits-get-bars wall-bits)))
+ (when (and left top) ;left-upper
+ (pacmacs--put-bits-dot wall-block 0 0 weight
+ (pacmacs--two-weights-to-color t t t weight)))
+
+ (when (and right top) ;right-upper
+ (pacmacs--put-bits-dot wall-block 0 (- width weight) weight
+ (pacmacs--two-weights-to-color t nil t weight)))
+
+ (when (and left bottom) ;left-bottom
+ (pacmacs--put-bits-dot wall-block (- height weight) 0 weight
+ (pacmacs--two-weights-to-color nil t t weight)))
+
+ (when (and right bottom) ;right-bottom
+ (pacmacs--put-bits-dot wall-block (- height weight) (- width weight)
weight
+ (pacmacs--two-weights-to-color nil nil t weight)))
+ ))
+
(defun pacmacs--create-wall-tile (width height
bottom right
top left
@@ -125,44 +212,21 @@
(-if-let (cached-tile (gethash cache-index pacmacs--wall-blocks))
cached-tile
(puthash cache-index
- (let ((wall-block (make-vector width nil))
- (weight 15))
+ (let* ((wall-block (make-vector width nil))
+ (weight 15)
+ (palette (pacmacs--color-hex-gradient
+ pacmacs--wall-gradient-color-start
+ pacmacs--wall-gradient-color-stop
+ weight)))
(dotimes (i width)
(aset wall-block i (make-vector height nil)))
- (when left-upper
- (pacmacs--put-bits-dot wall-block 0 0 weight))
-
- (when right-upper
- (pacmacs--put-bits-dot wall-block 0 (- width weight)
weight))
-
- (when left-bottom
- (pacmacs--put-bits-dot wall-block (- height weight) 0
weight))
-
- (when right-bottom
- (pacmacs--put-bits-dot wall-block (- height weight) (-
width weight) weight))
-
- (when left
- (pacmacs--put-vertical-bar wall-block 0 height weight))
-
- (when right
- (pacmacs--put-vertical-bar wall-block (- width weight)
height weight))
-
- (when top
- (pacmacs--put-horizontal-bar wall-block 0 width weight))
-
- (when bottom
- (pacmacs--put-horizontal-bar wall-block (- height weight)
width weight))
-
- ;; (dotimes (row height)
- ;; (dotimes (column width)
- ;; (when (zerop (mod (+ row column) 2))
- ;; (aset (aref wall-block row) column nil))))
+ (pacmacs--put-inner-corners wall-block width height weight
wall-bits)
+ (pacmacs--put-bars wall-block width height weight wall-bits)
+ (pacmacs--put-outer-corners wall-block width height weight
wall-bits)
- (create-image (pacmacs--bits-to-xpm wall-block width height
-
(pacmacs--color-hex-gradient "#5555ff" "#000011"
-
weight))
+ (create-image (pacmacs--bits-to-xpm wall-block width height
palette)
'xpm t))
pacmacs--wall-blocks))))
diff --git a/pacmacs-utils.el b/pacmacs-utils.el
index 8d2db4b127..c52b8f0185 100644
--- a/pacmacs-utils.el
+++ b/pacmacs-utils.el
@@ -64,12 +64,6 @@ side-effects."
'down (cons 1 0))))
(plist-get direction-table direction)))
-(defun pacmacs--squared-distance (row1 column1 row2 column2)
- (let ((d-row (- row2 row1))
- (d-column (- column2 column1)))
- (+ (* d-row d-row)
- (* d-column d-column))))
-
(defun pacmacs--direction-name (direction-vector)
(let ((direction-table '((( 0 . -1) . left)
(( 0 . 1) . right)
diff --git a/pacmacs-vector.el b/pacmacs-vector.el
index 1332bba166..2953b077fa 100644
--- a/pacmacs-vector.el
+++ b/pacmacs-vector.el
@@ -42,6 +42,12 @@
(pacmacs--vector-components-operation
vector1 vector2 #'-))
+(defun pacmacs--squared-distance (row1 column1 row2 column2)
+ (let ((d-row (- row2 row1))
+ (d-column (- column2 column1)))
+ (+ (* d-row d-row)
+ (* d-column d-column))))
+
(provide 'pacmacs-vector)
;;; pacmacs-vector.el ends here
diff --git a/test/pacmacs-utils-test.el b/test/pacmacs-utils-test.el
index 630f9a5f34..03580a3c1f 100644
--- a/test/pacmacs-utils-test.el
+++ b/test/pacmacs-utils-test.el
@@ -11,6 +11,4 @@
(should (not (pacmacs--levelname-from-filename "."))))
-(ert-deftest pacmacs--squared-distance-test ()
- (should (= (pacmacs--squared-distance 1 1 3 3)
- 8)))
+
diff --git a/test/pacmacs-vector-test.el b/test/pacmacs-vector-test.el
new file mode 100644
index 0000000000..ad2f46f54b
--- /dev/null
+++ b/test/pacmacs-vector-test.el
@@ -0,0 +1,4 @@
+
+(ert-deftest pacmacs--squared-distance-test ()
+ (should (= (pacmacs--squared-distance 1 1 3 3)
+ 8)))
- [nongnu] elpa/pacmacs f88ea61b10 035/472: Merge branch 'ut-coverage-27'. Close #27, (continued)
- [nongnu] elpa/pacmacs f88ea61b10 035/472: Merge branch 'ut-coverage-27'. Close #27, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9acb9eefa4 286/472: Introduce a constructor for terrified ghosts (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 25193bcdbf 289/472: Better running away algorithm (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 8fd7660240 290/472: Terrify ghosts by eating big pill (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e4e4053c26 306/472: Ghost terrified time as constant (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1978363e9d 310/472: Fix handle-ghost-blinking-threshold (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a896a83366 312/472: Merge pull request #164 from codingteam/blink-almost-timed-out-159, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d3c94de6da 320/472: Remove UT for pacmacs--track-point (#159), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 8b40dc51cf 330/472: Add 1st big pill level (#162), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 49292e34d3 342/472: UT for terrified-ghost-timed-out-p function (#171), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 40a3d00209 367/472: Implement glowing walls (#138),
ELPA Syncer <=
- [nongnu] elpa/pacmacs 5c45e17c40 399/472: Add docs for destroy function (#134), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs f79355209d 060/472: Refactor out functions for creating images (#51), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 080aae5f08 070/472: Use plist-bind for pacman-anim-next-frame function (#54), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1e1cebe39a 073/472: Introduce plist-map utility function (#54), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs ba7ad0349d 082/472: Rename pacman to pacmacs. Close #66, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs c447091a19 085/472: Fix description in the game headers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e85c81b077 090/472: Enable entire code base for coverage (#70), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e3d914a1ea 097/472: Dropping support for Emacs 24.1 and 24.2. Close #71, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 4b08605994 093/472: UTs for duration frame logic. Close #60, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs c865fda214 120/472: Merge branch 'board-refactoring-74'. Close #74, ELPA Syncer, 2022/01/06