Pixel art updated!
by sonone, May 4, 2021, 12:13 PM
I created a code that works to create pixel drawings with ease:
How to use
Simply type
after the source code. You must replace <h> and <w> with the height and width of you picture in mind. When you fill in <colors>, the first color will be assigned to a, the second b, and etc, until z. you cannot have more than 26 colors, The formatting for the string <code> is thus:When you type a letter, you will get the corresponding color
A dash (-) creates an invisible pixel
A any other character (preferably a space or new line) breaks the row you are in and takes you into the next
Examples
chess board
![[asy]
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(8,8,
"abababab
babababa
abababab
babababa
abababab
babababa
abababab
babababa
",black, white);[/asy]](//latex.artofproblemsolving.com/8/f/0/8f0778e56d5352b9f9ba2077548d49ca4a7e59f9.png)
house
![[asy]
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(10,10,
"----aa----
---aaaa---
--aaaaaa--
-aaaaaaaa-
aaaaaaaaaa
bbbbbbbbbb
bbaabbbbbb
bbaabbaabb
bbaabbaabb
bbaabbbbbb
",brown,red);[/asy]](//latex.artofproblemsolving.com/9/1/7/917155fb941a88de270f1ad82f73ca3c1e7bf46d.png)
dolphin![[asy]
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(15,15,
"--------aa-----
-------ada-----
----aaaddaa----
---addddccda---
--adbbcccccda--
-aadabccccccda-
addccccdbbccca-
-aaaaaaddabccda
----acaadaabcca
-----a--aa-acca
-----------aca-
----------aaca-
---------acca--
----------aca--
-----------a---
", black, white, deepcyan+royalblue+white, heavycyan+.1*white);
[/asy]](//latex.artofproblemsolving.com/2/6/b/26b8da8a0f66a372891768ba392fa2dd646358d1.png)
turtle
![[asy]
//Made by sonone
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(9,23,
"-------------aaaa-------
----------aaabbbbaaa----
---aaa--aabababbababaa--
-aaecdaabbabbbaabbbabba-
addddddabbabbabbabbabba-
-aaaaaaaaaaaabbbbaaaaaaa
-------addddaaaaaadddda-
--------adda------adda--
-------aaaaa-----aaaaa--
", black, deepgreen, white, brown, orange);
[/asy]](//latex.artofproblemsolving.com/d/b/c/dbc54405d15c209d8115c9bb3e85a61b3896103e.png)
void drawPenArray(pen[][] pixel = {{red}}) { for (int i = 0; i < pixel.length; ++i) { for (int j = 0; j < pixel[i].length; ++j) { fill(shift(j,-i)*unitsquare,pixel[i][j]); } } } void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette string letters = "abcdefghijklmnopqrstuvwxyz-"; defaultpen(invisible); int h = 0; int w = 0; pen[][] layout = new pen[height][width]; for (int i = 0; i < layout.length; ++i) { for (int j = 0; j < layout[i].length; ++j) { layout[i][j] = invisible; } } for (int i = 0; i < length(px); ++i) { int key = find(letters, substr(px,i,1)); if (key >= 0 && key < 26) { layout[h][w] = colors[key]; ++w; } else if (key == 26) { layout[h][w] = invisible; ++w; } else { ++h; w = 0; } } drawPenArray(layout); }
How to use
Simply type
draw_pixel_string(<h>,<w>,<code>,<colors>);
after the source code. You must replace <h> and <w> with the height and width of you picture in mind. When you fill in <colors>, the first color will be assigned to a, the second b, and etc, until z. you cannot have more than 26 colors, The formatting for the string <code> is thus:When you type a letter, you will get the corresponding color
A dash (-) creates an invisible pixel
A any other character (preferably a space or new line) breaks the row you are in and takes you into the next
Examples
chess board
draw_pixel_string(8,8, "abababab babababa abababab babababa abababab babababa abababab babababa ",black, white);
![[asy]
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(8,8,
"abababab
babababa
abababab
babababa
abababab
babababa
abababab
babababa
",black, white);[/asy]](http://latex.artofproblemsolving.com/8/f/0/8f0778e56d5352b9f9ba2077548d49ca4a7e59f9.png)
house
draw_pixel_string(10,10, "----aa---- ---aaaa--- --aaaaaa-- -aaaaaaaa- aaaaaaaaaa bbbbbbbbbb bbaabbbbbb bbaabbaabb bbaabbaabb bbaabbbbbb ",brown,red);
![[asy]
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(10,10,
"----aa----
---aaaa---
--aaaaaa--
-aaaaaaaa-
aaaaaaaaaa
bbbbbbbbbb
bbaabbbbbb
bbaabbaabb
bbaabbaabb
bbaabbbbbb
",brown,red);[/asy]](http://latex.artofproblemsolving.com/9/1/7/917155fb941a88de270f1ad82f73ca3c1e7bf46d.png)
dolphin
draw_pixel_string(15,15, "--------aa----- -------ada----- ----aaaddaa---- ---addddccda--- --adbbcccccda-- -aadabccccccda- addccccdbbccca- -aaaaaaddabccda ----acaadaabcca -----a--aa-acca -----------aca- ----------aaca- ---------acca-- ----------aca-- -----------a--- ", black, white, deepcyan+royalblue+white, heavycyan+.1*white);
![[asy]
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(15,15,
"--------aa-----
-------ada-----
----aaaddaa----
---addddccda---
--adbbcccccda--
-aadabccccccda-
addccccdbbccca-
-aaaaaaddabccda
----acaadaabcca
-----a--aa-acca
-----------aca-
----------aaca-
---------acca--
----------aca--
-----------a---
", black, white, deepcyan+royalblue+white, heavycyan+.1*white);
[/asy]](http://latex.artofproblemsolving.com/2/6/b/26b8da8a0f66a372891768ba392fa2dd646358d1.png)
turtle
draw_pixel_string(9,23, "-------------aaaa------- ----------aaabbbbaaa---- ---aaa--aabababbababaa-- -aaecdaabbabbbaabbbabba- addddddabbabbabbabbabba- -aaaaaaaaaaaabbbbaaaaaaa -------addddaaaaaadddda- --------adda------adda-- -------aaaaa-----aaaaa-- ", black, deepgreen, white, brown, orange);
![[asy]
//Made by sonone
void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[i].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}
void draw_pixel_string(int height, int width, string px...pen[] colors) { // converts a string into a pixel drawing with specified demensions and color palette
string letters = "abcdefghijklmnopqrstuvwxyz-";
defaultpen(invisible);
int h = 0;
int w = 0;
pen[][] layout = new pen[height][width];
for (int i = 0; i < layout.length; ++i) {
for (int j = 0; j < layout[i].length; ++j) {
layout[i][j] = invisible;
}
}
for (int i = 0; i < length(px); ++i) {
int key = find(letters, substr(px,i,1));
if (key >= 0 && key < 26) {
layout[h][w] = colors[key];
++w;
}
else if (key == 26) {
layout[h][w] = invisible;
++w;
}
else {
++h;
w = 0;
}
}
drawPenArray(layout);
}
draw_pixel_string(9,23,
"-------------aaaa-------
----------aaabbbbaaa----
---aaa--aabababbababaa--
-aaecdaabbabbbaabbbabba-
addddddabbabbabbabbabba-
-aaaaaaaaaaaabbbbaaaaaaa
-------addddaaaaaadddda-
--------adda------adda--
-------aaaaa-----aaaaa--
", black, deepgreen, white, brown, orange);
[/asy]](http://latex.artofproblemsolving.com/d/b/c/dbc54405d15c209d8115c9bb3e85a61b3896103e.png)
This post has been edited 4 times. Last edited by sonone, May 14, 2021, 11:15 PM
Reason: add rules box
Reason: add rules box