Board Logo
« Working in graphics »

Welcome Guest. Please Login or Register.
Jan 16th, 2018, 3:31pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Working in graphics  (Read 221 times)
Angelo2449
Member in Training
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 58
xx Working in graphics
« Thread started on: Nov 9th, 2017, 10:48pm »

Hi guys,
I realize a drawing in a graphicbox through cartesian coordinates read from a database.
Problems :
- if I minimize the window and then expanding it, the design disappears.
- after drawing the drawing with the cartesian coordinates read from database I draw lines, circles, and so on.
How do I save the drawing now with new graphics elements?
However, I would like to save it as a re-usable database and not as a .bmp file.
Thank you
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Working in graphics
« Reply #1 on: Nov 9th, 2017, 11:36pm »

Hi Angelo,

You could save it as like drawing instructions in oh say, a Basic program! smiley a far, far smaller file than a .bmp

There is also something called Draw Strings where all the drawing commands are condensed to a string$, not sure JB has it but easy enough to code something up.

This command will save your pictures when you resize your windows, found under Graphic commands in Help.

Quote:
print #handle, "flush"

This command ensures that drawn graphics 'stick'. Each time a flush command is issued after one or more drawing operations, a new group (called a segment) is created. Each segment of drawn items has an ID number. The segment command retrieves the ID number of the current segment. Each time a segment is flushed, a new empty segment is created, and the ID number increases by one. See also the commands cls, delsegment, discard, redraw, and segment.
« Last Edit: Nov 9th, 2017, 11:48pm by bplus » User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3635
xx Re: Working in graphics
« Reply #2 on: Nov 10th, 2017, 12:24am »

Quote:
- after drawing the drawing with the cartesian coordinates read from database I draw lines, circles, and so on.
How do I save the drawing now with new graphics elements?
However, I would like to save it as a re-usable database and not as a .bmp file.

You better save it in same database as you draw.
(like, after drawing a line add in database something like
"line x1 y1 x2 y2")
What really depends on what database you used, is where way to add lines circles where?
« Last Edit: Nov 10th, 2017, 12:35am by tsh73 » User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Working in graphics
« Reply #3 on: Nov 10th, 2017, 02:07am »

We had a contest once. http://webzoom.freewebs.com/gamebin/Other%20Software/Turtle.ZIP

Also look at the Just BASIC files archive for uncleBen’s Logo Script program.

But essentially , flush to keep stuff on screen and build the database as you go.
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Working in graphics
« Reply #4 on: Nov 10th, 2017, 05:10am »

Well once again someone has confused JB with some other flavor Basic

Code:
                case d$="P"                                     'Pp,b floodfill Paintcolor (backcolor) to bordercolor
                    pos=pos+1
                    gosub [getnumber]
                    co$="backcolor "
                    gosub [getcolor]
                    pco$=co$
                    paintcolor=clong
                    pos=pos+1 '","
                    gosub [getnumber]
                    gosub [getcolor]
                    bordercolor=clong
                    print #h$, "posxy xVar yVar"
                    print #h$, pco$
                    hw=(hwnd(#h$))
                    CallDll #user32,"GetDC",hw as long,hdc as long
                    'CallDll #gdi32, "GetPixel",hdc as long,xVar as long,yVar as long,actualColor as long  'color of pixel
                    Calldll #gdi32, "ExtFloodFill",hdc As Long,xVar As Long,_
                                yVar As Long,bordercolor As Long,_FLOODFILLBORDER as long,result as long
                    CallDll #user32, "ReleaseDC",hw as long,hdc as long


 


Unless we study the general case of Draw Strings:
http://retrogamecoding.org/board/index.php?topic=585.0

Code:

' turtle essence.bas SmallBASIC 0.12.9 (B+=MGA) 2017-06-13

' From my experience with Draw Strings and Nano series, 
' I think I have discovered the essence of Turtle Drawing
' I contend that all can be done with 5 global variables
' x, y the start position of ray = ra line
' a, r a = the radian angle of direction to go and r = the distance
' p is pen color, draw if 0 <= p <= 15 (QB colors 0 - 15)
' and one graphics command ra (as sub or gosub)

sub ra
  local x1 = x + r * cos(a)
  local y1 = y + r * sin(a)
  ' if pen p has a color draw, else just update x, y position
  if 0 <= p and p <= 15 then line x, y, x1, y1, p
  x = x1 : y = y1 'update x, y with current turtle position
end
'===== that's all the setup you need to do turle drawing

 
« Last Edit: Nov 10th, 2017, 05:24am by bplus » User IP Logged

B+
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Working in graphics
« Reply #5 on: Nov 10th, 2017, 07:15am »

Here is my first in JB 2.0

To learn Draw Strings first practice Turtle Drawing, here is essence to drawing like with pen that has 15 colors with 0 to just move pen.

Start at Turtle x, y = (tx, ty) coordinate usually middle of screen
'Set x, y
tx = 300
ty = 300

Turn some angle in degrees, 0 is East (right), 90 South (down), 180 West (left), 270 North (heading up)

'set angle a
a = 90

'set a distance with r
r = 100

'set pen color to red
p = 12

'now draw it
ra

'one red line starting at 300, 300 heading due South for distance 100

'finish a square
a = a + 90
ra
a = a + 90
ra
a = a + 90
ra
' that's one red square!

Here is something much fancier!
Code:
'Turtle Essence- Tree Demo thru DE6.txt for JB 2.0 2017-11-10

global xmax, ymax  'these two you can easily reset to your needs
'set these to screen width = xmax, screen height = ymax, that you want

xmax = 600 : ymax = 700  '<<<<<< set this as you need or from plug-in notes

global PI, DEG, RAD
PI = acs(-1)
DEG = 180 / PI
RAD = PI / 180

dim qb$(15) 'thanks Andy Amaya for use with his sub qColor fore, back
qb$( 0) = "  0   0   0" 'black
qb$( 1) = "  0   0 128" 'blue
qb$( 2) = "  8 128   8" 'green
qb$( 3) = "  0 128 128" 'cyan
qb$( 4) = "128   0   0" 'red
qb$( 5) = "128   0 128" 'magenta
qb$( 6) = "128  64  32" 'brown
qb$( 7) = "168 168 168" 'white
qb$( 8) = "128 128 128" 'grey
qb$( 9) = " 84  84 252" 'light blue
qb$(10) = " 42 252  42" 'light green
qb$(11) = "  0 220 220" 'light cyan
qb$(12) = "255   0   0" 'light red
qb$(13) = "255  84 255" 'light magenta
qb$(14) = "255 255   0" 'yellow
qb$(15) = "255 255 255" 'bright white

nomainwin

WindowWidth = xmax + 8
WindowHeight = ymax + 32
UpperLeftX = (DisplayWidth-WindowWidth) / 2
UpperLeftY = (DisplayHeight-WindowHeight) / 2

'graphicbox #gr, 2, 2, xmax-2, ymax-2
open "Turtle Essence Tree Demo with DE6 & JB 2.0" for graphics_nsb_nf as #gr
#gr "trapclose quit"
#gr "down"

'========================================================== plug-in main modules here
'translated to JB 2.0 from:
' turtle essence.bas SmallBASIC 0.12.9 (B+=MGA) 2017-06-13
' from Galileo's tree code (for YAB) found at
' http://retrogamecoding.org/board/index.php?topic=581.0

' From my experience with Draw Strings and Nano series,
' I think I have discovered the essence of Turtle Drawing
' I contend that all can be done with 5 global variables
' tx, ty the start position of ray = ra line
' a, r the radian angle of direction to go and r the distance
' p is pen color, draw if 0 <= p <= 15 (QB colors 0 - 15)
' and one graphics command ra (as sub or gosub)


'setup
Global tx, ty, a, r, p 'for turtle essence drawing
Global sway            'for swaying tree a bit

'start in middle of screen
tx = xmax/2 : ty = ymax/2 : a = 270  'turtle x, y, angle is pointed North 270 degrees
ty = ty + 250                               'move down from base of tree trunk
horizon = .67 * ymax                        'set background horizon to 2/3's down screen
p = 6                                       'set pen on at green


sway = 10                                   'try different sways -25 to 25 are pretty good

for h = 0 to horizon                        'make nice sky
    call midInk 0, 0, 128, 40, 200, 255, h/horizon
    call aline 0, h, xmax, h
next

for h = horizon to ymax                     'make nice ground
    call midInk 40, 200, 255, 50, 200, 50, (h-horizon)/(ymax-horizon)
    call aline 0, h, xmax, h
next

'make tree with ra commands
call tree 350  'make tree using recursive calls, using only turtle's "ra" command to draw

#gr "flush"
scan

wait '=====================================================

'procedure for essence, setup globals tx, ty, a, r, p
sub ra

    'RAD * .... is just converting an Angle in Degrees Units
    ' to one in Radians Units for the Trig Functions SIN and COS.

    x1 = tx + r * cos(RAD * a)  'new x, y from angle and distance r from last
    y1 = ty + r * sin(RAD * a)
    if 0 <= p and p <= 15 then
        call qColor p, 0             'set color and draw line
        call aline tx, ty, x1, y1
    end if
    tx = x1 : ty = y1     'update x, y with current turtle position
end sub

'===== that's all the setup you need to do turle drawing

'demo turtle essence, sway? had trees swaying in wind but too much for JB
sub tree size
    scan
    if size < 5 then 'the end of the branch
        'move
        r = size
        call ra
        'move
        r = -1 * size
        call ra
        exit sub
    end if

    'move
    r = size / 3
    call ra

    'turn(-30)
    a = a - (30 + sway)
    call tree size * 2 / 3

    'turn(30)
    a = a + (30 + sway)

    'move(size/6)
    r = size / 6
    call ra

    'turn(25)
    a = a + (25 + sway)
    call tree size / 2

    'turn(-25)
    a = a - (25 + sway)

    'move(size/3)
    r = size / 3
    call ra

    'turn(25)
    a = a + (25 + sway)
    call tree size/2

    'turn(-25)
    a = a - (25 + sway)

    'move(size/6)
    r = size / 6
    call ra

    'move(-size)
    r = -1 * size
    call ra
end sub

'bplus bonus coloring method!
sub midInk r1, g1, b1, r2, g2, b2, fr
  call hue r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr
end sub

wait ' ======= DE procedures color, drawing, events very useful subs or functions

sub quit hdl$
    timer 0
    close #gr
    end
end sub

sub hue r, g, b 'fore and back RGB color system
'hue sets both fore and backcolor for filled graphics commands fbox, fcirc, fellipse
    #gr "color ";r;" ";g;" ";b
    #gr "backcolor ";r;" ";g;" ";b
end sub

Sub qColor foreColor, backColor 'thanks Andy Amaya old QB color system
    #gr "Color ";qb$(foreColor);";BackColor ";qb$(backColor)
End Sub

sub aline x0, y0, x1, y1 'somethimes you might want to spec a pixel longer on end x1, y1
    #gr "line ";x0;" ";y0;" ";x1;" ";y1  'add 1 to end point
end sub

 


Append: Oh! I should modify this so that when pen < 0 then no drawing and save pen p=0 for Color Black! Much needed when default background is White.
« Last Edit: Nov 10th, 2017, 10:50am by bplus » User IP Logged

B+
Angelo2449
Member in Training
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 58
xx Re: Working in graphics
« Reply #6 on: Nov 10th, 2017, 5:20pm »

Problem solved.
I've created a file that contains the data of the graphics elements .
Then I read the data and draw the graphic elements.
Easy!
Thank you.
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Working in graphics
« Reply #7 on: Nov 12th, 2017, 07:00am »

Hi Angelo,

I am just wondering, do you know about READ and DATA statements?
User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3635
xx Re: Working in graphics
« Reply #8 on: Nov 12th, 2017, 09:39am »

Re: Turtle Essence- Tree Demo
Kids: Cool.
Could you slow it down please?

(huh)

(I just changed "'the end of the branch" condition for that so it draws more)
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Working in graphics
« Reply #9 on: Nov 12th, 2017, 1:18pm »

Ah, kid approved, my greatest joy!

Yes, I bet adding more branches would slow it down.

shhh, in other Basics you can have it grow and sway in the wind!

Tsh73, thanks for checking it out and reporting feedback, my day is made! smiley
User IP Logged

B+
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls