Image/Pixel-Color Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Paint Operations >

Image/Pixel-Color Operations

ANA.DrawBox - Draw Box into IR

Previous Top Next


MiniRobotLanguage (MRL)

 

ANA.DrawBox

Draw a Box into an Image-Register (IR)

 

 

Intention

 

The ANA.DrawBox command allows you to create a box within an Image Register (IR). This box can be either an outline or filled, and can be drawn in a solid color or with an inverted background color.

 

Creating a Box with Inverted Colors:

In this example, we'll create a background and then draw a filled box over it. We'll use the color "-1", which signifies "Invert Background Color".

 

Please note, due to the loop running 255 iterations, it's recommended to initiate the script in the Editor using the "Freerun Mode". The robot's drawing will not be visible until the Show command is executed.

 

Remember, the ANA commands provide you with a set of 20 Image Registers.

You can specify one or more source registers and sometimes a destination register in each command.

If a destination register is not specified, the source register will be overwritten with the result of the operation.

You can copy or move content from one Image Register to another, load an image into these registers, or snapshot a localized window into these registers. After filling the Image Registers with content, you can perform several types of processing with these images, and finally save the pictures.

 

To use ANA, you'll first need to fill the Image Registers (IRs) with some content, which will be processed in subsequent steps.

The first 20 Image Registers can be used freely, while registers 21-32 are reserved for internal operations.

 

The Blit command uses the GPU for fast graphics operations, which may result in artifacts in some operations.

If you prefer to avoid these, you can use the "ANA.Logic" command, which uses the CPU.

 
                            Freerun

  You will not see the Robot Painting unless the Show command is been called.

 

 

ANA.New|0|800|400

ANA.vgradient|0|&HFF00FF|&H000000

ANA.New|2|800|400

ANA.hgradient|2|&H0000FF|&H00FFFF

ANA.Mix|0|2|7

ANA.Show|2!

ANA.DrawBox|2|100|50|200|150|-1|1

ANA.Show|2!

FOR.$$LJ7|1|255

  RND.0|740|$$XP1

  CAL.$$XP2=$$XP1+50

  RND.0|340|$$YP1

  CAL.$$YP2=$$YP1+50   

  ANA.DrawBox|2|$$XP1|$$YP1|$$XP2|$$YP2|-1|1   

NEX.

ANA.Show|2!

ENR.

 

 

 

DrawBox01     Drawbox2

This box is filled and it is drawn with inverted background color.                                                 The second Part of the Script will draw 255 random filled boxes.

 

 

In the below example you will not see "how the robot paints". To refresh the Debug Display you generally need to call the "ANA.Show" Command like this:

 

' In this Sample the Debug Display is updated after every DrawBox-Command.

ANA.New|0|800|400

ANA.vgradient|0|&HFF00FF|&H000000

ANA.New|2|800|400

ANA.hgradient|2|&H0000FF|&H00FFFF

ANA.Mix|0|2|7

FOR.$$LJ7|1|255

  RND.0|740|$$XP1

  CAL.$$XP2=$$XP1+50

  RND.0|340|$$YP1

  CAL.$$YP2=$$YP1+50   

  ANA.DrawBox|2|$$XP1|$$YP1|$$XP2|$$YP2|-1|1   

' Thiswill make the Drawing visible

  ANA.Show|2

  PAU..1

NEX.

ANA.Show|2!

ENR.

 

 

2. Draw only the Outline of the Box

 

In the following Script we will draw only the Outline of the box, not filling the box.

However we will draw 2500 Boxes. In "Freerun-Mode" this will take less than a second.

Infact the Robot can - in my test - draw up to 25000 unfilled Boxes per Second.

 

ANA.New|0|800|400

ANA.vgradient|0|&HFF00FF|&H000000

ANA.New|2|800|400

ANA.hgradient|2|&H0000FF|&H00FFFF

ANA.Mix|0|2|7

FOR.$$LJ7|1|2500

  RND.0|740|$$XP1

  CAL.$$XP2=$$XP1+120

  RND.0|340|$$YP1

  CAL.$$YP2=$$YP1+80   

  ANA.DrawBox|2|$$XP1|$$YP1|$$XP2|$$YP2|-1|0     

NEX.

ANA.Show|2!

ENR.

 

Here is the Speed-Dump:

Speed-Dump1

 

Here is the result:

DrawBox3

 

 

Syntax

 

ANA.DrawBox[|P1][|P2][|P3][|P4][|P5]

 

Parameter Explanation

 

P1 - Source Image-Register number

P2 - X1 - Upper Left Coordinat X-Value

P3 - Y1 - Upper Left Coordinat Y-Value

P4 - X1 - Lower Right Coordinat X-Value

P5 - Y1 - Lower Right Coordinat Y-Value

P6 - opt. Color-Value (like &HFF00FF), if omitted 0 is used. If -1 is given, the Pixel-Color will be inverted.

P7 - opt. Fill-Flag (0/1), if 1 the Box is filled. If its 0 the just the outline is been painted. If omitted 0 is used.

 

The Command will leave a 0 on the TOS in case of error, otherwise you get the number of copied patterns.

 

Example

 

'***********************************

' ANA.DrawBox-Sample

'***********************************

ANA.New|0|800|400

ANA.vgradient|0|&HFF00FF|&H000000

ANA.New|2|800|400

ANA.hgradient|2|&H0000FF|&H00FFFF

ANA.Mix|0|2|7

FOR.$$LJ7|1|25

  RND.0|740|$$XP1

  CAL.$$XP2=$$XP1+120

  RND.0|340|$$YP1

  CAL.$$YP2=$$YP1+80   

  ANA.DrawBox|2|$$XP1|$$YP1|$$XP2|$$YP2|-1|1   

  ANA.Show|2

  PAU..1

NEX.

ANA.Show|2!

ENR.

 

 

 

 

Remarks

A rather complex DrawBox-Command without Fill but with several Variables uses on my computer up to 640 Ticks. This is 1/25000 th of a second on my Computer.

A Drawbox invert or with color, with a filled Box can use more then 3000 Ticks on my Computer. Therefore the Robot could draw more then 5000 such filled Boxes per Second.

 

 

 

Limitations:

 

The Coordinates in the lower, right corner may not be smaller then the Coordinates in the upper, right ccorner.

 

 

See also: