locatexy doesn't draw your text with the bottom-left corner at (x,y), it draws it at the closest row and column to (x,y). It "snaps-to", if you will.
To fix your problem, use fonts.
Turing: |
setscreen ("graphics:400, 400")
var fontNumbers := Font.New ("Times New Roman:12")
procedure DrawTheCell (x, y, w, h : int)
var clr : int := 255
if (x + y ) mod 2 = 0 then
clr := 0
end if
drawfillbox (x * w, (y + 1) * h, (x + 1) * w, (y ) * h, clr )
end DrawTheCell
var w : int := 40
var h : int := 40
drawfillbox (0, 0, maxx, maxy, 50)
%You don't have to go through the whole list like that. The first thing to do is try to recognize a pattern in your initialized array.
%in this case, it's the letters of the alaphbet. Open up your ASCII chart, we're going to make this shorter!
var letters : array 1 .. 8 of string
for i : 1 .. upper (letters )
letters (i ) := chr (64 + i ) %or for lowercase letters, (96 + i)
end for
%if you don't like that, you could always use init.
%var letters : array 1 .. of of string := init ("A", "B", "C", "D", "E", "F", "G", "H")
for i : 1 .. 8
locatexy (i * w + w div 2, h div 2)
colorback (50)
put letters (i )
end for
for decreasing j : 8 .. 1
%Font.Draw (intstr (j), w div 2, j * h + h div 2, fontNumbers, black) %-- this is using the code you used for locatexy.
% I modified it a bit to centre the numbers
Font.Draw (intstr (j ), w div 2, j * h + h div 2 - 6, fontNumbers, black) %the -6 is to centre the numbers. I'm using 12 point font,
% which means that each "tall" character (such as "h", "1", or "t") is 12 pixels high. So, we want half the number above the
% centre-line, and half below, so we subtract 6.
end for
for i : 1 .. 8
for decreasing j : 8 .. 1
DrawTheCell (i, j, w, h )
end for
end for
|
|