(+) Costants.hs, (+) Unlicense, (^) README

This commit is contained in:
Francesco 2022-07-31 16:01:13 +02:00
parent 17e5d43a36
commit 12218be75c
6 changed files with 62 additions and 43 deletions

46
LICENSE
View File

@ -1,30 +1,24 @@
Copyright Author name here (c) 2022
This is free and unencumbered software released into the public domain.
All rights reserved.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
For more information, please refer to <http://unlicense.org/>

View File

@ -3,4 +3,14 @@ Amaranth is a small drawing app written in Haskell. It was
created as a small learning project, and it probably won't
be continued.
# 📸 Screenshots
This code is licensed with The Unlicense. Learn more at
https://unlicense.org/.
# ⚙️ How to use
Amaranth comes with two modes with which you can draw on
the screen:
- **brush mode**, which you can use by hitting B on the keyboard, and
- **eraser mode**, which you can use by pressing E.
# 📸 Screenshots
None by now. 😥

View File

@ -26,6 +26,7 @@ source-repository head
library
exposed-modules:
Canvas
Costants
Lib
other-modules:
Paths_amaranth

View File

@ -1,6 +1,6 @@
module Canvas where
import Graphics.Gloss.Data.Picture ( Picture (Text), pictures )
import Graphics.Gloss.Data.Picture ( Picture (Text), pictures, scale )
import Graphics.Gloss.Interface.IO.Interact ( Event (EventKey), KeyState (Down), Key (Char) )
data Canvas = Canvas {
@ -10,14 +10,11 @@ data Canvas = Canvas {
data Mode = Brush | Eraser deriving (Eq, Show)
initial :: Canvas
initial = Canvas {
items = []
, mode = Brush
}
showMode :: Canvas -> Picture
showMode canv = scale 0.1 0.1 $ Text ( show (mode canv))
render :: Canvas -> Picture
render canvas = pictures ( Text ( show (mode canvas)) : items canvas )
render canv = pictures ( showMode canv : items canv )
handle :: Event -> Canvas -> Canvas
handle (EventKey (Char 'b') Down _ _ ) canv = canv { mode = Brush }

16
src/Costants.hs Normal file
View File

@ -0,0 +1,16 @@
module Costants where
import Canvas
import Graphics.Gloss
display :: Display
display = InWindow "Amaranth" (500, 500) (0,0)
background :: Color
background = white
initial :: Canvas
initial = Canvas {
items = []
, mode = Brush
}

View File

@ -1,14 +1,15 @@
module Lib where
import Graphics.Gloss
import Canvas as C
-- Variables
display :: Display
display = InWindow "Amaranth" (500, 500) (0,0)
background :: Color
background = white
import Canvas
import Costants
app :: IO ()
app = play Lib.display background 60 C.initial C.render C.handle C.update
app = play
Costants.display -- Display type
Costants.background -- Background
60 -- FPS
Costants.initial -- Initial world
Canvas.render -- Render function
Canvas.handle -- Input hadler
Canvas.update -- Update function (unused, since we don't have to make animations)