• No results found

Quick recap

N/A
N/A
Protected

Academic year: 2022

Share "Quick recap"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

Computer Programming

Dr. Deepak B Phatak Dr. Supratik Chakraborty

Department of Computer Science and Engineering IIT Bombay

Session: Elementary Graphics Events Guest Lecturer: Dr. Abhiram Ranade

(2)

Quick recap

Last session: Coordinate based graphics facility of Simplecpp. This session: Handling graphical input

Section 5.5, 5.7, 6.4 of ”An introduction to programming through C++”, McGraw Hill Education, 2014.

(3)

Quick recap

Last session: Coordinate based graphics facility of Simplecpp.

This session: Handling graphical input

Section 5.5, 5.7, 6.4 of ”An introduction to programming through C++”, McGraw Hill Education, 2014.

(4)

Quick recap

Last session: Coordinate based graphics facility of Simplecpp.

This session: Handling graphical input

Section 5.5, 5.7, 6.4 of ”An introduction to programming through C++”, McGraw Hill Education, 2014.

(5)

Quick recap

Last session: Coordinate based graphics facility of Simplecpp.

This session: Handling graphical input

Section 5.5, 5.7, 6.4 of ”An introduction to programming through C++”, McGraw Hill Education, 2014.

(6)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen. The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how. Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(7)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen. The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how. Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(8)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how. Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(9)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how.

Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(10)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how.

Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(11)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how.

Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(12)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how.

Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks. Later: other details such as dragging, mouse buttons..

(13)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how.

Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks.

Later: other details such as dragging, mouse buttons..

(14)

Graphical input

Input given through the mouse, touch screens.

By graphical input we mean information provided to a program by clicking on a screen using a mouse or using a touch screen.

The information usually includes the coordinates of the point at which a click was made, in addition to what was clicked/how.

Advantages:

I Some data is inherently geometric, e.g. coordinates of the vertices of a polygon. Better given by clicking.

I User interfaces, in which buttons can be clicked are very convenient.

This lecture: Graphical input involving mouse clicks.

Later: other details such as dragging, mouse buttons..

(15)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse. When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates. int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 << endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(16)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse. When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates. int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 << endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(17)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse.

When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates. int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 << endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(18)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse.

When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates. int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 << endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(19)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse.

When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates.

int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 << endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(20)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse.

When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates.

int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 <<

endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(21)

Handling mouse clicks: Function getClick()

Signature:

int getClick();

Causes the program to wait for the user to click the mouse.

When the user clicks, at some position(x,y), the function returns. The value returned is65536*x+y.

Here is how you will wait for a click and print the click coordinates.

int v = getClick();

cout <<"x: " << v/65536 <<", y: "<< v % 65536 <<

endl;

This works because thex,y coordinates are much smaller than 65536, and becausevis anint. Thus integer division gets us back the integer quotient and the remainder on dividing by 65536.

(22)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane. Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen. Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(23)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane.

Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen. Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(24)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane.

Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen. Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(25)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane.

Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen. Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(26)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane.

Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen. Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(27)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane.

Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen.

Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(28)

Demo 1: Best fit line

Input: Points (x1,y1), . . . ,(xn,yn) in the plane.

Output: Line which fits them best.

Standard algorithm: Find liney =mx+c such that the vertical distance of the points to the line is minimized (in a least square manner).

Section 5.7 discusses how to calculatem,c.

Observation: It is more natural to give the points by clicking on the screen, and show the line by plotting it on the screen.

Program gets points by clicking. Places a circle at the clicked position to mark it. Then plots the best-fit line.

(29)

Demo 2: Button based turtle controller

In the first session on graphics, we studied Turtle graphics. The turtle was controlled through the program, using commands forward, left, right.

We show a new way of controlling the turtle: the user can click a

”button” on the canvas to move the turtle forward, another to turn the turtle.

A button on the canvas is merely a rectangle with text inside it. To check if a button has been clicked, we merely check if the click coordinates lie inside the rectangle.

(30)

Demo 2: Button based turtle controller

In the first session on graphics, we studied Turtle graphics.

The turtle was controlled through the program, using commands forward, left, right.

We show a new way of controlling the turtle: the user can click a

”button” on the canvas to move the turtle forward, another to turn the turtle.

A button on the canvas is merely a rectangle with text inside it. To check if a button has been clicked, we merely check if the click coordinates lie inside the rectangle.

(31)

Demo 2: Button based turtle controller

In the first session on graphics, we studied Turtle graphics.

The turtle was controlled through the program, using commands forward, left, right.

We show a new way of controlling the turtle: the user can click a

”button” on the canvas to move the turtle forward, another to turn the turtle.

A button on the canvas is merely a rectangle with text inside it. To check if a button has been clicked, we merely check if the click coordinates lie inside the rectangle.

(32)

Demo 2: Button based turtle controller

In the first session on graphics, we studied Turtle graphics.

The turtle was controlled through the program, using commands forward, left, right.

We show a new way of controlling the turtle: the user can click a

”button” on the canvas to move the turtle forward, another to turn the turtle.

A button on the canvas is merely a rectangle with text inside it. To check if a button has been clicked, we merely check if the click coordinates lie inside the rectangle.

(33)

Demo 2: Button based turtle controller

In the first session on graphics, we studied Turtle graphics.

The turtle was controlled through the program, using commands forward, left, right.

We show a new way of controlling the turtle: the user can click a

”button” on the canvas to move the turtle forward, another to turn the turtle.

A button on the canvas is merely a rectangle with text inside it.

To check if a button has been clicked, we merely check if the click coordinates lie inside the rectangle.

(34)

Demo 2: Button based turtle controller

In the first session on graphics, we studied Turtle graphics.

The turtle was controlled through the program, using commands forward, left, right.

We show a new way of controlling the turtle: the user can click a

”button” on the canvas to move the turtle forward, another to turn the turtle.

A button on the canvas is merely a rectangle with text inside it.

To check if a button has been clicked, we merely check if the click coordinates lie inside the rectangle.

(35)

Summary

We discussed elementary graphical input as supported in Simplecpp.

I In many applications, data is graphical. So graphical input is useful, e.g. fitting line to points.

I User interfaces involving buttons/icons are very common. They can be easily implemented using getClick.

I Above situations may arise in many programming projects; graphical input will thus be very useful.

(36)

Summary

We discussed elementary graphical input as supported in Simplecpp.

I In many applications, data is graphical. So graphical input is useful, e.g. fitting line to points.

I User interfaces involving buttons/icons are very common. They can be easily implemented using getClick.

I Above situations may arise in many programming projects; graphical input will thus be very useful.

(37)

Summary

We discussed elementary graphical input as supported in Simplecpp.

I In many applications, data is graphical. So graphical input is useful, e.g. fitting line to points.

I User interfaces involving buttons/icons are very common. They can be easily implemented using getClick.

I Above situations may arise in many programming projects; graphical input will thus be very useful.

(38)

Summary

We discussed elementary graphical input as supported in Simplecpp.

I In many applications, data is graphical. So graphical input is useful, e.g. fitting line to points.

I User interfaces involving buttons/icons are very common.

They can be easily implemented using getClick.

I Above situations may arise in many programming projects; graphical input will thus be very useful.

(39)

Summary

We discussed elementary graphical input as supported in Simplecpp.

I In many applications, data is graphical. So graphical input is useful, e.g. fitting line to points.

I User interfaces involving buttons/icons are very common.

They can be easily implemented using getClick.

I Above situations may arise in many programming projects;

graphical input will thus be very useful.

References

Related documents

motivations, but must balance the multiple conflicting policies and regulations for both fossil fuels and renewables 87 ... In order to assess progress on just transition, we put

To give a perspective on potential benefits, if every country in the world adopted and implemented DPF-forcing Euro 6/VI-equivalent standards by 2025, these policies would

But as cuttlefish, which also h a s almost the same fishing season here as balistids, began to gain export demand since early eighties, the fishermen began to neglect balistids

• The participant observation method, also known as ethnographic research, is when a sociologist actually becomes a part of the group they are studying in order to collect data

Assistant Statistical Officer (State Cad .. Draughtsman Grade-I Local Cadre) ... Senior Assistant (Local

These gains in crop production are unprecedented which is why 5 million small farmers in India in 2008 elected to plant 7.6 million hectares of Bt cotton which

Deputy Statistical Officer (State Cadre) ... Deputy Statistical Officer (Local

Planned relocation is recognized as a possible response to rising climate risks in the Cancun Adaptation Framework under the United Nations Framework Convention for Climate Change