Question
read this very carefully, i want you to use processing for this , i repeat PROCESSING, if you use anything other than processing, expect a thumb down and incomplete. i posted this wuestion probably 10 times already, if u dont know then dont answer it! simple

4. in interactive sketches it is sometimes useful to calculate the distance between two points (x1, x2) and (y1, y2). Here is
0 0
Add a comment Improve this question Transcribed image text
Answer #1

void setup()
{
   size(640, 480);   // size(width, height) : Defines the dimension of the display window width and height in units of pixels
   background(51);   // sets the color used for the background of the Processing window
}

void draw()
{
   float x = 100;   // x-coordinate of top left corner of square
   float y = 100;   // y-coordinate of top left corner of square
   float length = 10;   // length of each side of square
   float threshold = 5;   // threshold distance between the centre of square and the mouse
  
   square(x, y, length);   // draws a square to the screen
  
   float centreX, centreY;
   centreX = x+(length/2);
   centreY = y+(length/2);
  
   if(distance(mouseX, mouseY, centreX, centreY) < threshold)   //condition for mouse being too close to the square
   {
       float dx, dy;
       if(x > width)   dx = -1;   // if sqaure goes out of processing window horizontally
       else dx=1;
       if(y > height)   dy = -1;   //   if sqaure goes out of processing window vertically
       else dy=1;
      
       // Updating coordinates of square each time it jumps away from mouse
       x = x + dx * 20;
       y = y + dy * 20;
      
       background(51);
       square(x, y, length);
   }
}

float distance(float x1, float y1, float x2, float y2)
{
   float tempX = x2 - x1;
   float tempY = y2 - y1;
  
   float X = pow(tempX, 2);   // Sets 'X' to tempX * tempX
float Y = pow(tempY, 2);   // Sets 'Y' to tempY * tempY
  
   float temp = X+Y;
   float dist = sqrt(temp);   // Sets dist to square root of temp
}

Add a comment
Know the answer?
Add Answer to:
read this very carefully, i want you to use processing for this , i repeat PROCESSING,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

  • I am programing an Extended Kalman Filter , with noise but not getting correct answer ....

    I am programing an Extended Kalman Filter , with noise but not getting correct answer . this is my code # ---------- # Part Two # # Now we'll make the scenario a bit more realistic. Now Traxbot's # sensor measurements are a bit noisy (though its motions are still # completetly noise-free and it still moves in an almost-circle). # You'll have to write a function that takes as input the next # noisy (x, y) sensor measurement and...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • I have this case study to solve. i want to ask which type of case study...

    I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT