QB64 Phoenix Edition
_NEWIMAGE() should be fixed to always take 3 parms - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2)
+--- Thread: _NEWIMAGE() should be fixed to always take 3 parms (/showthread.php?tid=1086)

Pages: 1 2


_NEWIMAGE() should be fixed to always take 3 parms - mnrvovrfc - 11-09-2022

If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". The source code was something I found from the "dot-com" forum that was meant for "QBJS" and not on Linux.

Code: (Select All)
''by "mikesharpe" from qb64-dot-com forum
dim shared pi, p, q, d, z0, t, f, sw, sh

sw = 800
sh = 600
d = 700
z0 = 1500
pi = 4*atn(1)

screen _newimage(sw, sh, 12)

sv = 2*pi/30
su = 2*pi/10


for t = 0 to 2*pi step 0.01
    cls
    u = 0
    for v=0 to 2*pi+sv step sv
        x = cos(u)
        y = sin(u)
        z = cos(v)
        w = sin(v)
        
        proj x, y, z, w
        pset (p, q)
        
        for u=0 to 2*pi+su step su
            x = cos(u)
            y = sin(u)
            z = cos(v)
            w = sin(v)
        
            proj x, y, z, w
            line -(p, q)
        next
    next
    
    for u=0 to 2*pi+su step su
        x = cos(u)
        y = sin(u)
        z = cos(v)
        w = sin(v)
        
        proj x, y, z, w
        pset (p, q), _rgb(255,0,0)
        
        for v=0 to 2*pi+sv step sv
            x = cos(u)
            y = sin(u)
            z = cos(v)
            w = sin(v)
        
            proj x, y, z, w
            line -(p, q), _rgb(255,0,0)
        next
    next
    
    _display
    _limit 50
next
_autodisplay
system

sub proj(x, y, z, w)
    xx = x
    yy = y*cos(t) - w*sin(t)
    zz = z
    ww = y*sin(t) + w*cos(t)

    d2 = 3
    w0 = 3
    xx = xx*d2/(w0 + ww)
    yy = yy*d2/(w0 + ww)
    zz = zz*d2/(w0 + ww)
    
    xxx = xx*cos(t) - zz*sin(t)
    zzz = xx*sin(t) + zz*cos(t)
    xx = xxx
    zz = zzz
    
    a = pi/12
    b = pi/3
    xxx = xx*cos(a) - yy*sin(a)
    yyy = xx*sin(a) + yy*cos(a)
    xx = xxx
    yy = yyy

    yyy = yy*cos(b) - zz*sin(b)
    zzz = yy*sin(b) + zz*cos(b)
    yy = yyy
    zz = zzz
    
    xx = 200*xx
    yy = 200*yy
    zz = 200*zz

    p = sw/2 + 2*xx*d/(yy + z0)
    q = sh/2 - 2*zz*d/(yy + z0)
end sub

My other addition to the original program was "_DISPLAY" just above "_LIMIT" so this was more tolerable.


RE: _NEWIMAGE() should be fixed to always take 3 parms - bplus - 11-09-2022

+1 don't know how many times I've forgotten the third and crashed!

Would be nice to just throw an error.


RE: _NEWIMAGE() should be fixed to always take 3 parms - mnrvovrfc - 11-09-2022

I said the source code I listed might have been meant for "QBJS" but got confused by another post made by the user of the other forum. I just went into "QBJS" and it complains "Missing or unsupported method" for "LINE" and "PSET", so I can't understand why that source code was provided with "_NEWIMAGE()" being given only two parameters and maybe never tested. The warning is given whether or not "_NEWIMAGE()" has two or three parameters, it's simply that "QBJS" doesn't support those graphics statements yet. Maybe I should have started this thread on the new sub-forum. However, this is a possibility for code that perhaps was composed first in "BAM" or "QBJS", and then somebody tries to run it on QB64(PE).


RE: _NEWIMAGE() should be fixed to always take 3 parms - bplus - 11-09-2022

OK yeah vince code worked without the 3rd parameter in QBJS, I think, the hypercube that PhilOfPerth noted.. but still an error thrown is better than crashing in regular IDE QB64pe.


RE: _NEWIMAGE() should be fixed to always take 3 parms - dbox - 11-09-2022

Quote:… it's simply that "QBJS" doesn't support those graphics statements yet.

Interesting… Line and PSet are supported in QBJS. I was able to run the program above in QBJS with no errors.


RE: _NEWIMAGE() should be fixed to always take 3 parms - bplus - 11-09-2022

Confirmed but on Windows:
   


RE: _NEWIMAGE() should be fixed to always take 3 parms - SpriggsySpriggs - 11-09-2022

Oh, cool. Are we making a torus?


RE: _NEWIMAGE() should be fixed to always take 3 parms - SMcNeill - 11-09-2022

(11-09-2022, 02:05 PM)mnrvovrfc Wrote: If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". 

This isn't as "broken" as you assume.  Wink

Code: (Select All)
Screen _NewImage(80, 40)

Print _Width, _Height, _PixelSize
A newimage, without any third parameter, defaults to a SCREEN 0 image -- which is text only.   Trying any graphics command in a text-only screen will generate that error box, but what probably causes it to hang up and then terminate is attemping to create an 800x600 text screen!

800 characters wide, 600 rows high..  I can see where that would push the limits of what's possible and terminate without much warning.  Wink


RE: _NEWIMAGE() should be fixed to always take 3 parms - mnrvovrfc - 11-09-2022

(11-09-2022, 05:21 PM)dbox Wrote:
Quote:… it's simply that "QBJS" doesn't support those graphics statements yet.

Interesting… Line and PSet are supported in QBJS.  I was able to run the program above in QBJS with no errors.
I had forgotten to post on the sub-forum that KDE Falkon might not be a supported web browser. It doesn't look like it's based on Chromium as I've been misled to believe until now. I tried it on EndeavourOS (Arch-based) XFCE but with Falkon instead of the provided Firefox as web browser.


RE: _NEWIMAGE() should be fixed to always take 3 parms - bplus - 11-09-2022

(11-09-2022, 05:58 PM)SMcNeill Wrote:
(11-09-2022, 02:05 PM)mnrvovrfc Wrote: If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". 

This isn't as "broken" as you assume.  Wink

Code: (Select All)
Screen _NewImage(80, 40)

Print _Width, _Height, _PixelSize
A newimage, without any third parameter, defaults to a SCREEN 0 image -- which is text only.   Trying any graphics command in a text-only screen will generate that error box, but what probably causes it to hang up and then terminate is attemping to create an 800x600 text screen!

800 characters wide, 600 rows high..  I can see where that would push the limits of what's possible and terminate without much warning.  Wink

Oh yeah, it's when I try and use 1200 pixels wide and whatever high and forget the 3rd that's when it gets bad!