Created
July 7, 2014 16:29
-
-
Save glorphindale/1b97f91d101e888c1541 to your computer and use it in GitHub Desktop.
Коэффициенты косинуса и синуса
This file contains hidden or 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
(ns visimath.circles | |
(:import [java.awt.event KeyEvent]) | |
(:require [quil.core :as qc])) | |
(def state (atom {:sin 1 :cos 1})) | |
(defn deg->pos [radius deg cos-k sin-k] | |
(let [rads (qc/radians (* 1 deg)) | |
posx (* radius (Math/cos (* cos-k rads))) | |
posy (* radius (Math/sin (* sin-k rads)))] | |
[posx posy])) | |
(def psize 10) | |
(defn draw [] | |
(let [ts (rem (qc/frame-count) 360) | |
cos-k (@state :cos) | |
sin-k (@state :sin) | |
center-x (/ (qc/width) 2) | |
center-y (/ (qc/height) 2) | |
[posx posy] (deg->pos 100 ts cos-k sin-k)] | |
(qc/with-fill [0 10] | |
(qc/rect 0 15 (qc/width) 35) | |
(qc/rect 15 0 35 (qc/height))) | |
(qc/with-fill [255 25] | |
(qc/with-translation [center-x center-y] | |
(qc/ellipse posx posy psize psize)) | |
(qc/with-translation [center-x 20] | |
(qc/ellipse posx 20 psize psize)) | |
(qc/with-translation [20 center-y] | |
(qc/ellipse 20 posy psize psize))) | |
)) | |
(defn setup [] | |
(qc/smooth) | |
(qc/no-stroke) | |
(qc/background 0) | |
(qc/frame-rate 60) | |
(swap! state (fn [_] {:cos 1 :sin 1}))) | |
(defn key-pressed [] | |
(qc/background 0) | |
(cond | |
(= (qc/key-code) KeyEvent/VK_DOWN) | |
(swap! state update-in [:cos] dec) | |
(= (qc/key-code) KeyEvent/VK_UP) | |
(swap! state update-in [:cos] inc) | |
(= (qc/key-code) KeyEvent/VK_LEFT) | |
(swap! state update-in [:sin] dec) | |
(= (qc/key-code) KeyEvent/VK_RIGHT) | |
(swap! state update-in [:sin] inc))) | |
(qc/defsketch circles | |
:title "Circles" | |
:size [400 400] | |
:draw draw | |
:setup setup | |
:key-pressed key-pressed | |
:renderer :opengl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment