Asymptote pixel art

by sonone, May 3, 2021, 7:09 PM

Inspired by this post, I made a simple function for making a 2D pen array into a pixel picture.[asy]
pen rd = rgb(1, 0.0156862745, 0.00392156862);
pen bl = black;
pen br = rgb(0.48235294117, 0.33333333333, 0);
pen sc = rgb(0.98823529411, 0.61568627451, 0.0862745098);

void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[0].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}

pen[][] mario = {
{bl,bl,bl,rd,rd,rd,rd,rd,bl,bl,bl,bl},
{bl,bl,rd,rd,rd,rd,rd,rd,rd,rd,rd,bl},
{bl,bl,br,br,br,sc,sc,br,sc,bl,bl,bl},
{bl,br,sc,br,sc,sc,sc,br,sc,sc,sc,bl},
{bl,br,sc,br,br,sc,sc,sc,br,sc,sc,sc},
{bl,br,br,sc,sc,sc,sc,br,br,br,br,bl},
{bl,bl,bl,sc,sc,sc,sc,sc,sc,sc,bl,bl},
{bl,bl,br,br,rd,br,br,br,bl,bl,bl,bl},
{bl,br,br,br,rd,br,br,rd,br,br,br,bl},
{br,br,br,br,rd,rd,rd,rd,br,br,br,br},
{sc,sc,br,rd,sc,rd,rd,sc,rd,br,sc,sc},
{sc,sc,sc,rd,rd,rd,rd,rd,rd,sc,sc,sc},
{sc,sc,rd,rd,rd,rd,rd,rd,rd,rd,sc,sc},
{bl,bl,rd,rd,rd,bl,bl,rd,rd,rd,bl,bl},
{bl,br,br,br,bl,bl,bl,bl,br,br,br,bl},
{br,br,br,br,bl,bl,bl,bl,br,br,br,br}
};

drawPenArray(mario);
[/asy]
[asy]
pen a = white;
pen b = black;

void drawPenArray(pen[][] pixel = {{red}}) {
for (int i = 0; i < pixel.length; ++i) {
for (int j = 0; j < pixel[0].length; ++j) {
fill(shift(j,-i)*unitsquare,pixel[i][j]);
}
}
}

pen[][] sonone = {
{a,a,a,a,a,a,a,a,a,a,a,a,a},
{a,a,a,b,a,a,a,a,a,a,a,a,a},
{a,a,a,b,a,a,a,a,a,a,a,a,a},
{a,b,b,b,b,b,a,b,b,b,b,b,a},
{a,a,a,b,a,a,a,a,a,a,a,a,a},
{a,a,a,b,a,a,a,a,a,a,a,a,a},
{a,a,a,a,a,a,a,a,a,a,a,a,a},
{a,a,a,b,a,a,a,b,a,a,a,b,a},
{a,a,a,a,a,a,a,a,b,a,b,a,a},
{a,b,b,b,b,b,a,a,a,b,a,a,a},
{a,a,a,a,a,a,a,a,b,a,b,a,a},
{a,a,a,b,a,a,a,b,a,a,a,b,a},
{a,a,a,a,a,a,a,a,a,a,a,a,a}
};

drawPenArray(sonone);
[/asy]

Comment

0 Comments

Old material is mostly Asymptote, new material is calculator programming

avatar

sonone
Archives
+ April 2023
+ August 2022
+ April 2021
+ August 2020
Shouts
Submit
  • I still exist as well.

    by G.G.Otto, Aug 11, 2023, 2:44 AM

  • hello I'm still here lol

    by player01, Aug 6, 2022, 6:24 PM

  • [REVIVAL] I will start posting more calculator relating posts very soon. Even though school has been busy, I have been programming my calculators a decent amount, so I have a lot to share...

    by sonone, Feb 18, 2022, 10:29 PM

  • wow its been like 2.5 years since geo class

    by pieMax2713, Feb 4, 2022, 8:38 PM

  • @violin21, I've been very busy with school lately and haven't been able to add another lesson. I will when i get a free moment

    by sonone, Aug 19, 2021, 12:45 AM

  • ORZ CODER

    by samrocksnature, Aug 9, 2021, 9:57 PM

  • Could you make more Asymptote lessons on your "How to do Asymptote" blog?

    by violin21, Aug 9, 2021, 7:26 PM

  • You can take it, just C&P the CSS into your CSS area

    by sonone, Apr 17, 2021, 10:08 PM

  • how can we take the CSS if we have permission to not take it?

    by GoogleNebula, Apr 17, 2021, 5:22 PM

  • That is awesome!

    by sonone, Apr 15, 2021, 10:09 PM

  • I modified your dodecahedron and got:
    [asy]
    import three;
    import solids;
    size(300);
    currentprojection=orthographic(0,1.3,1.2);
    light(0,5,10);

    real phi=(sqrt(6)+1)/3;
    real g=(phi-1)/2;
    real s=1/2;
    real a=sqrt(1-phi*phi/4-g*g)+phi/2;

    triple[] d;
    d[0]=(phi

    by Andrew2019, Mar 26, 2021, 12:15 AM

  • Not too many, just changing the color here and there. I really like your CSS!

    by sonone, Feb 2, 2021, 10:35 AM

  • Nice!

    I see you're making changes to the CSS. :)

    by G.G.Otto, Feb 1, 2021, 9:26 PM

  • I'm learning Java now!

    by sonone, Feb 1, 2021, 5:56 PM

  • And I took part of it from CaptainFlint and then added a ton of modifications. ;)

    by G.G.Otto, Dec 1, 2020, 8:56 AM

98 shouts
Tags
About Owner
  • Posts: 2106
  • Joined: Aug 20, 2016
Blog Stats
  • Blog created: Mar 28, 2020
  • Total entries: 61
  • Total visits: 4976
  • Total comments: 146
Search Blog
a