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.

Dark GDK / I want to make a snowman.please check for errors.

Author
Message
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 22nd Sep 2009 06:27
Kindly help me in this.I need to draw a snowman using Dark GDK
I need help in fixing this.
I want the circles to be filled with white color but i dont know how to do it.
Please check my program and tell me how to fill color in circles.

goonj

Attachments

Login to view attachments
Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 22nd Sep 2009 19:05 Edited at: 22nd Sep 2009 19:05
I got it semi working replace with this, doesnt look that much like a snowman though

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 22nd Sep 2009 20:47
The only thing I had to fix was that the drawArms function header must be added to the function list in the beginning. And the hat is not in a good place but you probably know that since the drawHat function is not even called.

There is no command to draw filled circles or ellipses. Only filled boxes exist. If you want a filled circle, you'll need to search for a suitable algorythm and code it.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 22nd Sep 2009 23:23
hey thank you o much for fixing that up.I will surely fix that hat..lol... i know its big ..! :-p
I also need a little hint in making a OCTAGON ..I just need a rough idea what do I need to do for it.
Also please solve this quiz for me,I'm not able to do the second-
1)Write definition of a function named showName.It should accept an X and Y coordinate AS arguments.The function should dispplay your name in the center just below these coordinates.(I have done it but just check it please)
Ans-
void showName()
{
int centerX;
int centerY;
int width;
int height;
width=dbScreenWidth();
height=dbScreenHeight();
centerX=width/2;
centerY=height/2;
dbDot(centerX,centerY);
dbCenterText(centerX,centerY,"Name");
}

2)Write the definition of a function named drawTriangle.It should accept an X and Y coordinate as arguments.The function should draw a triangle with top of the triangle,located at the coordinates passed as arguments.The height of triangle should be 50 pixels.

I need help with the second one ,how to do that.I have tried like this-
void drawTriangle()
{
int X;
int Y;
int width;
int height;
width=dbScreenWidth();
height=dbScreenHeight();
.
.
.
.

goonj
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 23rd Sep 2009 21:40
1) First of all, if the task says that the function has to accept the coordinates as ARGUMENTS, that means you have to pass those coordinates to the function from the outside, when you call the function. The showName function you wrote has no arguments.

Second, when you define a variable, you can initialize it at the same time, so instead of writing this:



write this, next time:



But this is not even necessary, because you can calculate the values "on the fly", without storing the values in variables, if the code is simplified. This is my solution to your first task:



I commented out the dbDot because that is just for checking that the text is in the good place, it is not necessary to execute the function. Note the X and Y function arguments and how they are used when the function is called. Since the task only wants the function definition, the solution is only the function header and the one-line function body, but I wanted to show you how it's called from DarkGDK main program.


2) The second task is really easy, you should be able to figure it out on your own. The top corner is the X,Y position that the function receives as ARGUMENTS (see the previous example). If the height of the triangle is 50 pixels, then the Y coordinate of the other two points will be Y+50. The width of the triangle is not specified, so we can use any value we like. If the width is also 50, then the X coordinates of the other two points will be X-25, X+25. Connect the three points with dbLine.

First try to write it on your own, then check out the code below.




3) For an octagon: Divide a circle (360 degrees) into 8 parts, what do you get? An angle of 45 degrees. Calculate the 8 points on the circle which are 45 degrees apart from each other and connect them. Four points are very easy to calculate, if the octagon is oriented so that one of the corner points is at the top. For the other four corners you need sine/cosine. But, since the sine and cosine of 45 degrees are equal, you only need one of them.

In the code below, the center point and the radius of the octagon are all arguments of the function, so it can be called with different values. Again, think about it on your own before you have a look at the solution.

Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 23rd Sep 2009 22:18
hey thank you so much for helping me out.I need to write my own code first before I see the solution you gave for octagon.I hope i will be able to figure it out and if not, i will ask you the doubts.
Thank you

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 23rd Sep 2009 22:20
Also,I use vista O.S.
When i built any program that has circles,it does not show up on the output window.
Can u tell me how to fix that up.

goonj
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 24th Sep 2009 08:52
We cannot fix the circles. Yesterday I wrote a bug report about this, we'll see what the developers of Dark GDK say to it.

http://forum.thegamecreators.com/?m=forum_view&t=158209&b=15

One more thing about the octagon. The code I wrote yesterday is a special case, because I supposed that one corner point is on the top (North, zero degrees). This is only one of many orientations that the octagon can be rotated. A proper function would be more general, but then it needs more sine/cosine calculations.

Here is the general method. Let's say we want a horizontal line to be on top, which looks more natural to the eye than corner-up view. Then, imagine the first point of the octagon is rotated 22.5 degrees (half of 45 degrees) to the right. Calculate the coordinates of the first point by using sine/cosine (you need both, they are no longer equal in a general case) and the radius of the octagon. Then for any subsequent point, increase the angle by 45 degrees and repeat, until you reach 360 degrees.

This is really calculating points on a circle. You will need to store the coordinates of the previous point, because you have to connect them with dbLine. All points can be calculated in a loop. The starting angle can even be an argument to the function, so that you can rotate your shapes in any way you want.

I'll post the general function code as well if you wish.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 27th Sep 2009 04:03
I tried doing the octagon program but i can make it working.Can you please help me out.
I do not have to use cos and sin as told by my professor .i just need to make that with the LINES

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 27th Sep 2009 06:33
i tried this but this is no where near to an octagon.
i can not use sine and cosine..
Please help me out....
Also can you explain me how to do it...
The width should be 40 and height should be 40... that is all i need.

goonj
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 27th Sep 2009 14:56
If you are not allowed to use sine/cosine, then ask the solution from your professor because I don't know any other way. At least, not if the sides of the octagon should be of equal length. I immediately supposed that it should be a "regular" octagon, but if it doesn't matter that the sides are not equal, then just experiment with the corner point coordinates until they look good.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 28th Sep 2009 04:13
ok i can use sine and cosine now but stil im not able to make it work.can you tell me how to caculate the difference and everything.

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 28th Sep 2009 05:03
i need to get 40 height and 40 width.... please help me out...

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 28th Sep 2009 05:26
I need the horizontal line on top of the octagon and not the pointed corner on top.
Please tell me what am i suppose to do.i tried with the graph but i can not make it 40pixels high and 40 pixels wide

goonj
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th Sep 2009 08:22
After some more thinking, I came up with a solution that does not require sine-cosine. Strange that the simplest way comes to mind last... (It's a long time since I was at school.) Anyway, here it is: think of a square, then cut off the corners. See the attached picture.

If CX,CY is the center point and width = height, then the P1 and P2 point coordinates on the picture can be calculated like this:

P1X = CX - Width / 2
P1Y = CY - Width / 4

P2X = CX - Width / 4
P2Y = CY - Width / 2

And so on, all the points can be calculated only by using half of the width or a quarter of the width. Always store the previous point's coordinates in variables, so that you can connect them with the current point.

Attachments

Login to view attachments
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 1st Oct 2009 06:50
1)Can you tell me how to flip an image vertically and horizontally with a bitmap number 2 or anything.
2)Also how to change the image key color to blue?

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 1st Oct 2009 06:51
Also you remember I made the snowman.I need to add a background image in that program.Please tell me how to do that by dbLoadBitmap()

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 1st Oct 2009 07:59
I want to include an image in the background of this snowman but Im not able to figure out what's wrong with my code.Please check and tell me what needs to be fixed.
The image is in the same folder where the snowman project is.I either get just the image or just the snowman but im not able to get them together.

goonj

Attachments

Login to view attachments
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 1st Oct 2009 08:03
Also I need some suggestion or hint on this question.

Ques.To draw an image of a spaceship.Select key color to use as the background.Then,draw a second image of a planet surface.
after you create the images,write program that displays the planet surface with the spaceship above it.
each time the user press a key,the spaceship should be displayed at a lower position.After user pressed a key for five times,the ship should be positioned on the planet's surface and the program should end.


goonj
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 1st Oct 2009 23:42


You load the image as a bitmap, then try to display it as an image. A bitmap and an image is not the same. Use dbLoadImage.

And place the loadBitmap function call in the beginning of your main function, because if it's loaded last, it will cover the snowman drawing.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 1st Oct 2009 23:49
I got that snowman working thanks anyways.
I made this one also but im not able to get the spaceship on top of the background of the planet.
Look into my program and please tell me whats wrong with it.
Also my professor told me that we can not pass dbScreenwidth()/2 and dbscreenheight()/2 as arguments in the function definition.Is that so?
The question was->
To draw an image of a spaceship.Select key color to use as the background.Then,draw a second image of a planet surface.
after you create the images,write program that displays the planet surface with the spaceship above it.
each time the user press a key,the spaceship should be displayed at a lower position.After user pressed a key for five times,the ship should be positioned on the planet's surface and the program should end.

goonj

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 3rd Oct 2009 14:11
It's exactly the same problem that I said in the previous post: an image and a bitmap are not the same objects, not even if they have the same identification number. You load two bitmaps, then try to display two images, which do not exist. Also the color key won't work on bitmaps, only on images. Use dbLoadImage instead of dbLoadBitmap.

Quote: "my professor told me that we can not pass dbScreenwidth()/2 and dbscreenheight()/2 as arguments in the function definition.Is that so?"


I can't even understand the statement. The "function definition" is the code where you write out the function header and the function body. Of course you can't pass any arguments there, since you pass arguments when you call the function, not when you define it. Unless your professor wanted to say something else.

But since you are studying all this at school, wouldn't it be simpler to ask directly your professor what he meant? Or your classmates? No offense meant, but you can't expect anyone on the forum to explain or solve all your homework. You have the best possible source of information near you: your teacher.
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 4th Oct 2009 04:17
i made this program for the spaceship one.
I can get the both images on window but i need to make the background of spaceship transparent so that it does not overlap the surface of planet.Also i need to bring the spaceship from top to bottom(on the surface) when the user enters anything.

goonj

Attachments

Login to view attachments
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 5th Oct 2009 03:34
i have done a more in it.
What i need to fix now is ... when i press the key the top of the spaceship part is left above and also i'm not able to get the spaceship on the surface.plz help

goonj

Attachments

Login to view attachments
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 5th Oct 2009 04:53
Did you read the responses to your previous posts ?

You are still making the same mistake with Images and Bitmaps that was explained to you by Miraben.

In DarkGDK... and IMAGE and a BITMAP are NOT the same. They are 2 Different kinds of things and are not interchangeable.

It is true that there is a format of image known as "a bitmap", usually a windows .bmp file, DarkGDK bitmaps are NOT windows bitmap images, again they are 2 different things. In DarkGDK a Bitmap is a surface that you can draw to, like a render target, but has nothing to do with images.

The set of commands that are Image related.. eg :

dbGetImage()
dbPasteImage()
dbLoadImage()

are NOT compatible with the commands that are bitmap related.. eg:

dbLoadBitmap()
dbPasteBitmap()
dbCreateBitmap()

You cannot load an image, then expect it to be displayed as a GDK bitmap without first copying it onto the GDK bitmap properly.

Also, your call the command dbSetImageColorKey() twice, using the same value. I think that you are doing this in the belief that you need to call it once for each image. That isnt correct. The usage of that command is to set a "global" color that GDK will treat as transparent. So, you only need to call dbSetImageColorKey once, but you need to make sure that whatever color you designate as transparent, is used as transparent in all of your images. You cannot, for example, have a pink as transparent then expect another image loaded with green as transparent to work(at least without some more setup, its possible with multiple render passes, but inefficient)

To help you with the basic logic of how you need to code your program, you could use something like this :

1 - Load images, set color key and enter main loop
2 - Paste planet image and spaceship image
3 - detect any user input(when dbScanCode() is equal to anything other than 0 the user has pressed a key)
4 - when user input is detected, paste the ship image 1/5 of the way closer to the planet image.

So say at the start, you spaceship is 250 pixels higher than your planet image. Each time the user presses a key, you would re-paste the spaceship image, 50 unites lower. After 5 key presses the spaceship should be level with the planet.

You will need to make sure that only 1 keypress at a time is read, otherwise you may endup with your spaceship looking like it "instantly" appeared on your planet, keep in mind that the main loop of your program will execute somwhere around 60 times per second. so there is a chance that any key pressed will be read 60 times per second, meaning 5 keypresses will go past quickly if not checked.

If it ain't broke.... DONT FIX IT !!!
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 5th Oct 2009 05:10
i made it work...but i dont know if its right or not... i can now get it on planet when i press a key 5 times

goonj

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 6th Oct 2009 20:44
It's enough to set the color key only once, it should apply for all images.

The dbDeleteBitmap and dbCopyBitmap commands are not meaningful. Again, you try to delete a bitmap that does not exist, then copy the just deleted bitmap to the screen. This shouldn't work too well.

You don't need to delete an object to make it disappear from the screen and put it into a new position. It's enough to clear the background with dbCLS, or, if you have already a full-screen background picture, then paste the background picture again.

If the bitmap commands are removed, then this is what remains (just the part after the images are loaded):



First, I would add these lines after the last "waitkey", to erase the two images from memory before the pogram exits:



Second, if you paste the spaceship image again and again, you will have several images of the same spaceship appear under each other on the screen. The background should be restored before the spaceship image is pasted again.

Third, if the coordinates are modified a little, then these repeated actions can easily be organized into a loop. For example like this:



The last coordinate where the ship "lands" will be the same, 100.
crystalgolem
14
Years of Service
User Offline
Joined: 8th Oct 2009
Location:
Posted: 9th Oct 2009 02:56
...these cries of help sound rather familiar....im picking up waves of stupidity.....nooj is that u? .........dude if u need help with ur homework then ask me, i might not be Todd but i can still get the job done......and honestly the answers to all ur questions uv asked so far are in our textbooks...trust me i found them there....
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 9th Oct 2009 03:34
well i have fixed all my programs on my own.By the time i got this post, i was already done with my work.I m not crying out for help...I just needed correction...not the whole program.
Anyways thanks

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 9th Oct 2009 03:36
and my name is GOONJ not NOOJ!

goonj
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 19th Oct 2009 05:34
Hey I made this program to display roman numbers but if i use only LoadBitmap(),then the image is not displayed so I used CopyBitmap and PasteBitmap which has helped in displaying the image but after displaying image 3 i.e.i., roman number III , i can not see the menu option again because it hides behind the image maybe or disappears.Please I need to fix it somehow,I have tried all ways but can not fix it.Also I do not see the default option displayed when i press anything other than 1-5

goonj

Attachments

Login to view attachments
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 19th Oct 2009 05:38
here is my roman number image,in case they need some attribute change..im attaching roman number I

goonj

Attachments

Login to view attachments
Goonj
15
Years of Service
User Offline
Joined: 21st Sep 2009
Location:
Posted: 22nd Oct 2009 08:01
I need help with this program
Color Manipulator
I need to make a program that changes the pixel color to black if the color component blue and green are less than 100.I need to change each pixel to black if the condition is satisfied.I have made the following program if you want to have a look and tell me what needs to be fixed.

If not then the program should stop.

goonj

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-10-01 16:33:44
Your offset time is: 2024-10-01 16:33:44