Laser cut visual effect

Code snippets illustrating how LBB can be used
Post Reply
tsh73
Posts: 36
Joined: Fri Apr 06, 2018 7:58 pm

Laser cut visual effect

Post by tsh73 » Sun Feb 03, 2019 9:02 pm

Code: Select all

'Laser engraving (look-alike)
'tsh73
'Jan 2019. Feb 2019 - with GetPixelAPI for LB

nomainwin
open "Laser engraving" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
    handleg  =hwnd( #gr)
    calldll  #user32, "GetDC", handleg as ulong, hDC as ulong

#gr "down"
#gr "fill black; flush"

#gr "backcolor black"
#gr "color 1 1 1"    'almost black, but not exactly
'#gr "color white"
#gr "place 30 200"
#gr "font times_new_roman 60 bold"
#gr "font times_new_roman 0 90 bold"
#gr "\Laser"

#gr "color cyan"    'gives red on black after XOR. Don't ask.

n = 5
r = 20

x0=300
y0=150
x1=35
y1=y0

t0=time$("ms")
#gr "rule xor"

 for x1 = 30 to 230
    for y = 145 to 200
        scan
        calldll #gdi32, "GetPixel", hDC as ulong, x1 as long, y as long, pixcol as ulong
        'print x1, y, pixcol       
                
        hasDot = (pixcol<>0)
        if not(hasDot) then goto [skip]
        y0=y:y1=y0
        'since last point on a line not drawn, we draw line from LAST point
        '#gr "line ";x0;" ";y0;" ";x1;" ";y1
        #gr "line ";x1;" ";y1;" ";x0;" ";y0
        'random sparkles
        for i = 1 to n
            a(i)=int(rnd(0)*360)
            r(i)=int(rnd(0)*r)
        next
        for i = 1 to n
            #gr "place ";x1;" ";y1
            #gr "north; turn ";a(i)
            #gr "go ";r(i)
        next
        'call pause 20'0'00
        '#gr "line ";x0;" ";y0;" ";x1+1;" ";y1   '+1 !!
        #gr "line ";x1+1;" ";y1;" ";x0;" ";y0
        for i = 1 to n
            #gr "place ";x1;" ";y1
            #gr "north; turn ";a(i)
            #gr "go ";r(i)
        next
[skip]
    next
    #gr "discard"
next
#gr "flush"
t1=time$("ms")

notice "That's all, folks ";t1-t0
wait

[quit]
    close #gr
end

sub pause mil
    t0=time$("ms")
    while time$("ms")<t0+mil
        scan
    wend
    exit sub
[quit]
    close #gr
    end
end sub

tsh73
Posts: 36
Joined: Fri Apr 06, 2018 7:58 pm

Re: Laser cut visual effect

Post by tsh73 » Wed Feb 06, 2019 8:52 pm

I got inconsistent results under Win10
One machine works as is
other leaves picture blank.
On examining output of getPixel, it happens that it is always 0.

In his case I was able to fix that by either removing first FLUSH (in

Code: Select all

#gr "fill black; flush"
line)
or adding FLUSH after printing text (

Code: Select all

#gr "\Laser"
).

User avatar
JackKelly
Posts: 31
Joined: Fri Apr 06, 2018 2:38 am

Re: Laser cut visual effect

Post by JackKelly » Tue Feb 12, 2019 7:34 pm

This code worked perfectly for me, as well as the code posted by Alincon, using LBB 3.10 under Windows 10, on an HP laptop PC.

Jack

Post Reply