The new DRAWing command

This forum is dedicated to those who wish to suggest new features.
Questo forum è dedicato a chi desidera suggerire nuove feature.
Ce forum est dédié à ceux qui souhaitent suggérer de nouvelles fonctionnalités.
Post Reply
spotlessmind1975
Site Admin
Posts: 149
Joined: Fri Oct 06, 2023 8:25 pm

The new DRAWing command

Post by spotlessmind1975 »

[italian and french follow]

:arrow: ENGLISH

Hi everyone!

With the new version (and from the beta version) a new command has been introduced: DRAW.When you draw a figure onto a piece of paper, your pen starts at a particular place and it moves up or right for a certain amount, then down, and so on. The DRAW command allows you to repeat this process on the screen. The syntax is:

Code: Select all

DRAW string
where string is either a string constant, or a string variable, containing a set of the draw subcommands. The commands can be separated by a semi-colon. Note that it is not required, you can use it to make the string easier to read. Usually the first action of any drawing is to move to the start point.
Image
M x,y means move to the coordinates given by x,y, as in M128,96. This will move the pen to screen centre (if the screen has a resolution of 256x192 pixels). When you move to a point it is usually a good idea to make a "blank" move, that is move without drawing or lifting the pencil off the paper. If you do not you may get unwanted lines on your drawing. A blank move is done by using the letter B, any drawing instruction following the B will be drawn as a blank line (in other words: no modifications will be made).

Having decided the start point, you may now move up (U), down (D), right (R), or Left (L) by as many points as you like. The sequence U20R20D20L20 will cause a line to be drawn upwards 20 points for the start, then to the right 20, then down 20 and left 20, drawing a square. Apart from vertical and horizontal lines you can also draw diagonal lines. These use the subcommands E, F, G and H. So E12 will draw a diagonal line, 12 points long, at 45 degrees from the vertical. This allows diagonal lines to be drawn in any of 4 directions.

Code: Select all

DRAW "BM10,10;D4R4U4;BR2NR4D4R4UL2"
This command will draw a "UG". The computer remembers its last position so line will continue drawing from that point. The drawed object is drawn in the default foreground colour, but you can alter that, if we all want by using C. The letter C is followed by a number from 0 to COLOR COUNT:

Code: Select all

DRAW "BM10,10;C40;D4R4U4;C20;BR2NR4D4R4UL2"
and we now have a two-tone "UG"! The drawing can be painted exactly the same way as other shapes, but the C command changes the default foreground colour, so care is needed to avoid painting over everything.

If the drawing is a bit small, we wall scale it up with the S parameter. The S means scale, and allows a drawing, or parts of a drawing to be scaled up or down in units of 1/4 (0,25). So S1 reduces the drawing to 1/4 scale, S2 to 2/4 (half) scale, S8 to 8/4 (2x) scale, and so on. The default setting for scale is S4 as the original size. Another option available is the angle parameter A. This allows us to rotate all or part of the drawing, as all lines after the A will be drawn with the displacement given by An, where n is a number between 0 and 3, as follows: 0 = 0 degrees, 1 = 90 degrees, 2 = 180 degrees, 3 = 270 degrees.

These are just the first instructions: now it's time to try it it!

:arrow: ITALIAN

Ciao a tutti!

Con la nuova versione (e dalla versione beta) è stato introdotto un nuovo comando: DRAW. Quando si disegna una figura su un pezzo di carta, la penna inizia da un punto particolare e si sposta verso l'alto o verso destra per un certo periodo, poi va verso il basso e così via. Il comando DRAW consente di ripetere questo processo sullo schermo. La sintassi è:

Code: Select all

DRAW string
dove string è una costante stringa o una variabile stringa contenente un insieme di sottocomandi per disegnare. I comandi possono essere separati da un punto e virgola. Tieni presente che non è obbligatorio, che si può usare il punto e virgola per rendere la stringa più facile da leggere. Di solito la prima azione è spostarsi al punto iniziale.
Image
M x,y significa spostarsi alle coordinate date da x,y, come in M128,96. Ciò sposterà la penna al centro dello schermo (se lo schermo ha una risoluzione di 256x192 pixel). Quando ci si sposta verso un punto, di solito è una buona idea fare una mossa "a vuoto", cioè spostarsi senza disegnare o sollevare la matita dal foglio. In caso contrario si possono ottenere linee indesiderate sul disegno. Una mossa vuota viene eseguita utilizzando la lettera B. Qualsiasi istruzione di disegno che segue la B verrà disegnata come una riga vuota (in altre parole: non verrà apportata alcuna modifica sullo schermo).

Dopo aver deciso il punto di partenza, ci si può spostare in alto (U), in basso (D), a destra (R) o a sinistra ([ b]L[/b]). La sequenza U20R20D20L20 farà sì che venga tracciata una linea verso l'alto di 20 punti per l'inizio, poi a destra di 20, poi in basso di 20 e a sinistra di 20 punti, disegnando quindi un quadrato. Oltre alle linee verticali e orizzontali si possono anche disegnare linee diagonali. Queste utilizzano i sottocomandi E, F, G e H. Quindi E12 disegnerà una linea diagonale, lunga 12 punti, a 45 gradi dalla verticale. Ciò consente di tracciare linee diagonali in una qualsiasi delle 4 direzioni.

Code: Select all

DRAW "BM10,10;D4R4U4;BR2NR4D4R4UL2"
Questo comando disegnerà un "UG". Il computer ricorda la sua ultima posizione quindi la linea continuerà a tracciare da quel punto. L'oggetto disegnato viene colorato con il colore della penna attuale, ma può essere modificato utilizzando il comando C. La lettera C è seguita da un numero da 0 a COLOR COUNT:

Code: Select all

DRAW "BM10,10;C40;D4R4U4;C20;BR2NR4D4R4UL2"
e ora abbiamo un "UG" bicolore! Il disegno può essere dipinto esattamente allo stesso modo delle altre forme, ma il comando C cambia il colore della penna, quindi è necessario fare attenzione a evitare di dipingere sopra tutto.

Se il disegno è un po' piccolo, lo si può ingrandire con il parametro S. S significa "scala" e consente di ingrandire o ridurre un disegno o parti di esso in unità di 1/4 (0,25). Quindi S1 riduce il disegno a 1/4 di scala, S2 a 2/4 (metà) scala, S8 a 8/4 (2x) scala e così via. L'impostazione predefinita per la scala è S4 cioè come la dimensione originale. Un'altra opzione disponibile è il parametro A. Questo permette di ruotare tutto o parte del disegno, poiché tutte le linee dopo la A verranno disegnate con lo spostamento dato da An, dove n è un numero compreso tra 0 e 3, come segue: 0 = 0 gradi, 1 = 90 gradi, 2 = 180 gradi, 3 = 270 gradi.

Queste sono solo le prime istruzioni: ora è il momento di provarlo!

:arrow: FRENCH

Avec la nouvelle version (et depuis la version bêta) une nouvelle commande a été introduite: DRAW. Lorsque vous dessinez une figure sur une feuille de papier, votre stylo commence à un endroit particulier et se déplace vers le haut ou vers la droite d'un certain montant, puis vers le bas, et ainsi de suite. La commande DRAW vous permet de répéter ce processus à l'écran. La syntaxe est :

Code: Select all

DRAW chaîne
string est soit une constante de chaîne, soit une variable de chaîne, contenant un ensemble de sous-commandes draw. Les commandes peuvent être séparées par un point-virgule. Notez que ce n’est pas obligatoire, vous pouvez l’utiliser pour rendre la chaîne plus facile à lire. Habituellement, la première action de tout dessin consiste à se déplacer vers le point de départ.
Image
M x,y signifie se déplacer vers les coordonnées données par x,y, comme dans M128,96. Cela déplacera le stylet au centre de l'écran (si l'écran a une résolution de 256 x 192 pixels). Lorsque vous vous déplacez vers un point, c'est généralement une bonne idée de faire un mouvement "à blanc", c'est-à-dire sans dessiner ni soulever le crayon du papier. Si vous ne le faites pas, vous risquez d'avoir des lignes indésirables sur votre dessin. Un coup à blanc se fait en utilisant la lettre B, toute instruction de dessin suivant le B sera dessinée comme une ligne vierge (en d'autres termes : aucune modification ne sera apportée).

Après avoir décidé du point de départ, vous pouvez maintenant vous déplacer vers le haut (U), vers le bas (D), vers la droite (R) ou vers la gauche ([ b]L[/b]) par autant de points que vous le souhaitez. La séquence U20R20D20L20 fera tracer une ligne vers le haut de 20 points pour le départ, puis vers la droite 20, puis vers le bas 20 et vers la gauche 20, dessinant un carré. Outre les lignes verticales et horizontales, vous pouvez également tracer des lignes diagonales. Ceux-ci utilisent les sous-commandes E, F, G et H. Ainsi, E12 tracera une ligne diagonale de 12 points de long, à 45 degrés de la verticale. Cela permet de tracer des lignes diagonales dans l'une des 4 directions.

Code: Select all

DRAW "BM10,10;D4R4U4;BR2NR4D4R4UL2"
Cette commande dessinera un "UG". L'ordinateur se souvient de sa dernière position et la ligne continuera donc à tracer à partir de ce point. L'objet dessiné est dessiné dans la couleur de premier plan par défaut, mais vous pouvez la modifier, si nous le souhaitons tous, en utilisant C. La lettre C est suivie d'un nombre compris entre 0 et COLOR COUNT :

Code: Select all

DRAW "BM10,10;C40;D4R4U4;C20;BR2NR4D4R4UL2"
et nous avons maintenant un "UG" bicolore ! Le dessin peut être peint exactement de la même manière que les autres formes, mais la commande C modifie la couleur de premier plan par défaut, il faut donc faire attention à éviter de peindre par-dessus tout.

Si le dessin est un peu petit, nous l'agrandissons avec le paramètre S. Le S signifie échelle et permet d'agrandir ou de réduire un dessin ou des parties d'un dessin par unités de 1/4 (0,25). Ainsi, S1 réduit le dessin à l'échelle 1/4, S2 à 2/4 (demi), S8 à 8/4 (2x) escaliers, etc. Le paramètre par défaut pour l'échelle est S4 comme taille d'origine. Une autre option disponible est le paramètre d'angle A. Cela nous permet de faire pivoter tout ou partie du dessin, car toutes les lignes après le A seront dessinées avec le déplacement donné par An, où n est un nombre compris entre 0 et 3, comme suit : 0 = 0 degré, 1 = 90 degrés, 2 = 180 degrés, 3 = 270 degrés.

Ce ne sont que les premières instructions : maintenant, il est temps de l'essayer !
spotlessmind1975
Site Admin
Posts: 149
Joined: Fri Oct 06, 2023 8:25 pm

Re: The new DRAWing command

Post by spotlessmind1975 »

Someone asked if this command execute faster than several draws instructions or is it just a syntaxic shortcut.

So, let's assume that the code is written in Median language (sorry, I couldn't find a better name). The Median language is a sort of "portable assembly", a cross between pure and simple assembly and ugBASIC code. It usually runs faster than ugBASIC, although it often uses its primitives (so: it pays penalties) but less quickly than writing an implementation for the various processors from scratch.

Anyway, in this specific case, the actual drawing uses the routines of the DRAW (LINE) command [written in Median Language], which in turn uses the PLOT routines [written in assembly].

So, in theory, it should be the same speed. In reality, DRAW has to manage two somewhat unfortunate cases: scaling and angle. These are two parameters that require calculations for each coordinate. Which, always in theory, could be slower than simple drawing. However, if you have to do it anyway, it should be faster because there are no intermediate copies, and the peephole optimizer doesn't have to struggle to make things faster.

In short: we need to do benchmarks!
ldir_hector
Posts: 12
Joined: Sun Oct 08, 2023 11:47 am

Re: The new DRAWing command

Post by ldir_hector »

I'm sorry but I don't understand the N in BR2NR4D4R4UL2
spotlessmind1975
Site Admin
Posts: 149
Joined: Fri Oct 06, 2023 8:25 pm

Re: The new DRAWing command

Post by spotlessmind1975 »

Hi ldir_hector!
ldir_hector wrote: Wed Nov 22, 2023 5:54 pm I'm sorry but I don't understand the N in BR2NR4D4R4UL2
The N command has the meaning of no update of drawing position.
This is to draw a line as specified but do not use the end of the line as the new position.
So, NR4D4 means: "draw a line of 4 pixel on the right (R4), go back to the origin (N) of the line, draw a line of 4 pixel down (D)".
Post Reply