Author Topic: Axe Greyscale  (Read 3688 times)

0 Members and 2 Guests are viewing this topic.

Offline calvinhtml

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 14
  • Rating: +0/-0
  • I constantly need ideas for what to program
    • View Profile
Axe Greyscale
« on: December 08, 2014, 06:26:31 pm »
Hi there, today I will be discussing how to program in greyscale! Yes. But not just three level, but also four. So before we start, let's answer this question. What is greyscale? Greyscale is the contrast between the front and back buffers, respectively. It creates a flickering lighter or darker image on the calculator. With that in mind, let's take a look at three and four level greyscale.
Three level greyscale is white, absolute LCD, grey, back buffer, and black, complete pixel turned on. To demonstrate this, let's write a sample program. The will display a box in three level greyscale.
Code: [Select]
.Threegre
[F00000000000000F]->Pic1
[0FFFFFFFFFFFFFF0]->Pic2
Repeat getkey(15)
Pt-on(25,25,Pic1
Pt-on(25,25,Pic2)r
DispGraphr
End

This is the superscript r, found in 2nd, Angle, 3. IF YOU DO NOT PUT THIS YOUR GREYSCALE WILL MESS UP!
Different in a way, but much the same is four level greyscale. Four level greyscale consists of 3 level greyscale with light grey, but also adds dark grey. This is what is turned on in the main buffer, but not the back. Let's see what a program with this would look like. Remember that this is the superscript r, not the letter r.
Code: [Select]
.Fourgrey
[FF818181818181FF->Pic1
[4242424242424242->Pic2
[6868686868686868->Pic3
Repeat getkey(15)
Pt-on(25,25,Pic1
Pt-on(25,25,Pic2)r
Pt-on(25,25,Pic3)r
Pt-on(25,25,Pic3
DispGraphrr
End

In this sample program, two superscript r's are need instead of one. Why? This is because you want to trigger both the main buffer, AND back buffer, instead of just the back buffer with one superscript r, and the main buffer with no superscript r. Kind of confusing? Well, let's look at an application you actually might use in a program. This will take a while.  ;)

Code: [Select]
.Link
10->A
47->B
.Back Buffer
[0F1F100004000018->Pic1
[C0E0200000000020->Pic2
[0001000100010000->Pic3
[70F0601070C00000->Pic4
.Main Buffer
[000040406B6B3F0C->Pic1A
[000008085858F040->Pic2A
[0320722222027C00->Pic3A
[8808000000000000->Pic4A
.Both Buffers
[00000F1F10140003->Pic1B
[0000C0E020A00898->Pic2B
[7CDE8DDCDCEC0000->Pic3B
[000090E08020E0E0->Pic4B
Repeat getkey(15)
Pt-on(A,B,Pic1)r
Pt-on(A,B,Pic1B)r
Pt-on(A,B,Pic1B
Pt-on(A,B,Pic1A
Pt-on(A+8,B,Pic2)r
Pt-on(A+8,B,Pic2B)r
Pt-on(A+8,B,Pic2B
Pt-on(A+8,B,Pic2A
Pt-on(A,B+8,Pic3)r
Pt-on(A,B+8,Pic3B)r
Pt-on(A,B+8,Pic3B
Pt-on(A,B+8,Pic3A
Pt-on(A+8,B+8,Pic4)r
Pt-on(A+8,B+8,Pic4B)r
Pt-on(A+8,B+8,Pic4B
Pt-on(A+8,B+8,Pic4A
Line(0,63,95,63
DispGraphClrDrawrr
47->B
If A<1:A++
End
If A>82:A--
End
If B<8:B+7->B
End
If B>47:B--
End
If getkey(4)
B-7->B
End
If getkey(2):A--
End
If getkey(3):A++
End
If getkey(15)
Return
End
End

Ok, I know that this is a very long code for one simple 16x16 sprite, but this should come out to be the Nintendo hit character, Link, holding a shield with a dark cross on it.
Feel free to use this in programs you make, but please give me at least 10% credit for drawing the sprites.
I realize that this might be hard to understand, so here is the post for greyscale where I learned how to do it: http://www.omnimaga.org/axe-language/axe-greyscale-tutorial/
Or, if you want to use a simpler method, you can go here: http://clrhome.org/pix/ for an online greyscale sprite editor with presets.
Sorry about the shown superscript code. I will fix it later. My phone is at three percent.
« Last Edit: December 10, 2014, 07:26:54 pm by calvinhtml »

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Axe Greyscale
« Reply #1 on: December 08, 2014, 07:14:05 pm »
Cool tutorial, but it can use some formatting to make it more readable. For example: use [code][/code] tags for axe code.
« Last Edit: December 08, 2014, 07:22:08 pm by Runer112 »
If you like my work: why not give me an internet?








Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Axe Greyscale
« Reply #2 on: December 09, 2014, 01:11:06 am »
You could probably use a better coding style.

For example, your whole code isn't indented. Yeah, it can be complicated to indent on the small screen but that's why zStart has a small font editor. And if you write your code on a PC, then you have no excuse ;)

If A<1:A++
End
This is not even indentable. And you may say that you wrote it this way to save one line, but in thise case, you could have saved one more line by writing A<1?A++.

If getkey(15)
Return
End
This is useless at the end of a "Repeat getKey(15)" loop.

[C0E0200000000020->Pic2
Keeping brackets open is not useful in Axe (it doesn't save space on the compiled executable), except if you have a regular 83+ and want to save space at all costs, including on your sources.
Moreover, it would probably be better to use custom named variables and constants to keep the code readable, instead of using a random token like Pic2. You could for example have written [C0E0200000000020]→°MySprite2Back.

Now talking about the tutorial itself, why use 3 bits for one pixel in 4 level greyscale ? You can optimize this by only using 2 bits, and save one sprite per drawing. Basically, for one drawing, instead of having a [light_grey_sprite], a [dark_grey_sprite], and a [black_sprite], just use a [light_grey_and_black_sprite], and a [dark_grey_and_black_sprite].
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline calvinhtml

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 14
  • Rating: +0/-0
  • I constantly need ideas for what to program
    • View Profile
Re: Axe Greyscale
« Reply #3 on: December 09, 2014, 02:50:21 pm »
Ok, thank you. I did the code, /code stuff, and it does organize it better. I have actually been trying to figure out how to do that. And the suggestions the Hayleia gave me, thank you. I use the return at the end so it will exit immidiately after clear is pressed, instead of waiting five seconds or so. I also edit my programs on calc. ;)

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Axe Greyscale
« Reply #4 on: December 09, 2014, 03:23:01 pm »
Well the way you did this, removing the "If getKey(15):Return:End" won't make the program wait for 5 seconds before quitting when hitting Clear, it will make it quit immediately, since once you press Clear, it exits the loop then hits the end of the program where there's always a Return, implicit or not.

And [code] isn't a good idea when you are using [sup]. Try using [tt] and [hr] instead. Example below:


.Threegre
[F00000000000000F]->Pic1
[0FFFFFFFFFFFFFF0]->Pic2
Repeat getkey(15)
Pt-on(25,25,Pic1
Pt-on(25,25,Pic2)r
DispGraphr
End



And another example while I am at it:


.Fourgrey
[FF818181818181FF->Pic1
[4242424242424242->Pic2
[6868686868686868->Pic3
Repeat getkey(15)
Pt-on(25,25,Pic1
Pt-on(25,25,Pic2)r
Pt-on(25,25,Pic3)r
Pt-on(25,25,Pic3
DispGraphrr
End


I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s