DIKU.Canvas 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DIKU.Canvas --version 1.0.0
NuGet\Install-Package DIKU.Canvas -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DIKU.Canvas" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DIKU.Canvas --version 1.0.0
#r "nuget: DIKU.Canvas, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DIKU.Canvas as a Cake Addin
#addin nuget:?package=DIKU.Canvas&version=1.0.0

// Install DIKU.Canvas as a Cake Tool
#tool nuget:?package=DIKU.Canvas&version=1.0.0

The DIKU.Canvas library

<img src="https://raw.githubusercontent.com/kfl/img-util-fs/main/images/turtle.png" border="2" width="250" align="right">

This library features a number of utility functions for drawing simple 2d graphics on a canvas, including features for running simple user-interactive apps that display such canvas. A small DSL for drawing using turtle graphics is included.

Features for loading a canvas from an image file and saving canvas to .png are included. They should work out of the box on Windows, but on Linux and MacOS they require the user to have SDL2 installed locally.

The library, which is based on SDL2, is portable, in the sense that applications built using the library can execute on Linux, macOS, and Windows using .NET6.0.

The library is intended to be built (and consumed) as a NuGet package.

The API

The library API is available in the file canvas.fsi.

How to use Canvas in a F# script (.fsx)

Make an F# script, say example.fsx and make a NuGet reference:

#r "nuget:DIKU.Canvas";;

Or, if you want a specific version:

#r "nuget:DIKU.Canvas, 1.0.0";;

How to use Canvas in a F# project (that uses .fsproj)

Make an new directory, say mycanvasapp, in that directory start a F# "Console App" project with the command:

dotnet new console -lang "F#"

(This will give you both a Program.fs file and a mycanvasapp.fsproj file.)

Add a reference to the DIKU.Canvas package with the command:

dotnet add package DIKU.Canvas

Edit Program.fs to have the content:

let draw width height =
    let canvas = Canvas.create width height
    Canvas.setFillBox canvas Canvas.blue (0,0) (width, height)
    canvas

do Canvas.runSimpleApp "Hello from F#" 400 400 draw

Run your app with the command:

dotnet run

This should result in a window with a blue background.

Examples

<img src="images/applespiral.png" border="2" width="250" align="right">

A number of examples are available in the examples folder.

The best show-cases for using the library are

  • examples/color_boxes.fsx
  • examples/keyboard_example.fsx
  • examples/spiral.fsx
  • examples/turtle.fsx (eventually)

Note that it is not all the examples in the examples directory that have been ported to the current version of the Canvas library.

How to build the Canvas library itself (if you want to contribute)

If you want to build the library and NuGet package yourself, you will need the .NET6.0 SDK and development versions of SDL2 and SDL2_image for your platform.

First install .NET 6 for your platform.

Then install SDL2 and SDL2_image:

  • On macOS with homebrew:

    brew install sdl2 sdl2_image
    
  • On Debian and Ubuntu:

    apt install libsdl2-dev libdl2-image-dev
    
  • On Arch (and probably Manjaro), sdl2 is available in extra:

    sudo pacman -S sdl2 sdl2_image
    
  • On Windows you need SDL2.dll and SDL2_image.dll in a search path available to dotnet. The .dll's in the lib/ folder should be sufficient for building. (Better instructions are a welcome contribution if anyone builds on Windows)

Finally, compile the library:

dotnet build

And pack it into a NuGet package:

dotnet pack

The package will be available in bin/Debug/Canvas.X.y.z.nupkg.

Using the NuGet package from a local repository

Start by creating a directory to use as a local NuGet repository. Add it to the NuGet sources list:

dotnet nuget add source /full/path/to/the/directory

Ensure the repository was added with:

dotnet nuget list source

Place Canvas.X.y.z.nupkg in the local repository. Now clear the nuget cache:

dotnet nuget locals all -c

Test that everything worked with dotnet fsi

dotnet fsi
>#r "nuget:DIKU.Canvas";;
>open Canvas;;

Canvas is now available to use in projects through NuGet, both in the interpreter and in projects with e.g. .fsproj files.

License

MIT license

Copyright 2018-2021 - Martin Elsman

Contributions

The following individuals have contributed to the DIKU.Canvas (previosly ImgUtil) library:

  • Ken Friis Larsen
  • Mads Dyrvig Obitsø Thomsen
  • Jan Rolandsen
  • Jon Sporring
  • Chris Pritchard (SDL P/Invoke)
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 109 3/9/2024
2.0.2 647 9/22/2023
2.0.2-alpha1 75 9/22/2023
2.0.1 571 9/6/2023
2.0.0 794 9/1/2023
2.0.0-beta1 113 8/27/2023
2.0.0-alpha8 113 8/22/2023
2.0.0-alpha7 117 8/20/2023
1.0.2.1 179 8/5/2023
1.0.2 178 8/5/2023
1.0.1 1,046 9/11/2022
1.0.1-alpha 153 9/10/2022
1.0.0 1,024 9/4/2022
1.0.0-alpha3 142 9/4/2022
1.0.0-alpha2 276 9/1/2022
1.0.0-alpha1 154 9/1/2022
1.0.0-alpha 142 9/1/2022