NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
November 23, 2017, 04:42:24 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Give me a standpoint and I will move the earth. ...Archimedes (287-212BC)
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: hot spots on drawing area  (Read 9536 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Fred Chuit
Newbie
*
Offline Offline

Posts: 18



«
Embed this message
on: December 20, 2008, 12:21:07 am » posted from:Meppel,Drenthe,Netherlands

Dear EJS-users,

Is there a way, in EJS, to create hot-spot areas on a drawing area where one could slide small pictures to, in a way they snap into place.
I couldn't manage to solve this.

Already many thanks for all help and advice.
Regards,
Fred
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: December 21, 2008, 12:48:37 am »

There is an image GUI element in EJS which enable user to drag image(gif or jpg files) in the simulation region. You can add code to snap image to grid position.
e.g. if the distance between is dx, add the following code in OnDrag action:
x=(int)(x/dx)*dx;

Please write down in more detail what you really want to do.
Logged
Fred Chuit
Newbie
*
Offline Offline

Posts: 18



«
Embed this message
Reply #2 on: December 21, 2008, 01:42:05 pm » posted from:Meppel,Drenthe,Netherlands

Dear Prof. Fu-Kwun Hwang,

I am looking for a way to slide pictures of electrical equipment in to a home-circuit.
The pictures are on the right of the screen and the dropzones are in the left part (yellow in drawing).
I hope to find a way that pupils can drag the equipment pictures to several places in the circuit,
so they snap in to place of a dropzone.
I attach a drawing of the idea.

Is such possible to create with EJS?
Already many thanks for any advice and help.

Regards,
Fred


* voorbeeld2.jpg (59.66 KB, 700x480 - viewed 407 times.)
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #3 on: December 21, 2008, 02:27:01 pm »

Yes. It can be done with EJS. You need to code it so that if the image was dragged inside a dropzone, put the image at the specific place.
e.g. if the image coordinate is (x,y) and the dropzone is x0Assume the enable property is draggable. (draggable is true initially.)
Add the following code to the onMouseClick (or onMouseDown) event.
if((x-x0)*(x-x0-w)<0 && (y-y0)*(y-y0-h)<0){
 x=x0+w/2;
 y=y0+h/2;
 draggable=false; // so that user will not be able to drag it again.
}else {
 // add some more code , if the image is not inside dropzone .
}
If you have several drapzone, then you will need a loop to check for each dropzone.

The following is a jigsaw_puzzle created with EJS.





Logged
Fred Chuit
Newbie
*
Offline Offline

Posts: 18



«
Embed this message
Reply #4 on: December 22, 2008, 04:44:21 pm » posted from:Meppel,Drenthe,Netherlands

Dear Prof. Fu-Kwun Hwang,

Your advice is a great help, I am trying to implement it.
An other problem I can't solve is following:
-Is it possible to get the X,Y cooridinates of a moving cursor?
I noticed it is possible to have the coordinates displayed in a drawing area, but is it possible to get them as a X and Y number?
-is it possible to paint the same picture or shape 10-15 times on different locations on a drawing area at the beginning of an animation, or do I have to do each picture or shape separate? If so, how is this done?

Already many thanks for your advice.
Regards,
Fred
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #5 on: December 23, 2008, 12:12:55 am »

Define a variable to store value for mouse x,y in the user coordinate system.
For example: mx,my
In the drawingPanel: find the properties: Pos X and Pos Y
set  Pos X to mx and Pos Y to my
Then, mx and my will always keep the current mouse coordinate when you click the mouse inside the drawingPanel.

You will find imageSet GUI element, set up properties for :# of element and x,y coordinates ...etc,
and EJS will show them (You need to provide enough information to show those images).
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #6 on: December 23, 2008, 09:23:48 am » posted from:Singapore,,Singapore

i agree that it can be done through use of cursor and a 2d trail.

but i am puzzled how to make EJS detect a mouse "on press" on any part of the plot panel to assign (mx,my) to the position of the mouse cursor.

is there more that is needed to make plot panel understand a "on pressed"?

i go explore the plot panel and see how.

cool, the plot panel has a
Visibility and Interaction
Pos X
Pos Y

just assign mx and my.

link for the source and the *.jar are available there Grin
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=830.msg3149#msg3149
« Last Edit: December 23, 2008, 12:17:34 pm by lookang » Logged
Fred Chuit
Newbie
*
Offline Offline

Posts: 18



«
Embed this message
Reply #7 on: December 29, 2008, 08:43:43 pm » posted from:Meppel,Drenthe,Netherlands

Dear Prof. Fu-Kwun Hwang,

Thank you very much for your help and advice on this project.
I am in the stage of fine tuning and can show you how it looks now.
With the applet one can experiment some with dragable equipment in a home environment.
It is not a complex physics problem but was great fun to make.

Again your help was superb,
hoping I can ask you in future again .
Regards,
Fred


* huisinstallatie.jpg (111.78 KB, 761x526 - viewed 302 times.)
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #8 on: December 29, 2008, 09:17:55 pm »

It look like a very interesting simulation. Wink
I hope you can consider attach related files and share your work with other.
You can zip your ejs source and related images files and upload the ZIP file as an attachment. Smiley
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #9 on: December 30, 2008, 06:36:46 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

With the applet one can experiment some with dragable equipment in a home environment.
It is not a complex physics problem but was great fun to make.
Fred

Indeed a great addition to the diverse range of interactive digital media available. Do consider posting your great work Fred Wink

or in this board
Collaborative Community of EJS http://www.phy.ntnu.edu.tw/ntnujava/index.php?board=28.0
« Last Edit: December 30, 2008, 06:38:25 am by lookang » Logged
Pages: [1]   Go Up
  Print  
Give me a standpoint and I will move the earth. ...Archimedes (287-212BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
how to make a variable number appear in the drawing panel?
Questions related to EJS
lookang 13 15667 Last post February 24, 2009, 04:45:54 pm
by Fu-Kwun Hwang
how to make x and y axis automatically on the drawing panel
Questions related to EJS
lookang 4 13291 Last post August 10, 2007, 02:35:48 pm
by lookang
The area of an ellipse
misc
Fu-Kwun Hwang 0 4833 Last post January 02, 2010, 03:38:38 pm
by Fu-Kwun Hwang
how to detect a point is inside an area that is rotatable by cta ?
Questions related to EJS
lookang 2 4365 Last post April 22, 2010, 10:25:02 pm
by lookang
The area of an ellipse
misc
ahmedelshfie 0 2904 Last post May 21, 2010, 12:52:48 am
by ahmedelshfie
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.075 seconds with 22 queries.since 2011/06/15