Liberty BASIC Community Forum
Special Topics and Projects >> Game and Graphic Programming >> wanna change color of a LINE in graphics !
http://libertybasic.conforums.com/index.cgi?board=game&action=display&num=1469116653

wanna change color of a LINE in graphics !
Post by Zabo on Jul 21st, 2016, 10:57am

'===========================================LEVEL 3===============================================

[linetrack]
#zeichnen, "color white"
#zeichnen, "line "; startX; " "; startY; " "; oMouseX; " "; oMouseY
#zeichnen, "color " ; color$ 'wanna define here a color that is already chosen before , to change line color for current draw
'color$ is at the moment "red"
#zeichnen, "place "; startX; " "; startY
#zeichnen, "line "; startX; " "; startY; " "; MouseX; " ";MouseY
oMouseY = MouseY
oMouseX = MouseX
goto [input]
========================================

Hi ,

i want to change the color with a variable chosen before in the code in this Graphics tracking code.
Dont know how the exact syntax for this is.

Any help possible. I would appreciate it.

WBR

Zabo
Re: wanna change color of a LINE in graphics !
Post by cundo on Jul 21st, 2016, 1:23pm

How do you want to do it, something like this for example:
Code:
'===========================================LEVEL 3===============================================
OPEN "err wrong title" FOR graphics_nf_nsb AS #zeichnen
#zeichnen "trapclose [quit]"
#zeichnen "when leftButtonDown [linetrack]"
color$ = "red"
#zeichnen "down;fill white;flush"
startX=16 : startY = 16

[linetrack]

#zeichnen, "color white"
#zeichnen, "line "; startX; " "; startY; " "; oMouseX; " "; oMouseY
colordialog color$, color$
#zeichnen, "color " ; color$ 'wanna define here a color that is already chosen before , to change line color for current draw

'color$ is at the moment "red"
#zeichnen, "place "; startX; " "; startY
#zeichnen, "line "; startX; " "; startY; " "; MouseX; " ";MouseY
oMouseY = MouseY
oMouseX = MouseX
'goto [input]
'========================================
wait

[quit]
close #zeichnen : end

 


Re: wanna change color of a LINE in graphics !
Post by Zabo on Jul 21st, 2016, 2:55pm

Hello cundo ,

if it is possible i want to make the command

#zeichnen, "color " ; color$

before

#zeichnen, "place "; startX; " "; startY


color$ is "red" , therefore a colordialog is normaly
not necessary here.

Only to define the color normal , if that is possible.

The color$ is defined in the beginning of the program
before the label of drawing a line is activated.

In that case only this command must be prepared :

#zeichnen "color black"

and changed to :

#zeichnen "color color$"

but that is not functioning in that syntax.

If it is possible , i can change the colors BEFORE

the LINE Label is called. example color$ = "green"


Regards

Hans




Re: wanna change color of a LINE in graphics !
Post by tenochtitlanuk on Jul 21st, 2016, 4:23pm

The following code may help you with an example. Click at a series of places on screen and watch the line colour change.
Code:
open "Line color demo" for window as #zeichnen

#zeichnen    "trapclose [quit]"

#zeichnen.gb "down ; size 10 ; fill 40 40 160"
#zeichnen.gb "when leftButtonDown [paint]"

wait

[paint]
    scan
    #zeichnen.gb "color " ; color$( colorIndex)
    colorIndex =( colorIndex +1) mod 5
    newMouseY   = MouseY
    newMouseX   = MouseX
    #zeichnen.gb "line "; oMouseX; " "; oMouseY; " "; newMouseX; " "; newMouseY

    oMouseY     = newMouseY
    oMouseX     = newMouseX

    wait

[quit]
    close #zeichnen
    end
 

Since you only posted part of your code it's difficult to see exactly what you are trying to do..

PS It helps if you put BASIC listing between code tags, which you get by clicking the # icon on the message editor.
Re: wanna change color of a LINE in graphics !
Post by cundo on Jul 21st, 2016, 4:56pm

There is something missing there John.

To Zabo, the syntax is : #zeichnen, "color "; color$

Code:
'===========================================LEVEL 3===============================================
OPEN " " FOR graphics_nf_nsb AS #zeichnen
#zeichnen "trapclose [quit]"
#zeichnen "when leftButtonDown [linetrack]"

#zeichnen "down;fill white;flush"
startX=16 : startY = 16

[linetrack]

color$ = "red"
#zeichnen, "color ";color$
#zeichnen, "line "; startX; " "; startY; " "; oMouseX; " "; oMouseY

color$ = "blue"
#zeichnen, "color " ; color$ 'wanna define here a color that is already chosen before , to change line color for current draw

#zeichnen, "place "; startX; " "; startY
#zeichnen, "line "; startX; " "; startY; " "; MouseX; " ";MouseY
oMouseY = MouseY
oMouseX = MouseX

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

[quit]
close #zeichnen : end

 

Re: wanna change color of a LINE in graphics !
Post by Zabo on Jul 22nd, 2016, 02:01am

I got it.

Thank you for your help.

Syntax: #zeichnen "color black" is changed to

Syntax: #zeichnen "color " ; color$

That works.

What i program here is a complete rapid drawing program in basic language.
A program for "hands on mentality" in field service technician.

Why is the color here a problem?

Easy case.

For witing a line the linetrack branch makes to erase
all the mouse actions during the endpoint with WHITE.
The color must therefore be changed in the branch label.
Normally , if this erasing procedure is not happen
the predefined color is on the way and NO color is seen
in the complete linetrack label.
Switch to white and then to the chosen color is uptodate.

Level 3 mean that i have arranged the branch labels in categories of code flow.
1. Branch Label 1
2. first from 1
3. first from 2 (Level3)
to see where this branch label come from and what are directly connected to the main code.


Best Regards

Zabo