# Be the Creator of your world

PixelsWorld documentation version: v3.4.2
Author ZzStarSound
History
v2.3.1
v1.0

## Welcome to PixelsWorld!

We have compressed all essence of how to use PixelsWorld into this section. If you master it, you will be a new creator of PixelsWorld!

## Simply speaking

PixelsWorld draws graphics basing on your code

• You can apply presets written by others.
• By learning code's grammar, you can write code to draw the scene by yourself.
• By learning GLSL, you can create an advanced visual effect by yourself.

## How to do it?

Let's begin with regarding PixelsWorld as a Painting robot. If you tell it what/where to draw step-by-step, it will draw graphics into the current layer for you.

For instance, consider the case you want to draw a house to the center of the layer, but the painter is your friend Andrew (and Andrew doesn't know what you want to draw). How to make the instructions so that Andrew can draw them for you?

We might say:

DrawHouse.myBro

Draw a house to the center of the layer


This is OK, but what if you cannot directly tell Andrew the answer, but 1. where to draw, 2. what to draw, 3. the color instead, maybe we can say:

DrawHouse2.myBro

move the paintbrush to the center
use yellow pigment
draw a 10x10cm square
move the paintbrush 5cm upward
use red pigment
draw a 15cm base length, 10cm height isosceles triangle.


You and Andrew will complete the masterpiece of a house!

Indeed, the instructions above is exactly what we need to code in PixelsWorld. It finally looks like this:

DrawHouse3.lua

version3() -- Use version 3, this is what you always have to call in the first line.
move(width/2, height/2) -- Move the Paintbrush Coordinate to the center
rotateX(PI) -- Rotate Paintbrush Coordinate along X axis 180 degrees
fill(1,1,0) -- Use yellow pigment (Red=1,Green=1,Blue=0)
rect(100) -- Draw a 100x100px square
fill(1,0,0) -- Use red pigment(Red=1,Green=0,Blue=0)
move(0,50) -- Move the Paintbrush Coordinate 50px upwards
tri(150,100) -- Draw a isoceles triangle in 150px of base, 100px of height.


There is a function rotateX(PI) not mentioned above. Because the default orientation of the Y-axis of Paintbrush Coordinate is downward, we need to rotate it along with the X-axis 180 degrees (PI radians) to make it upward. Otherwise, the following move(0,50) function would move it 50cm downward.

Here we want to add some extra controls to the scene like color combination controllers of our house.

DrawHouse3.lua

version3() -- Use version 3, this is what you always have to call in the first line.
move(width/2, height/2) -- Move the Paintbrush Coordinate to the center
rotateX(PI) -- Rotate Paintbrush Coordinate along X axis 180 degrees
fill(color(0)) -- Use color #0
rect(100) -- Draw a 100x100px square
fill(color(1)) -- Use color #1
move(0,50) -- Move the Paintbrush Coordinate 50px upwards
tri(150,100) -- Draw a isoceles triangle in 150px of base, 100px of height.


Then click the Ok button, the house will... disappear!

Indeed, our house is still drawn onto the layer, but because the default color of the color controller is black, so as a result, the house seems to disappear.

To fix it, open the Parameter list, find the first 2 Color controllers, change them to whatever you want.

## Mayor is me! Draw more houses

One tremendous advantage of code is the capability of handling repetitive operations.

Needless to say, Lua language allows you to write looping code.

DrawHouse3.lua


version3() -- Use version 3, this is what you always have to call in the first line.
move(width/2, height/2) -- Move the Paintbrush Coordinate to the center
rotateX(PI) -- Rotate Paintbrush Coordinate along X axis 180 degrees
for i=1,3 do -- Begin repeat (3 times)
fill(color(0)) -- Use color #0
rect(100) -- Draw a 100x100px square
fill(color(1)) -- Use color #1
move(0,50) -- Move the Paintbrush Coordinate 50px upwards
tri(150,100) -- Draw a isoceles triangle in 150px of base, 100px of height.
move(0,-50) -- Move the Paintbrush Coordinate back
move(175,0) -- Move the Paintbrush Coordinate 175px rightward
end -- End repeat


If you don't want to write functions like "move back". Write in this way:

DrawHouse3_1.lua


version3() -- Use version 3, this is what you always have to call in the first line.
move(width/2, height/2) -- Move the Paintbrush Coordinate to the center
rotateX(PI) -- Rotate Paintbrush Coordinate along X axis 180 degrees
for i=1,3 do -- Begin loop (3 times)
fill(color(0)) -- Use color #0
rect(100) -- Draw a 100x100px square
fill(color(1)) -- Use color #1
beginGroup() -- NEW LINE! Begin to record transformations of Paintbrush Coordinate
move(0,50) -- Move the Paintbrush Coordinate 50px upwards
tri(150,100) -- Draw a isoceles triangle in 150px of base, 100px of height.
endGroup() -- NEW LINE! This line will automatically calls 'move(0,-50)'
move(175,0) -- Move the Paintbrush Coordinate 175px rightward
end -- End loop


Finally, we want to give the controllers names:

## Save code as a preset.

Note: The Administrator mode is required in this step if you installed Ae into the disc where your system files are (like C:\).

First of all, add a new Preset column into the popup list:

Then, save your preset into the newly created Preset column:

### Apply preset

Select the preset you want to apply, click the Replace button in Presets review area.

## Congratulations!

You have already mastered almost all of PixelsWorld.

>>> Next step: Go to the lua chapter for more details