Last active
September 8, 2015 03:02
pyonpyon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; pyonpyon.el --- pyonpyon | |
;; Copyright (C) 2015 by Syohei YOSHIDA | |
;; Author: Syohei YOSHIDA <syohex@gmail.com> | |
;; URL: https://github.com/syohex/ | |
;; Version: 0.01 | |
;; This program is free software; you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License, or | |
;; (at your option) any later version. | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;;; Code: | |
(require 'cl-lib) | |
(defcustom pyonpyon nil | |
"Emacs ga pyonpyon surunja-" | |
:group 'frame) | |
(defcustom pyonpyon-gravity 2.4 | |
"Gravity") | |
(defvar pyonpyon--timer) | |
(defvar pyonpyon--max-x 0) | |
(defvar pyonpyon--max-y 0) | |
(defvar pyonpyon--xpos 0) | |
(defvar pyonpyon--ypos 0) | |
(defvar pyonpyon--x-velocity 0) | |
(defvar pyonpyon--y-velocity 0) | |
(defun pyonpyon--display-size-x-window () | |
(with-temp-buffer | |
(process-file "xdpyinfo" nil t) | |
(goto-char (point-min)) | |
(when (re-search-forward "dimensions:\\s-+\\([0-9]+\\)x\\([0-9]+\\)" nil t) | |
(cons (string-to-number (match-string-no-properties 1)) | |
(string-to-number (match-string-no-properties 2)))))) | |
(defun pyonpyon--display-size-darwin () | |
(with-temp-buffer | |
(process-file "system_profiler" nil t nil "SPDisplaysDataType") | |
(goto-char (point-min)) | |
(when (re-search-forward "Resolution:\\s-+\\([0-9]+\\) x \\([0-9]+\\)" nil t) | |
(cons (string-to-number (match-string-no-properties 1)) | |
(string-to-number (match-string-no-properties 2)))))) | |
(defun pyonpyon--display-size () | |
(cl-case system-type | |
(gnu/linux (pyonpyon--display-size-x-window)) | |
(darwin (pyonpyon--display-size-darwin)))) | |
(defun pyonpyon--update-xpos () | |
(let ((next (+ pyonpyon--xpos pyonpyon--x-velocity))) | |
(cond ((< next 0) | |
(setq pyonpyon--xpos 0 | |
pyonpyon--x-velocity (- pyonpyon--x-velocity))) | |
((> next (- pyonpyon--max-x (frame-pixel-width))) | |
(setq pyonpyon--xpos (- pyonpyon--max-x (frame-pixel-width)) | |
pyonpyon--x-velocity (- pyonpyon--x-velocity))) | |
(t | |
(setq pyonpyon--xpos next))))) | |
(defun pyonpyon--update-ypos () | |
(let ((next (+ pyonpyon--ypos pyonpyon--y-velocity))) | |
(cond ((< next 50) | |
(setq pyonpyon--ypos 50 | |
pyonpyon--y-velocity (- pyonpyon--y-velocity))) | |
((> next (- pyonpyon--max-y (frame-pixel-height))) | |
(setq pyonpyon--ypos (- pyonpyon--max-y (frame-pixel-height)) | |
pyonpyon--y-velocity (- pyonpyon--y-velocity))) | |
(t | |
(setq pyonpyon--ypos next))))) | |
(defun pyonpyon--move-frame () | |
(pyonpyon--update-xpos) | |
(pyonpyon--update-ypos) | |
(set-frame-position (window-frame) pyonpyon--xpos pyonpyon--ypos)) | |
(defun pyonpyon--init () | |
(let* ((max-xy (pyonpyon--display-size)) | |
(max-x (car max-xy)) | |
(max-y (cdr max-xy)) | |
(unit-h (/ max-x 133.0)) | |
(unit-v (sqrt (* max-y pyonpyon-gravity 2)))) | |
(setq pyonpyon--max-x max-x | |
pyonpyon--max-y max-y | |
pyonpyon--x-velocity (floor unit-h) | |
pyonpyon--y-velocity (floor unit-v)) | |
(setq pyonpyon--xpos 0 pyonpyon--ypos 0))) | |
(defun pyonpyon () | |
(interactive) | |
(pyonpyon--init) | |
(setq pyonpyon--timer (run-with-timer 0 0.1 #'pyonpyon--move-frame))) | |
(defun pyonpyon-stop () | |
(interactive) | |
(cancel-timer pyonpyon--timer)) | |
(provide 'pyonpyon) | |
;;; pyonpyon.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment