Hello All and a Happy New Year
Can you please assist
I tried to set the last point of a drawn line as new point to draw the next line...
GRAPHICS
'set draw to start position
x=350
y=250
DRAW COLOR 1,1,1
DRAW SIZE 2
DRAW TO x,y
' I can do x+50,y+50
DRAW LINE TO x+50,y+0
'but this gets very confusing when trying to workout the next location if i have to draw 50 lines
'i want to draw a line from the current location (x,y), then pick up the end point of the drawn line to draw the next line then pick up the end point of the last drawed line again and draw the next line and so on
'Is there a "command" to set the current end point location as the new location for the next draw command and so on, so that each time I can just enter the length x and height y of the line
'Thanking you in Advance
Erdogan
Draw lines continuously
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Draw lines continuously
smart Basic has a command for exactly that purpose: DRAW LINE to x,y.
In the following code, I created a loop with four repeats that reads new x and y values from a data statement. In each repeat, DRAW LINE to x,y draws to the new x,y coordinates from the current pen coordinates (e.g. where the last line ended.
In the following code, I created a loop with four repeats that reads new x and y values from a data statement. In each repeat, DRAW LINE to x,y draws to the new x,y coordinates from the current pen coordinates (e.g. where the last line ended.

Code: Select all
GRAPHICS
'set draw to start position
x=350
y=250
DRAW COLOR 1,1,1
DRAW SIZE 2
DRAW TO x,y
FOR i=1 TO 4
READ x,y
DRAW LINE to x,y
x=x1!y=y1
DATA 0,0,100,200,400,30,500,300
NEXT i
- Attachments
-
- IMG_9237.PNG (75.52 KiB) Viewed 3280 times
The only thing that gets me down is gravity...
Re: Draw lines continuously
Thanks rbytes
Your sample is good. However maybe I haven't explained to well as to what I'm trying to achieve.
I'm trying to achieve a user input each time and draw as variable inputs are entered.
sample file... if you can load and test, screen shot attached
GRAPHICS ! GRAPHICS CLEAR
DRAW COLOR 0,0,0
SET OUTPUT FONT COLOR .4,.2,.1
SET OUTPUT BACK COLOR 1,.94,.86
SET OUTPUT FONT NAME "arial"
SET OUTPUT FONT SIZE 20
DRAW FONT NAME "bradley hand"
DRAW FONT SIZE 20
OPTION ANGLE DEGREES
'set draw to start position
x=350
y=250
'set draw conditions
'DRAW COLOR 1,1,1
DRAW SIZE 2
'goto start position
DRAW TO x,y
DRAW TEXT "L1:" AT 0,0
FIELD "L1" TEXT prompt$ AT 160,0 SIZE 80, 20
FIELD "L1" SELECT
DO
UNTIL FIELD_CHANGED("L1")
L1 = FIELD_TEXT$("L1")
DRAW LINE TO x+L1,y+0
DRAW TEXT "Arc1:" AT 0,25
FIELD "R1" TEXT prompt$ AT 160,25 SIZE 80, 20
FIELD "R1" SELECT
DO
UNTIL FIELD_CHANGED("R1")
R1 = FIELD_TEXT$("R1")
DRAW TEXT "Start Angle1:" AT 0,45
FIELD "SA1" TEXT prompt$ AT 160,45 SIZE 80, 20
FIELD "SA1" SELECT
DO
UNTIL FIELD_CHANGED("SA1")
SA1 = FIELD_TEXT$("SA1")
DRAW TEXT "Finish Angle1:" AT 0,65
FIELD "FA1" TEXT prompt$ AT 160,65 SIZE 80, 20
FIELD "FA1" SELECT
DO
UNTIL FIELD_CHANGED("FA1")
FA1 = FIELD_TEXT$("FA1")
DRAW TEXT "Angle Direction1:" AT 0,85
FIELD "AD1" TEXT prompt$ AT 160,85 SIZE 80, 20
FIELD "AD1" SELECT
DO
UNTIL FIELD_CHANGED("AD1")
AD1 = FIELD_TEXT$("AD1")
DRAW ARC x+L1,y-R1,R1,SA1,FA1,AD1
DRAW TEXT "L2:" AT 0,105
FIELD "L2" TEXT prompt$ AT 160,105 SIZE 80, 20
FIELD "L2" SELECT
DO
UNTIL FIELD_CHANGED("L2")
L2 = FIELD_TEXT$("L2")
DRAW LINE x+L1+R1,y-R1 TO x+L1+R1,y-R1-L2
DRAW TEXT "Arc2:" AT 0,125
FIELD "R2" TEXT prompt$ AT 160,125 SIZE 80, 20
FIELD "R2" SELECT
DO
UNTIL FIELD_CHANGED("R2")
R2 = FIELD_TEXT$("R2")
DRAW TEXT "Start Angle2:" AT 0,145
FIELD "SA2" TEXT prompt$ AT 160,145 SIZE 80, 20
FIELD "SA2" SELECT
DO
UNTIL FIELD_CHANGED("SA2")
SA2 = FIELD_TEXT$("SA2")
DRAW TEXT "Finish Angle2:" AT 0,165
FIELD "FA2" TEXT prompt$ AT 160,165 SIZE 80, 20
FIELD "FA2" SELECT
DO
UNTIL FIELD_CHANGED("FA2")
FA2 = FIELD_TEXT$("FA2")
DRAW TEXT "Angle Direction2:" AT 0,185
FIELD "AD2" TEXT prompt$ AT 160,185 SIZE 80, 20
FIELD "AD2" SELECT
DO
UNTIL FIELD_CHANGED("AD2")
AD2 = FIELD_TEXT$("AD2")
DRAW ARC x+L1+R1+R2,y-R1-L2,R2,SA2,FA2,AD2
DRAW TEXT "L3:" AT 0,205
FIELD "L3" TEXT prompt$ AT 160,205 SIZE 80, 20
FIELD "L3" SELECT
DO
UNTIL FIELD_CHANGED("L3")
L3 = FIELD_TEXT$("L3")
DRAW LINE x+L1+R1+R2,y-R1-L2-R2 TO x+L1+R1+R2+L3,y-R1-L2-R2
I find that the programming is getting clumsy. Rather than have draw lines and draw arcs with formulas, I asked if the last end point can be set as a new 0,0 location for the next draw command which would simplify things. Can my program be improved?
Also if a wrong entry is made in say 2 fields ago , how can I click back into that field and correct it and the output is updated automatically and continue with the rest of the inputs, currently if I make a wrong entry in any of the fields, I have to start the program again and this becomes annoying
Thank you
Your sample is good. However maybe I haven't explained to well as to what I'm trying to achieve.
I'm trying to achieve a user input each time and draw as variable inputs are entered.
sample file... if you can load and test, screen shot attached
GRAPHICS ! GRAPHICS CLEAR
DRAW COLOR 0,0,0
SET OUTPUT FONT COLOR .4,.2,.1
SET OUTPUT BACK COLOR 1,.94,.86
SET OUTPUT FONT NAME "arial"
SET OUTPUT FONT SIZE 20
DRAW FONT NAME "bradley hand"
DRAW FONT SIZE 20
OPTION ANGLE DEGREES
'set draw to start position
x=350
y=250
'set draw conditions
'DRAW COLOR 1,1,1
DRAW SIZE 2
'goto start position
DRAW TO x,y
DRAW TEXT "L1:" AT 0,0
FIELD "L1" TEXT prompt$ AT 160,0 SIZE 80, 20
FIELD "L1" SELECT
DO
UNTIL FIELD_CHANGED("L1")
L1 = FIELD_TEXT$("L1")
DRAW LINE TO x+L1,y+0
DRAW TEXT "Arc1:" AT 0,25
FIELD "R1" TEXT prompt$ AT 160,25 SIZE 80, 20
FIELD "R1" SELECT
DO
UNTIL FIELD_CHANGED("R1")
R1 = FIELD_TEXT$("R1")
DRAW TEXT "Start Angle1:" AT 0,45
FIELD "SA1" TEXT prompt$ AT 160,45 SIZE 80, 20
FIELD "SA1" SELECT
DO
UNTIL FIELD_CHANGED("SA1")
SA1 = FIELD_TEXT$("SA1")
DRAW TEXT "Finish Angle1:" AT 0,65
FIELD "FA1" TEXT prompt$ AT 160,65 SIZE 80, 20
FIELD "FA1" SELECT
DO
UNTIL FIELD_CHANGED("FA1")
FA1 = FIELD_TEXT$("FA1")
DRAW TEXT "Angle Direction1:" AT 0,85
FIELD "AD1" TEXT prompt$ AT 160,85 SIZE 80, 20
FIELD "AD1" SELECT
DO
UNTIL FIELD_CHANGED("AD1")
AD1 = FIELD_TEXT$("AD1")
DRAW ARC x+L1,y-R1,R1,SA1,FA1,AD1
DRAW TEXT "L2:" AT 0,105
FIELD "L2" TEXT prompt$ AT 160,105 SIZE 80, 20
FIELD "L2" SELECT
DO
UNTIL FIELD_CHANGED("L2")
L2 = FIELD_TEXT$("L2")
DRAW LINE x+L1+R1,y-R1 TO x+L1+R1,y-R1-L2
DRAW TEXT "Arc2:" AT 0,125
FIELD "R2" TEXT prompt$ AT 160,125 SIZE 80, 20
FIELD "R2" SELECT
DO
UNTIL FIELD_CHANGED("R2")
R2 = FIELD_TEXT$("R2")
DRAW TEXT "Start Angle2:" AT 0,145
FIELD "SA2" TEXT prompt$ AT 160,145 SIZE 80, 20
FIELD "SA2" SELECT
DO
UNTIL FIELD_CHANGED("SA2")
SA2 = FIELD_TEXT$("SA2")
DRAW TEXT "Finish Angle2:" AT 0,165
FIELD "FA2" TEXT prompt$ AT 160,165 SIZE 80, 20
FIELD "FA2" SELECT
DO
UNTIL FIELD_CHANGED("FA2")
FA2 = FIELD_TEXT$("FA2")
DRAW TEXT "Angle Direction2:" AT 0,185
FIELD "AD2" TEXT prompt$ AT 160,185 SIZE 80, 20
FIELD "AD2" SELECT
DO
UNTIL FIELD_CHANGED("AD2")
AD2 = FIELD_TEXT$("AD2")
DRAW ARC x+L1+R1+R2,y-R1-L2,R2,SA2,FA2,AD2
DRAW TEXT "L3:" AT 0,205
FIELD "L3" TEXT prompt$ AT 160,205 SIZE 80, 20
FIELD "L3" SELECT
DO
UNTIL FIELD_CHANGED("L3")
L3 = FIELD_TEXT$("L3")
DRAW LINE x+L1+R1+R2,y-R1-L2-R2 TO x+L1+R1+R2+L3,y-R1-L2-R2
I find that the programming is getting clumsy. Rather than have draw lines and draw arcs with formulas, I asked if the last end point can be set as a new 0,0 location for the next draw command which would simplify things. Can my program be improved?
Also if a wrong entry is made in say 2 fields ago , how can I click back into that field and correct it and the output is updated automatically and continue with the rest of the inputs, currently if I make a wrong entry in any of the fields, I have to start the program again and this becomes annoying
Thank you
- Attachments
-
- IMG_2132.PNG (1.67 MiB) Viewed 3261 times
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Draw lines continuously
Maybe the trick would be to dimension a large array and store each x,y coordinate in it. You would also need to store other information about the coordinates, such as when an arc is drawn, the radius etc.
Then if a mistake is made, just redraw up to the error point using a loop with the number of repeats needed. If you set refresh off before you clear screen and redraw, and then set refresh on again when everything is redrawn, the user will not be aware of these processes. They will only see that the line has become a bit shorter, ending at the error location.
Then if a mistake is made, just redraw up to the error point using a loop with the number of repeats needed. If you set refresh off before you clear screen and redraw, and then set refresh on again when everything is redrawn, the user will not be aware of these processes. They will only see that the line has become a bit shorter, ending at the error location.
The only thing that gets me down is gravity...
Re: Draw lines continuously
I'm new to smart basic and to basic language, so I don't fully understand arrays or refreshing screens. I will read up and wotk it out. Thanks 

-
- Posts: 822
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Draw lines continuously
Hi,Erg2 wrote:I'm new to smart basic and to basic language, so I don't fully understand arrays or refreshing screens. I will read up and wotk it out. Thanks
Your program consists of as many code blocks as there are picture components. The structure of those code blocks are similar, so the first and foremost important optimalization is to have one (generalized) drawing block for all components.
So, using the "grand design" your program could look like (in "pseudo code"):
Initializations (graphics and other options, defining interface objects)
DO
Drawing code block (checking and using buttons and input fields)
UNTIL stop button is pressed
END
Designing one step further.
For drawing ARC's, 3 inputfields are needed, assuming that the x,y coordinates of the centre can be calculated from those 3 fields and the current position of the pen.
The same 3 fields may be used for ALL arc's to be drawn.
For drawing a line, one additional field is used (length of the line).
Your program needs 3 buttons: one "draw arc" buton, one "draw line" button and one "stop" button.
Those 7 interface objects may be defined (naming and locating on the screen) in the initialization phase. I would place them near the upper or lower side of the screen, to have a relatively "clean" drawing area.
One step further detailed, your program might now look as follows:
Initialization
- graphics and other options
- define fields and buttons
- specify starting position of pen
DO
IF "draw arc" button pressed THEN
- read fields, needed for an arc
- draw the arc
- set starting point x,y for next drawing command
END IF
IF "draw line" button pressed THEN
- read fields, needed for a line
- draw the line
- set starting point x,y for next drawing command
END IF
UNTIL "stop button" is pressed
END
It is the user's responsability to fill the inputfields prior to each use of the draw buttons.
Voilà, that's all there is to it. With this little program, you can draw a picture with a unlimited number of components.
Just fill in the correct SB statements.
Re: Draw lines continuously
Hi Mr. Henko,
Thank you for your suggestions. But at my stage this is all very new. So I have to read the forums, look at examples and see if I can figure out. It would be much appreciated if you can write a sample program for me of what you have suggested so I can start on this as my building block.
If it's not too much trouble.
Also I was wondering if it's possible to touch a drawn line or arc on the screen say for example the 5th line, correct its values, and once the redraw button is touched, the 5th line is updated and all draws after also pull in/out automatically to touch the end of the corrected line?
thanks & have a great day
Thank you for your suggestions. But at my stage this is all very new. So I have to read the forums, look at examples and see if I can figure out. It would be much appreciated if you can write a sample program for me of what you have suggested so I can start on this as my building block.
If it's not too much trouble.
Also I was wondering if it's possible to touch a drawn line or arc on the screen say for example the 5th line, correct its values, and once the redraw button is touched, the 5th line is updated and all draws after also pull in/out automatically to touch the end of the corrected line?
thanks & have a great day
-
- Posts: 822
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Draw lines continuously
It's not much trouble, but i am hesitating to write complete code on demand. But i gave the complete program in pseudo_code, so i will at least fill it in partly, namely for drawing lines.
You can see then, that one can draw an endless amount of straight lines with only one piece of code. You repeatedly enter a x and y coordinate in the fields and press the draw line button.
Here is the code. Your task to fill in the "arc" drawing code.
As for your 2nd question: what you suggest is indeed possible, but not easy for starting programmers. The TOUCH statement would be used to check if the user tries to touch any of the drawed lines or arcs. So, first of all the drawing history must be stored in arrays. And if a touch at x,y is detected, all the components must be checked if the touch was near to it. If so, from that point on, the drawing proces must be repeated, not triggered by the buttons and the input fields, but by the array entries. And old drawing components must be erased. It really requires some thinking how to organize things. You can try it, but I am not going to deep into that (other things to do, you know
). Success.
You can see then, that one can draw an endless amount of straight lines with only one piece of code. You repeatedly enter a x and y coordinate in the fields and press the draw line button.
Here is the code. Your task to fill in the "arc" drawing code.
Code: Select all
Initialize_program ' this function does what it says
DO SLOWDOWN ' slodown is not a must
IF BUTTON_PRESSED("arc") THEN
'
' here the SB code to read the arc input fields and to draw the arc
'
' xs=... ys=... here the starting coordinates for the next draw
END IF
IF BUTTON_PRESSED("lin") THEN
xt=VAL(FIELD_TEXT$("x")) ' read the coordinate fields
yt=VAL(FIELD_TEXT$("y"))
DRAW LINE xs,ys TO xt,yt ' draw the line
xs=xt ! ys=yt ' prepare for the next draw component
END IF
UNTIL BUTTON_PRESSED("stop")
END
DEF Initialize_program
GRAPHICS ! GRAPHICS CLEAR
DRAW COLOR 0,0,0
SET OUTPUT FONT COLOR .4,.2,.1
SET OUTPUT BACK COLOR 1,.94,.86
SET OUTPUT FONT NAME "arial"
SET OUTPUT FONT SIZE 20
DRAW FONT NAME "bradley hand"
DRAW FONT SIZE 20
OPTION ANGLE DEGREES
'set draw to start position
.xs=350
.ys=250
'set draw conditions
'DRAW COLOR 1,1,1
DRAW SIZE 2
'goto start position
DRAW TO .xs,.ys
DRAW TEXT "x coordinate" AT 15,5
FIELD "x" TEXT "?" AT 10,30 SIZE 120, 30
DRAW TEXT "y coordinate" AT 155,5
FIELD "y" TEXT "?" AT 150,30 SIZE 120, 30
t$="fill in the x- and y-coordinates where the line should go"
draw text t$ at 120,70
button "arc" text "Draw arc" at 370,10 size 120,30
button "lin" text "Draw line" at 500,10 size 120,30
button "stop" text "Stop drawing" at 630,10 size 120,30
end def

Re: Draw lines continuously
Mr Henko,
Thank you so much for taking time to do this and the guides you have given, I really do appreciate
. Have a great day and success to you.
Thank you so much for taking time to do this and the guides you have given, I really do appreciate


