Liberty BASIC Community Forum
« Mouse Drawing program made Aug 2011 »

Welcome Guest. Please Login or Register.
Nov 17th, 2017, 1:23pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Mouse Drawing program made Aug 2011  (Read 416 times)
michael
Guest
xx Mouse Drawing program made Aug 2011
« Thread started on: Apr 13th, 2015, 8:24pm »

This is an old drawing project I made years ago.
When you sample a color from the palette on the right make sure you rub the mouse over the color !!!
I am starting to see why it was not working properly.
The saveit and loadit option kicks you out cus I screwed something up years ago and I haven't fixed it.

Ill update the code later with a extremely fast method. But for now here is something for you to play with :)
nomainwin
WindowWidth = 800
WindowHeight = 600
dim gr(1024,768)
dim c$(18)
ctrl$ = chr$(_VK_CONTROL)
alt$ = chr$(_VK_MENU)
shift$ = chr$(_VK_SHIFT)
home$ = chr$(_VK_HOME)
end$ = chr$(_VK_END)
insert$ = chr$(_VK_INSERT)
delete$ = chr$(_VK_DELETE)
numLock$ = chr$(_VK_NUMLOCK)
up$ = chr$(_VK_UP)
down$ = chr$(_VK_DOWN)
left$ = chr$(_VK_LEFT)
right$ = chr$(_VK_RIGHT)
c=0
open "This program created by Michael gallup (August 2011) UTILITY " for graphics_nsb_fs as #draw
#draw "backcolor black"
#draw "down": gosub [colorbar]
ma=821:mb=300:m1$="Load":m2$="Save":m3$="Clear":m4$="File name":gosub [menu]
'ma and mb hold the values for the entire menu location
gosub [forceit]
#draw "size 1"
#draw "when leftButtonMove [draw]"
#draw "trapclose [quit]"
#draw "when rightButtonMove [changecolor]"
wait
[draw]
x=MouseX
y=MouseY
if x<0 then x=0
if y<0 then y=0
#draw "place 800 0"
if x>811 then a=x:b=y:gosub [menuactivity]
if x>800 and x<811 then gosub [dfcolor]
if x>800 then x=800
if y>600 then y=600
if x<800 and y<600 then #draw "set "; x ;" "; y
'save this for file data #draw, "set "; MouseX ; " "; MouseY
if x<800 and y<600 then gr(x,y)=c 'store value to dim array only if in drawing area.
wait
[quit]
close #draw:end


[dfcolor]' this checks for mouse position in colorbox and changes color according to where it is.***********************
oldvalue=c
if x>800 and x<810 and y>0 and y<10 then c=0: gosub [forceit]
if x>800 and x<810 and y>10 and y<20 then c=1: gosub [forceit]
if x>800 and x<810 and y>20 and y<30 then c=2: gosub [forceit]
if x>800 and x<810 and y>30 and y<40 then c=3: gosub [forceit]
if x>800 and x<810 and y>40 and y<50 then c=4: gosub [forceit]
if x>800 and x<810 and y>50 and y<60 then c=5: gosub [forceit]
if x>800 and x<810 and y>60 and y<70 then c=6: gosub [forceit]
if x>800 and x<810 and y>70 and y<80 then c=7: gosub [forceit]
if x>800 and x<810 and y>80 and y<90 then c=8: gosub [forceit]
if x>800 and x<810 and y>90 and y<100 then c=9: gosub [forceit]
if x>800 and x<810 and y>100 and y<110 then c=10: gosub [forceit]
if x>800 and x<810 and y>110 and y<120 then c=11: gosub [forceit]
if x>800 and x<810 and y>120 and y<130 then c=12: gosub [forceit]
if x>800 and x<810 and y>130 and y<140 then c=13: gosub [forceit]
if x>800 and x<810 and y>140 and y<150 then c=14: gosub [forceit]
if x>800 and x<810 and y>150 and y<160 then c=15: gosub [forceit]
if x>800 and x<810 and y>160 and y<170 then c=16: gosub [forceit]
if x>800 and x<810 and y>170 and y<180 then c=17: gosub [forceit]
return
'******************************************************************************************************colorbar for paint
[colorbar]
oldvalue=c
c=0
gosub [forceit]
#draw "size 1"
a= 800:b=0
e=810:d=10: gosub [rect]
c=1
gosub [forceit]
a= 800:b= 10
e= 810:d= 20:gosub [rect]
c=2:gosub [forceit]
a=800:b=20
e=810:d=30:gosub [rect]
c=3:gosub [forceit]
a=800:b=30
e=810:d=40:gosub [rect]
c=4:gosub [forceit]
a=800:b=40
e=810:d=50:gosub [rect]
c=5:gosub [forceit]
a=800:b= 50
e=810:d= 60:gosub [rect]
c=6:gosub [forceit]
a=800:b= 60
e=810:d= 70:gosub [rect]
c=7:gosub [forceit]
a=800:b=70
e=810:d=80:gosub [rect]
c=8:gosub [forceit]
a=800:b=80
e=810:d= 90:gosub [rect]
c=9:gosub [forceit]
a=800:b=90
e=810:d=100:gosub [rect]
c=10:gosub [forceit]
a=800:b=100
e=810:d=110:gosub [rect]
c=11:gosub [forceit]
a=800:b=110
e=810:d=120:gosub [rect]
c=12:gosub [forceit]
a=800:b=120
e=810:d=130:gosub [rect]
c=13:gosub [forceit]
a=800:b=130
e=810:d=140:gosub [rect]
c=14:gosub [forceit]
a=800:b=140
e=810:d=150:gosub [rect]
c=15:gosub [forceit]
a=800:b=150
e=810:d=160:gosub [rect]
c=16:gosub [forceit]
a=800:b=160
e=810:d=170:gosub [rect]
c=17:gosub [forceit]
a=800:b=170
e=810:d=180:gosub [rect]
c=0:gosub [forceit]
#draw "place 0 0"
#draw "boxfilled 800 600"
return
'***********************************************
[forceit]' gets color value of 0 to 17 then forces drawing color change
'0 black,1 blue,2 brown,3 buttonface,4 cyan,5 darkblue,6 darkcyan,7 darkgray,8 darkgreen,
' 9 darkpink,10 darkred,11 green,12 lightgray,13 palegray,14 pink,15 red,16 white,17 yellow syntax: #draw "color brown"
if c = 0 then #draw "color black"
if c = 1 then #draw "color blue"
if c = 2 then #draw "color brown"
if c = 3 then #draw "color buttonface"
if c = 4 then #draw "color cyan"
if c = 5 then #draw "color darkblue"
if c = 6 then #draw "color darkcyan"
if c = 7 then #draw "color darkgray"
if c = 8 then #draw "color darkgreen"
if c = 9 then #draw "color darkpink"
if c = 10 then #draw "color darkred"
if c = 11 then #draw "color green"
if c = 12 then #draw "color lightgray"
if c = 13 then #draw "color palegray"
if c = 14 then #draw "color pink"
if c = 15 then #draw "color red"
if c = 16 then #draw "color white"
if c = 17 then #draw "color yellow"
return
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'**********************************************************************************************************save file pic
[saveit1]
open "mybmp.dat" for output as #mybmp
x=0:y=0:goto [saveit]
[saveit]
c=gr(x,y)
if c>0 then print #mybmp, gr(x,y):print #mybmp, x:print #mybmp, y
x=x+1
if x = 801 then x=0:y=y+1
if y = 601 then x=0:y=0:goto [fin]
goto [saveit]
[fin]
close #mybmp
return
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'*********************************************************************************************************load file pic
[loadit1]
gosub [cleargr]
open "mybmp.dat" for input as #mybmp
[entryLoop] 'loop around until end of file or until index = 20
'test for the end of file
if eof(#mybmp) = -1 then [endSeries]
'get the user's name
input #mybmp, c:input #mybmp, x:input #mybmp, y
gr(x,y)=c
goto [entryLoop] 'go back and get another entry
[endSeries] 'entries are finished
close #mybmp
return
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[cleargr]'******************************************clear gr(x,y) array and clear screen*********************************
x=0:y=0:goto [clearit]
[clearit]
gr(x,y)=0
x=x+1
if x = 801 then x=0:y=y+1
if y = 601 then x=0:y=0:#draw "color black":#draw "place 0 0":#draw "boxfilled 800 600":return
goto [clearit]
[rect]'a=811:b=0:e=900:d=50:c=1:text$="Save" c-color (a b e d)-line coordinates tc- textcolor***************************
gosub [forceit]:#draw "line ";a;" ";b;" ";a;" ";d;" "
if a<e then a=a+1
if a=e then c=tc:return
goto [rect]
[input]
ent$="no"'n1$ is name of text to be typed in input for keyboard: ia and ib are locators for keyboard input *********************
a=ia+10:b=ib+10:e=ia+200:d=ib+15:text$=n1$:tc=0:c=13:gosub [rect]:gosub [input1]
return
[input1]' ent$- for enter, and backspace commands
'w$ - is the string that carries your input: l is length of string: limited to 10 characters******************************
if ent$="no" then #draw "place ";ia+10;" ";ib+10;" ":#draw "color white":#draw "|";text$;" ";w$;"_ "
if ent$="yes" then [quit]'back to complete function
gosub [keyboard]:goto [input1]
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'**************************************************************************************************************menu******
[menu]'ma and mb hold the values for the entire menu location
' m1$,m2$,m3$ ect... hold text values for the menu from top to bottom
' l is a length control for the text input controller from keyboard
a=ma:b=mb:e=ma+84:d=mb+15:c=13:text$=m1$:tc=0:gosub [rect]:gosub [text]
a=ma:b=mb+17:e=ma+84:d=mb+32:c=13:text$=m2$:tc=0:gosub [rect]:gosub [text]
a=ma:b=mb+34:e=ma+84:d=mb+49:c=13:text$=m3$:tc=0:gosub [rect]:gosub [text]
a=ma:b=mb+51:e=ma+84:d=mb+66:c=13:text$=m4$:tc=0:gosub [rect]:gosub [text]
a=ma:b=mb+200:e=ma+84:d=mb+249:c=13
return
[text]' #draw "place 0,0" -moves to new drawing loc
a=a-70
nb=d-b:nb=nb/2:b=b+nb+5
#draw "place ";a;" ";b;" ":#draw "|";text$;" "
return
[menuactivity]' this checks for clicks outside the color bar and drawing area
'n1$ is name of text to be typed in input for keyboard: ia and ib are locators for keyboard input
if a>ma and a<ma+84 and b >mb and b<mb+15 then n1$="LOAD FILENAME":ia=0:ib=600:gosub [input]:return
if a>ma and a<ma+84 and b>mb+15 and b<mb+32 then n1$="SAVE FILENAME ":ia=0:ib=600:gosub [input]:return
if a>ma and a<ma+84 and b>mb+32 and b<mb+49 then gosub [cleargr]:return
if a>ma and a<ma+84 and b>mb+49 and b<mb+66 then ia=0:ib=600:n1$="FILE NAME ":gosub [input]:return
return
[keyboard]'remember, trapclose for window must be addressed otherwise when you close window it will have serious conflicts
'Inkey$ example, part two
#draw "when characterInput [keyPressed]"
goto [loopHere]
[loopHere]
'make sure #graph has input focus
#draw "setfocus"
'scan for events
scan
goto [loopHere]
[keyPressed]
key$ = left$(Inkey$, 2):if right$(key$, 1) = chr$(13) then key$="":ent$="yes":return
w$=w$+key$
return

« Last Edit: Apr 13th, 2015, 8:38pm by michael » User IP Logged

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

Rules|Home|Help|Search|Recent Posts|Notification

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