mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-04 01:25:04 +03:00
Replaced example in README.md
This commit is contained in:
parent
344e4abcf5
commit
45882daafa
34
README.md
34
README.md
@ -26,34 +26,26 @@ The key features of Carp are the following:
|
||||
* [Carp Language Guide](docs/LanguageGuide.md) - syntax and semantics of the language
|
||||
* [Libraries](docs/Libraries.md) - how to work with libraries and modules
|
||||
* [Tooling](docs/Tooling.md) - supported editors
|
||||
* [Game Example](examples/game.carp) - an example of how to use SDL with Carp
|
||||
* [Game Example](examples/reptile.carp) - a Snake clone in Carp
|
||||
|
||||
The Carp REPL has built-in documentation, run ```(help)``` to access it!
|
||||
|
||||
## A Small Example
|
||||
## A Very Small Example
|
||||
|
||||
```clojure
|
||||
(use IO)
|
||||
(use Int)
|
||||
(use String)
|
||||
(load-and-use SDL)
|
||||
|
||||
(defn tick [state]
|
||||
(+ state 10))
|
||||
|
||||
(defn draw [app rend state]
|
||||
(bg rend &(rgb @state (/ @state 2) (/ @state 3))))
|
||||
|
||||
(defn main []
|
||||
(do (println "~ The number guessing game ~")
|
||||
(print "Please enter a number between 1 - 99: ")
|
||||
(let [play true
|
||||
answer (random-between 1 100)]
|
||||
(while play
|
||||
(let [guess (get-line)
|
||||
num (from-string &guess)]
|
||||
(if (= &guess "q\n")
|
||||
(do
|
||||
(println "Good bye...")
|
||||
(set! play false))
|
||||
(do
|
||||
(cond (< num answer) (println "Too low.")
|
||||
(> num answer) (println "Too high.")
|
||||
(println "Correct!"))
|
||||
(print "Please guess again: "))))))))
|
||||
(let [app (SDLApp.create "The Minimalistic Color Generator" 400 300)
|
||||
state 0]
|
||||
(SDLApp.run-with-callbacks &app SDLApp.default-event-handler tick draw state)))
|
||||
|
||||
```
|
||||
|
||||
To build this example, save it to a file called 'example.carp' and load it with ```(load "example.carp")```, then execute ```(build)``` to build an executable, and ```(run)``` to start.
|
||||
|
@ -1,17 +1,12 @@
|
||||
(load "SDL.carp")
|
||||
(load-and-use SDL)
|
||||
|
||||
(defn tick [s]
|
||||
(inc s))
|
||||
(defn tick [state]
|
||||
(+ state 10))
|
||||
|
||||
(defn draw [app rend state-ref]
|
||||
(let [mouse-state (SDL.MouseState.get)
|
||||
rect (SDL.rect 50 50 @(SDL.MouseState.x &mouse-state) 200)]
|
||||
(do
|
||||
(SDL.set-render-draw-color rend @state-ref 0 0 255)
|
||||
(SDL.render-clear rend)
|
||||
(SDL.set-render-draw-color rend 200 250 255 255)
|
||||
(SDL.render-fill-rect rend (address rect)))))
|
||||
(defn draw [app rend state]
|
||||
(bg rend &(rgb @state (/ @state 2) (/ @state 3))))
|
||||
|
||||
(defn main []
|
||||
(let [app (SDLApp.create "Minimal" 400 300)]
|
||||
(SDLApp.run-with-callbacks &app SDLApp.default-event-handler tick draw 0)))
|
||||
(let [app (SDLApp.create "The Minimalistic Color Generator" 400 300)
|
||||
state 0]
|
||||
(SDLApp.run-with-callbacks &app SDLApp.default-event-handler tick draw state)))
|
||||
|
Loading…
Reference in New Issue
Block a user