I am trying to draw a town. I have the pic of one house drawn. I need to be able to write a code to copy that picture and multiply it at different coordinates and different sizes. I have the code for the one house written, but I can't figure out how to multiply it. (Pic attached of example) I'm using DrJava.
My code for the house is: -
public void drawHouse() {
-
//get graphics
-
Graphics graphics = this.getGraphics();
-
//start with black color
-
graphics.setColor(Color.blue);
-
//draw a filled rectangle
-
graphics.fillRect(10,210,200,100);
-
//set color back to black
-
graphics.setColor(Color.black);
-
//draw triangle
-
Polygon poly = new Polygon();
-
poly.addPoint(10, 210);
-
poly.addPoint(110, 50);
-
poly.addPoint(210, 210);
-
graphics.fillPolygon(poly);
-
//draw windows with yellow
-
graphics.setColor(Color.yellow);
-
graphics.fillRect(20,220,50,45);
-
graphics.fillRect(150,220,50,45);
-
//oval window
-
graphics.fillOval(85,150,50,45);
-
//draw door with black
-
graphics.setColor(Color.black);
-
graphics.fillRect(85,220,50,90);
1 1820
Well, the general idea would be to create a drawHouse() function which takes the arguments - x The x-coordinate of, say, the top left corner.
- y The y-coordinate of the same corner.
- scale A scaling factor.
Or alternatively: - x The x-coordinate of, say, the top left corner.
- y The y-coordinate of the same corner.
- width The width of the house.
- height Th height of the house
The code you already wrote would have to be modified something like this: - //...
-
graphics.fillRect(x,y,20*scale,10*scale);
-
//...
-
poly.addPoint(x, y);
-
poly.addPoint(x + 10*scale, 5*scale);
-
poly.addPoint(x, x + 20*scale);
-
//...
or - //...
-
graphics.fillRect(x,y-height/3,width,2*height/3);
-
//...
-
poly.addPoint(x, y);
-
poly.addPoint(x + width, width/2);
-
poly.addPoint(x, x + width);
-
//...
and so on and so forth.
You don't have to create a new Graphics- or Polygon-Object for each house, by the way (though you could).
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lawrence |
last post by:
I've the form you see below, which is supposed to upload an image. I
expect the image name as a var to be $uploadedFile. In the receiving
function, I've this code:
global $uploadedFile,...
|
by: Bill N. |
last post by:
Using VB .Net 2003 Standard Edition.
This simple form has a "File in Use" problem while the executable is running.
Created this simple program to make sure that I hadn't done something in my...
|
by: kris_scheyer |
last post by:
Hi,
I've searched dozens of forums and websites to find a way to have
javascript copy an image I click on into the clipboard of windows. I
found a few examples but I couldn't get any of them to...
|
by: Frank Rizzo |
last post by:
How can I retrieve the dimentions of the image that's been loaded into a
picture box?
Thanks
|
by: Ricardo Furtado |
last post by:
I'm developing a drawing software in visual basic .Net and i need to copy the
image that exists in a picturebox and automaticaly paste it in another
picturebox as being part of that other image....
|
by: fergarduno |
last post by:
I do have a RAW image file and i want to load it to a picture box i want to know please if it es posible and how to do it without having to buy an ActiveX component
Thanks
|
by: Shmedlap |
last post by:
I want a picture of my form for documentation, but when I use <Print Scrn> with or without <Ctrl><Alt> I get also the entire Access application. I just want the form window. True I could open up the...
|
by: aeris |
last post by:
Hello, sorry for disturbing.
I have a pictureBox on my form. May i know how to open the image from the pictureBox in Windows Picture and Fax Viewer?
I've tried the code below, but it failed...
|
by: nuhbye |
last post by:
I want to display a bitmap in its original size using a picturebox and scrollbar, but i couldn't find any option to clip a bitmap and display it in the picturebox, i am searching for one like we have...
|
by: Eugene Gephart |
last post by:
Trying to link radio buttons with images in a picture box, but can't remember how to start the coding.
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |