Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 13th Mar 2012 12:22
Hey, sorry making a new post about the same problem, just seemed my post go lost, so here is a new.

So here is the problems i have.
Again stil need help with the drawing lines.
the user should be able to click somewhere on the screen, and then clicks another pleace on the screen and it makes a line from the to seperate clicks. the main problem i have is, i want to save the x,y for the first click, and it shouldn't keep changing with the mouse. this is what i have so fare.
[Code]
If mus=2
If mouseclick() = 1
MuX=Mousex()
MuY=Mousey()
If mouseclick()=1
Line MuX,MuY,Mousex(),Mousey()
Endif
endif
endif
[/Code]

mus=2 is activated when i click on the line icon i the tool bare in my program.
as you may see its not working, here i where i need you guys help to make it work =)

secound problem is not really a coding problem. i just want to know where i could save images(PNG's) for the change mouse command.
Ramon156
14
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 13th Mar 2012 14:11 Edited at: 13th Mar 2012 14:14
Hi.
Here's some code I've written in DBPro.
That's how I would do it, to draw one line.

If you need to draw more lines I think it's best someone else who is more experienced could edit my code or post an entirely new code.

Use W and E to set the coordinates and press enter to draw the line between those coordinates.

This code has been tested and works like it should.
I don't know how I can register the MouseClick once, I will try to add this.

The basic Idea is that you store the first X and Y the coordinates in a variable when you press a key or use the mouse.
After that has been done, you set a variable to check if the first coordinates have been set.
Then you store the second X and Y coordinates in a new variable.

I've commented my code, I hope you can understand it and learn a bit from it.

KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 13th Mar 2012 14:27
Thats my problem, i can't store x,y in a vriable, it keeps changing with the mouse cordinates. but i kinda made it work, now i only need help to make the lines start from second click. now it start where my icon(Mus=2)
If mus=2
wait 5
If mouseclick() = 1
MuX=Mousex()
MuY=Mousey()
wait 2
endif
do
If mus=2
If mouseclick()=1
Line MuX,MuY,Mousex(),Mousey()
exit
Endif
endif
for x = 0 to 1
if mus=x
exit
endif
next x
loop
endif
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Mar 2012 14:54 Edited at: 13th Mar 2012 15:06
That doesn't look like it will work. You need gosubs, and you need click1, and click2. You don't need the waits.. you need


Just add the rest of your code to that template. or use Ramon156 code.

KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 13th Mar 2012 17:29
My code works but again i starts for 0,0.. or the icon where i active the line thing...
thanks both of you. not what i am looking for but thanks for taking time to help. pincho, for some reason your code is taking it all at once...

nvm i will tell in the report that it was a bug.. still need help to the "change mouse" command, i want to know where to save the mouse icons.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Mar 2012 18:54 Edited at: 13th Mar 2012 18:55
Quote: "pincho, for some reason your code is taking it all at once...
"


Oh yeah..
change this..

If mouseclick() = 1
if click = 1 then gosub click1
If click = 2 then gosub click2
endif

To this...

If mouseclick() = 1
if click = 1 then gosub click1
endif

If mouseclick() = 1
if click = 2 then gosub click2
endif

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Mar 2012 01:02 Edited at: 14th Mar 2012 01:14
Hi, thought I'd throw some ideas in here.

Quote: "the user should be able to click somewhere on the screen, and then clicks another pleace on the screen and it makes a line from the to seperate clicks"


What you need are flags that hold the current state of the above sequence. You need a flag that shows the left mouse button is currently being pressed, so the user has to release the button in order to place the second point (or a new line). You also need a second flag to record whether the first or second point of the line has been or is being placed. See the demo below for a way of implementing this (I'm sure there are other ideas lurking in the dark and ancient depths of the forum somewhere).



You'll notice in the code that I have created an off screen bitmap that the user draws to and is then copied to the screen. This allows the use of a "rubber band" line and for any text / icons to be printed to the screen without deletely what has been drawn. I don't know if this is something you sorted out yourself but I thought I'd include it here for the sake of completeness.

Hope this helps.


Edit: only just noticed this:
Quote: " now i only need help to make the lines start from second click"


A little mod to my above demo and I think this is what you want. Use left hand mouse button to draw the lines and then right hand mouse button to finish drawing the lines. You can then keep drawing lines.

KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 14th Mar 2012 14:36
Quote: "Hope this helps."


i have the biggest smile on my face rigth now. it helped alot. best thing happend to me this week, got lots and lots of homework atm, thanks for solving one my problems, so i could acutully finish my program =) and the comments are greate.. thanks alot..

first code was perfect.
thank you very much!
KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 14th Mar 2012 17:42
Is there a way to use your code on a white background? with out the cls?
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Mar 2012 23:43
Yes
KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 15th Mar 2012 00:10
How ?
i tried to delete the bitmap, and the cls,(even tried to change background and line color, but it didn't help) but then it made this meny lines to where ever i move the cursor.
i am not as expirens as you. the most complicated program i have made befor this drawing program was a game where you have to avoide ONE faling brick...
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Mar 2012 02:49
Sorry, I couldn't resist but maybe my sense of humour doesn't translate very well over the internet.

Quote: "i am not as expirens as you. the most complicated program i have made befor this drawing program was a game where you have to avoide ONE faling brick"


It seems to me that you figured out how to do the difficult bit so if you can create a program where the player avoids one block what do you have to do to have two or more blocks? I made a game exactly like this, it had a about 20 blocks, and I didn't know about arrays at the time so I wrote the falling block code and collision code twenty times with each block having its own seperate set of variables. The code was rediculous but it worked, I was happy and I made a couple of games in this style. Then I learned more stuff, like arrays, and, well, here I am still learning stuff but creating games and demos with the knowledge I have at the time. This was all back in the days before I had regular internet access and no help from anyone. But I can see that you've put some effort in so I don't mind helping and I won't pretend it was all fun doing things by myself.

Anyway, back the problem at hand. I'm guessing that you want black lines on a white background. So, I'll take you through my thought process of how I would solve this:

What is bitmap 1? What's it for? Well, it's an offscreen bitmap that we are drawing to. Anything that is drawn to bitmap 1 appears in the picture. It is then copied to the screen so we can see it. Nothing that is drawn to bitmap 1 is ever deleted. You are constantly drawing on top of whatever was there before.

Anything that is drawn to the screen (bitmap zero) is erased by the use of the CLS command at the start of the loop. The screen is being used for temporary stuff that gets updated in each loop, such as text and the rubber band line. When you come to draw the line in your picture (i.e click the mouse a second time) the current bitmap needs to be set to 1, the line is drawn (to bitmap 1), and then the current bitmap is set to zero again.

At the start of the program, the code creates bitmap 1 then has to set the current bitmap to zero (i.e the screen). This is because when you create a bitmap the program automatically sets the current bitmap to the one just created. Now, I said earlier that anything drawn to bitmap 1 appears in the picture. So you can set the current bitmap to 1 at any time and draw whatever you like to it, this can happen inside the loop or before the loop, and it can be a circle, some text, a massive white box that fills the entire bitmap or what ever you like. Just make sure the current bitmap is set correctly.

Try inserting this line:

circle 100,100,10

between the "create bitmap 1" and "set bitmap current bitmap 0" lines (that appear before the loop) and you'll see that there is now a circle in your drawing.

If you want the lines in a different colour, all you have to do is set the INK colour before the line is drawn to bitmap 1. This can be done before the loop or during the loop. If you don't want to be able to change the colour whilst your drawing but just want to set it to a default colour, then do this before the loop (so you don't execute the command unnecessarily). If you want to be able to change the colour as you are drawing, so you can have different coloured lines, then you need to set the ink colour inside the loop but also inside some controls that allow you to change the colour (key presses or whatever).

This may seem a little long winded and, yes, I could've just modified my code and reposted it (it takes two extra lines of code to get a white background and black lines) but if you really want to be good at coding you have to be able to work stuff out. Hopefully, this gives you an insight into the problem solving process, which is much more valuable than anything I else I can give you, and you can now ask yourself, how would I delete the image and start again without restarting the program? How can I draw circles or boxes? How can I put an eraser in? and be able to solve it.
KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 15th Mar 2012 19:42
Quote: "This may seem a little long winded"

Yes but all worth it, learn about bitmap, wicth i didn't know was befor.
i also tried the INK color befor this but i could't get it to work, now it works perfectly. you have a really nice and simple way to explain things unlike my teacher, who i dont understand any thing he tells us. wish you was my teacher =)
Thanks alot(Cant say it enougth), really helped, and i learnd alot.
KhaxaaZ
14
Years of Service
User Offline
Joined: 28th Feb 2012
Location:
Posted: 15th Mar 2012 20:00
Finaly i am done with my program, almost 700 lines of code, most of it is being repeated, like the diffrent buttoms, same code diffrent x,y's color pickers and drawing/Erasing. never i my life thought that a simple drawing program could be so meny lines. on the other hand i smiling really big when seeing what the rest of the class made; Area, and density calculatur. really glad i knew this site where ther is people to help when you need it. thanks alot 29 games.
now just need to write 10 pages about the program.

Login to post a reply

Server time is: 2026-07-09 02:12:51
Your offset time is: 2026-07-09 02:12:51