Open ckp95 opened 2 years ago
import pixels
type
x: int
y: int
type
Direction = enum
Horizontal
Vertical
# Create a proc to draw a horizontal line
proc drawHorizontalLine(start: Point, length: Positive) =
for delta in 0 .. length:
putPixel(start.x + delta, start.y)
# Create a proc to draw a vertical line
proc drawVerticalLine(start: Point, length: Positive) =
for delta in 0 .. length:
putPixel(start.x, start.y + delta)
# Create a proc that will combine both drawHorizontal and drawVertical
proc drawLine(start: Point, length: Positive, direction: Direction) =
case direction
of Horizontal:
drawHorizontalLine(start, length)
of Vertical:
drawVerticalLine(start, length)
# crate a point with coordinates x: 60, y: 40
let a = Point(x: 60, y: 40)
# Call drawLine
drawLine(a, 50, Horizontal)
drawLine(a, 30, Vertical)
Archlinux x86-64 nim 1.6.8
I can't get the drawText to work at all , but putPixel does print lines for me in the canvas window.
I have sdl2 installed also.
I figured it out you need Mozilla's Fira-sans ttf fonts.
I have the "Mastering Nim" book. Trying to run the first code example:
import pixels # needed to install sdl2 and sdl2_tff put_pixel(5, 9) put_pixel(11, 18, Red)
(btw the book didn't say I needed the
sdl2
andsdl2_tff
libraries; kept getting compilation errors until I figured it out)Anyway, I run this example and a window appears, but nothing is in it. It just shows the background pixels fixed in place:
untitled.mp4 Is there anything else I need to install to make this work? Or some kind of config setting?
OS is Manjaro Linux KDE.
You need Mozilla Fira-sans ttf , do this.
sudo pacman -S ttf-fira-sans
Solution on WSL2 Ubuntu: Change the font directory and font that pixels.nim
uses, which can be found in ~/.nimble/pkgs2/pixels[...etc]
. This is the correction that worked for me. Others will have to point pixels.nim
to a font that is already at /usr/share/fonts/[TTF or truetype]/
:
elif defined(linux):
const location = r"/usr/share/fonts/truetype/"
.
.
.
elif defined(linux): "dejavu/DejaVuSans"
Explanation:
pixels.nim
on Linux expects fonts to be installed at /usr/share/fonts/TTF/
and also expects the presence of the font FiraSans.ttf
. /usr/share/fonts/truetype/
and FiraSans is not a font in the repo (afact). FiraCode, but FiraCode doesn't contain a FiraSans.ttf
.FiraSans
online, I simply pointed pixels.nim
to what already exists on my computer.For the maintainer @Araq , it looks like on Linux, the default font absolute path can be found via the shell command^1:
fc-match --format=%{file}
This approach may be better than hard-coding fonts and their locations^2. I don't know enough Nim yet to change pixels myself. If the issue still exists when I'm more familiar, I'll give it a go.
But then how can I find the command to use in order to find the font locations? Maybe on Dünnpfiff-Linux fc-match
does not exist?
That's true; my Kali installation doesn't have fc-match
. Maybe pixels could come with a font and just reference that, as I didn't find an obvious OS-independent solution.
I have the "Mastering Nim" book. Trying to run the first code example:
(btw the book didn't say I needed the
sdl2
andsdl2_tff
libraries; kept getting compilation errors until I figured it out)Anyway, I run this example and a window appears, but nothing is in it. It just shows the background pixels fixed in place:
https://user-images.githubusercontent.com/43073868/177007927-34349cce-9341-4960-b871-7c344335d6af.mp4
Is there anything else I need to install to make this work? Or some kind of config setting?
OS is Manjaro Linux KDE.