LB Booster
Programming >> BASIC code examples >> Winter fun 2016 Snow Scene
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1478730854

Winter fun 2016 Snow Scene
Post by Richard Russell on Nov 9th, 2016, 9:34pm

You can find my submission for this challenge at the Umbrella Forum - it works in JB, LB and LBB. I would appreciate it if somebody would cross-post it to the other forums because needless to say I'm not able to.

There are a few interesting features. Firstly it draws a different tree every time it is run, using a fractal algorithm with random terms; I think it's quite realistic. Secondly it contains a 'getpixel' function which works even in Just BASIC, by reading from a saved BMP file (not an original idea by any means, but I coded this one from scratch).

It provides a tough test for LBB's graphics, because it consists almost entirely of 'set' commands. What I'm finding here is that it runs at about the same speed as JB/LB when run on a CPU with a least two cores, but is actually somewhat slower if run on a single-core CPU (even if hyperthreaded).

Richard.

Re: Winter fun 2016 Snow Scene
Post by Richard Russell on Nov 10th, 2016, 08:33am

on Nov 9th, 2016, 9:34pm, Richard Russell wrote:
You can find my submission for this challenge at the Umbrella Forum - it works in JB, LB and LBB.

Interestingly it showed up a bug in JB/LB that I haven't come across before, and which isn't documented at the Bug Tracker wiki. It appears that when JB/LB redraws graphics from a stored 'segment' (i.e. after a flush and when the window is minimized/maximized or covered/uncovered) it doesn't initialise the rule.

So if (for example) a rule xor command has later been issued, JB/LB will redraw the stored segment using that rule instead of the one in effect when the graphics were originally drawn! So rather than re-drawing them as they were, the graphics are drawn completely differently.

The workaround is to deliberately store a rule over command in the original segment. It won't have any effect on the graphics when they are initially drawn, but will cause them to be re-drawn correctly later, if required.

Richard.

Re: Winter fun 2016 Snow Scene
Post by Richard Russell on Nov 10th, 2016, 1:25pm

on Nov 9th, 2016, 9:34pm, Richard Russell wrote:
it draws a different tree every time it is run, using a fractal algorithm with random terms; I think it's quite realistic.

The trunk is perhaps a bit too slim, so if you like you can change the line in sub branch which sets the size as follows:

Code:
    #w "size ";int(1.4^depth);";line ";x1;" ";y1;" ";x2;" ";y2 

Richard.