• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[BasicCasio] Code Optimization

Status
Not open for further replies.
So, i did a simple program on my Casio in maths today that colors one pixel on 2 on the screen in that scheme :

010101010
101010101
010101010
101010101
010101010

(1 being colored pixels and 0 blank pixels).

My current problem is that the program takes a long time to do the whole screen, and so i would like to fasten it a bit if there's any way to optimize the code.


Code:
//Graphics Parameters
ViewWindow 1, 127, 0, 1, 63, 0
AxesOff
GridOff
LabelOff
//Grid Creation
2->A
1->B
While B=!64
PxlOn B,A
If A<125
Then A+2->A
Else A-125->A
B+1->B
IfEnd
WhileEnd
//Keeping the grid on the screen until Exe is pressed
While Getkey=!31
WhileEnd
//Resetting Graphics Parameters, Variables & such to default
Prog "INITCONF"

With that code, it takes a few minutes to have the grid on the whole screen, and that's quite a problem. So i'm searching ways to make it faster if it's possible. So, hmm any ideas ?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
I am guessing it draws each pixel 1 at a time and waits for the display to refresh. As such it takes approximately 4,000 frames to build the graphic.

If there is some way you can disable graphic display until the graphic is complete (a back buffer) that could speed it up. The idea is you generate the graphic and only display it when it is complete saving time updating for each pixel.

Another way would be to generate it using diagonal lines. Instead of 4000 individual pixels, you use about 128 individual lines at a diagonal, each filling in many pixels. As each line probably takes a frame or two to draw it will be much faster compared to the individual pixels.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Preventing the display from refreshing will still be faster as the cost seems to be related to that. It has to refresh the display after drawing every pixel.

If this is the case, then sending line draw commands instead of pixel draw commands will also be faster as each may fill many pixels in a single frame.
 
Preventing the display from refreshing will still be faster as the cost seems to be related to that. It has to refresh the display after drawing every pixel.

If this is the case, then sending line draw commands instead of pixel draw commands will also be faster as each may fill many pixels in a single frame.
Well, tested with the window being created after the grid is created, it doesn't seems to fasten it.

Diagonal lines fasten it a lot, but too lazy to find a good algorithm that works well with those atm (just tested with drawing 50 diagonal lines).

Else, I've fund another way to do it using representative curves :

Code:
Graph Y>1
This only takes ~1 seconds to do it.
 
Status
Not open for further replies.
Top