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.

AppGameKit Classic Chat / simple drawing commands

Author
Message
basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 4th May 2013 23:53 Edited at: 5th May 2013 18:22
hi guys:

Based on the command "DrawLine" we can create all other drawing commands.

the following program creates the listed drawing commands:

_DrawCircle(x,y,radius,red,green,blue)
_DrawFillCircle(x,y,radius,red,green,blue)
_DrawAnimatedCircle(x,y,radius,rotation#,red,green,blue)

_DrawOval(x,y,radiusX,radiusY,red,green,blue)
_DrawFillOval(x,y,radiusX,radiusY,red,green,blue)
_DrawAnimatedOval(x,y,radiusX,radiusY,rotation#,red,green,blue)

_DrawPolygon(x,y,radius,numberoflines,red,green,blue)
_DrawFillPolygon(x,y,radius,numberoflines,red,green,blue)
_DrawAnimatedPolygon(x,y,radius,numberoflines,rotation#,red,green,blue)

_DrawBox(x1,y1,x2,y2,red,green,blue)
_DrawFillBox(x1,y1,x2,y2,red,green,blue)

_DrawTriangle(x1,y1,x2,y2,red,green,blue)
_DrawFillTriangle(x1,y1,x2,y2,red,green,blue)




this program uses 640*480 screen size.

hope this would be helpful



Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th May 2013 00:09
Very useful! Thanks for sharing


this.mess = abs(sin(times#))
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 5th May 2013 00:14
Oh frikkin fantastic. You made my day,Basjak!

here is a carrot!

I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th May 2013 02:35 Edited at: 5th May 2013 02:47
Here's a fill circle function that doesn't loop 720 times or use sin/cos.





Here's a box with rounded corners, originally made by Obese.



When I came home this evening I had planned on creating a similar set of commands by simply porting my old DBP commands:
http://forum.thegamecreators.com/?m=forum_view&t=203590&b=6

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 5th May 2013 03:13 Edited at: 5th May 2013 03:42
Very nice, Phaelax.

I doubled basjak's filled circle to make up for resolution change.



They are both equally fast it seems...

Edit: No they are not....Basjak's doubled is faster...



I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th May 2013 06:48
I don't see from that snippet how you determine his is faster. All I can see is that his doesn't fully fill a circle.

But I did run a test with timer. And basically, where a certain number of calls with my function took 1700ms, his took 88ms. Huge difference, and I'm not sure why the difference is that large.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 5th May 2013 07:06 Edited at: 5th May 2013 07:57
Quote: "I don't see from that snippet how you determine his is faster. "


I used the snippet on my laptop forcing the built in intel hd 3000 graphics chip (it's a double chip laptop with an extra ati card) - and yours moved considerably slower (or choppier).

Quote: "Huge difference, and I'm not sure why the difference is that large"


I don't know why either...

Could it be the IF statement?
EDIT: I think it is. You have two if statements. Basjak has none. Tell don't ask is the factor here - I think...

Quote: "All I can see is that his doesn't fully fill a circle."


So the doubling up didn't make a full circle for you?

I never want what I know.
haliop
User Banned
Posted: 5th May 2013 07:46
very cool stuff thank you for sharing

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th May 2013 14:10 Edited at: 5th May 2013 14:11
Here's what that doubling looks like on my machine (and makes sense considering how it fills the circle):



"You're all wrong. You're all idiots." ~Fluffy Rabbit

Attachments

Login to view attachments
basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 5th May 2013 15:15
good morning:

am happy to see the others sharing my love to 2D commands.

back to the top. I added the following commands:

it looks really cool.

@Phaelax: the thing about sin/cos is that we have more control over the commands. as well it can shorten our code.

Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 5th May 2013 17:41
Quote: "it looks really cool."

Yes they sure do!

I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th May 2013 02:14
Quote: "@Phaelax: the thing about sin/cos is that we have more control over the commands. as well it can shorten our code."

More control how?

I'm still curious as to why there is such a huge speed difference between the commands. Shorter code doesn't necessarily mean anything. I stripped out the drawLine command in each and time both purely on the loop and inner calculations. It's still a difference of about 1660 to 80 for 375 function calls with a radius of 150. Yours makes a total of 720 iterations to draw a circle, whereas mine is dependent and equal to the radius and so only made 150 total iterations(counted from inside the inner FOR loop).

I then changed it from using ^2 three times to just multiplying by the numbers themselves and the time got even longer, 1930. (In DB, it turned out to be faster to multiply instead of square a number through an exponent, opposite in AGK).

Then I found a typo, where I subtracted r from x but what I really wanted was the radius. Turns out I was subtracting the red component for the draw color instead, which oddly the program works the same either way, only now it became 3 times faster. Puts my run time (using same test method as before) at 415ms. Still not as fast as 80, but better. I changed d# to an integer (a float wasn't really needed there) and it dropped to 350ms.

Threw the drawLine back in now that I corrected my code, and timing the two based on Timeshark's example, they're much closer now: 3477 for mine, 3032 for basjak.

Got me thinking of a way to make it more efficient. Using sqrt, my new function did the test in 6ms. However, it requires drawing two lines for each iteration, and ended up being slower than both.



"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 6th May 2013 03:39 Edited at: 6th May 2013 05:58
This is fun

Having a solid filled circle is more important (for me).
Great Work Phaelax.

I'm looking forward to analyze the different methods a little later
(focused on my own code now - very focused)

Shaving of milliseconds here and there is always a good thing. The finding of those milliseconds wil be a useful speed-lesson for other things.

I never want what I know.
basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 6th May 2013 05:03
by the way, am very open to any better solution. this is what this forum is all about .

- regarding filled circle there maybe another faster options but sin/cos allowed further commands developments which led to shapes rotated and animated

- simple modifications will enable us to draw arcs,much better rounded box resolution, colorful digital signs etc.........

my example on the top has 15 object 5 of them are animated and the last one required more drawings and after all it doesn't seem that the program is slowing down. I even tried it on my android with no trouble at all(a bit slowed down actually).

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th May 2013 07:27
It doesn't bother me who has the fastest method, I just want to know why a function with many more times the iterations and more complex math commands runs faster.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
haliop
User Banned
Posted: 6th May 2013 08:52
makes me wonder how can i draw a rotated box ?
anyone?

Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 6th May 2013 09:00
Quote: "makes me wonder how can i draw a rotated box ?"


In a lot of ways.
The fastest is to create a sprite with image 0 and just rotate the sprite.

//CreateSprite(1,0)
//SetSpriteColor(1,red,green,blue,alpha)
//SetSpriteAngle(1,Angle)

I never want what I know.
haliop
User Banned
Posted: 6th May 2013 09:12
cant use sprites since i use get image and when im drawing sprites...
the first will remain on top and all others will be behind it... kinda not working right for me.. if i could use sprites i wouldnot even ask that question... sorry..

Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 6th May 2013 09:17 Edited at: 6th May 2013 09:27
Quote: "the first will remain on top and all others will be behind it"


So the solution I proposed in this thread:
http://forum.thegamecreators.com/?m=forum_view&t=204586&b=41
didn't work?

EDIT: SetSpriteDepth also changes the order of the sprites.

But I'll think of something. Do you want An animated/rotating box or do you just want to draw it in an angle?

I never want what I know.
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 6th May 2013 09:37
Back in the good old Amiga days, we use to pre-calculate the sin/cos into arrays, since reading an array was faster than doing sin/cos calculation.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
haliop
User Banned
Posted: 6th May 2013 09:55
the suggestion didnot work...
since i dont use Render before get image since it will also draw the buttons into the image... so no.. also the spritedepth 0 also didnot work...
and i want them only in an angle..but i cant use sprites ... which kinda sux cause i really want to use them..

Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 6th May 2013 11:41 Edited at: 6th May 2013 11:42
Haliop,
I added animation to Basjak's _DrawFillPolygon
If you set the rotation from 0 to 360 and use only 4 lines you will at least get a filled Square.





I don't know how fast it is though. (I'm not really good at trigonometry)

I'll check out the drawFillBox and see if I can add animation to that

I never want what I know.
haliop
User Banned
Posted: 6th May 2013 11:49
you know what i got a challenge for you! who ever choose to accept it!


lets say i have an image , any image..
what if i want to use DrawLine command to mimic that image on screen with lines...

hmmm i think thats a hard one to achive.. but maybe it will be with a nice tweeked function faster then DrawSprite... DrawImage(x,y,angle) hmmmmmm!!!!!!!!!!!!!!!!!!!!!!!!!!!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th May 2013 11:56
It's worth remembering that processors below ARM V7 do not have hardware floating-point processors, so avoiding FP as much as possible is a good idea!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
haliop
User Banned
Posted: 6th May 2013 11:58
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th May 2013 12:31
Apple's processors are "secret" - but hackers think they may be Cortex derivatives.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th May 2013 20:47
Quote: "ARM v7 is Iphone 5 right?"

Quote: "Apple's processors are "secret" - but hackers think they may be Cortex derivatives."


The 4S is an Apple A5; Cortex A9
The 5 is an A6; a custom ARM 7

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 7th May 2013 00:22 Edited at: 7th May 2013 00:39
Phaelax or Basjak,

Could you give me the formula to get the angle of a line if you know the x1,y1,x2,y2 value. I've really tried to find it out with your code but there are just two many formulas so my brain gave up

I guess there is a bunch of ways, but knowing at least two different versions - One with float and one without - would be a great knowledge to build upon. I believe I then have the knowledge to build a lot of things myself. And maybe one without sin,cos and float altogether...if possible.

I think having one without float would be good considering jimhawkins warning
Quote: "It's worth remembering that processors below ARM V7 do not have hardware floating-point processors"


I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 00:46
Tim,

atanfull(x1-x2, y1-y2)

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 7th May 2013 00:50
Great. thanks. Forgot something. I meant with an added value - degree or angle

I never want what I know.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 7th May 2013 01:48 Edited at: 7th May 2013 01:49
Quote: "atanfull(x1-x2, y1-y2)"

Never liked this command, so I wrote my own.

My problem with it is this;

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th May 2013 01:50
What's thisAngle?

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 7th May 2013 01:52 Edited at: 7th May 2013 02:03
a typo

edit: .. which will confuse people now since I corrected it before you posted

Here's what I use

Yeah, I know - long winded and not very efficient, but it's old code which has never failed and always gives the same angle I put in.

It's in several bits because it's part of a suite of functions I use for 2d Vector routines.

Optimisations welcome.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 03:38
Wow, all that just to get the angle between two points? I don't know why you wouldn't like to use atanfull, it's math is pretty simple:



"You're all wrong. You're all idiots." ~Fluffy Rabbit
easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 7th May 2013 04:32
Here's a number of functions I use in Airstrike Unleasehd (working title, pre-alpha so far).

you wouldn't believe how useful something like diff(a,b) is!

Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 7th May 2013 07:02
Ok. sorry you have to spoonfeed me but...

How do I use the angle produced by: atanfull(x1-x2, y1-y2)
on drawline(x1,y1,x2,y2)....to draw an angled line....

Let's say I have drawline(100,100,200,100) (0 degrees)
and I want to animated that from 0 to 45 degrees

How do I calculate the new x1,y1,x2,y2 (i guess it will be based on the midpoint of 100,100,200,200)?

I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 07:47


But if you're just drawing a line from point A to point B, then there's no reason to calculate the angle between A and B since you already have the points.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 7th May 2013 08:06
Phaelax,
I'm trying to animate it. Rotate it.

I will use this knowledge to rotate e.g. a filled rectange (which consist of lines)

I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 08:27
This will draw a rotated filled(sort've) rectangle.



"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 7th May 2013 08:47
Great, thanks.

This I can pick apart and Finally understand how you add the rotation to the lines.

I never want what I know.
haliop
User Banned
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 13:02
I'll try to explain the method for ya.

First, think of how to draw a filled rectangle with lines without it being rotated. You'd draw lines going from left to right for the width of the rectangle, incrementing downward to the next line until you've reached it's height.

Now rotate it. The width and height haven't changed, merely the starting points for the line. Obtain the sine/cosine values of the rotation angle, and multiply that by the width for both X and Y axis. By adding these values to the origin, you have end points for your first line.

How do we get the next starting point for the 2nd line below? Determine the angle for the side of the rectangle. If the top line for a rectangle is axis-aligned and going from left to right, you can think of this as having 0 rotation. So the side of the rectangle forms a 90 degree angle with the top. When the rectangle is rotated, simply add 90 to the rotation value to obtain the direction of the sides.

Increment the amount you multiple that new value by 1 until you reach the full amount, which is the rectangle's height. Each time you do this, that is your new origin. Add the first values we calculated to it to obtain that line's new end points.

So basically, we're using sin/cos to determine the direction of the legs on the rectangle. You can think of this as a direction unit vector, which is why we can simply multiply the values to get the points we need. We travel in one direction to get the starting points, then draw in the other direction to paint the lines of the rectangle.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 23:11
Quote: "Never liked this command, so I wrote my own."


Now I see why. I just went to use it for the first time in AppGameKit and it seems to operate different. The input values appear to have to be between -1 and 1.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 7th May 2013 23:51 Edited at: 8th May 2013 00:01
Quote: "I'll try to explain the method for ya."


Now I got it. Huge help, Phaelax. I've been googling all around to learn about trigonometry and the net is just full of it. The problem (as a beginner) is that you really don't know where to start. That's why I pushed you further for an explanation. It's so much easier and more fun to learn when you have specific task.

In my search I also found Diggseys trigonometry tutorial for beginner:
http://forum.thegamecreators.com/?m=forum_view&t=122502&b=1
Wich is very nice.

Your explanation is very easy to follow.

On another note - Have you come to a conclusion about the speed difference of the various circle methods? I think it is really strange. I put in a sync/sleep() inside both yours and basjaks filled circle (just to visualize the formulas so i could learn from them) - and basjaks sure does a huge amount of iterations and takes forever with a sleep(1) inside it.

I really don't understand why it is faster...

I never want what I know.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th May 2013 08:15
Never figured it out. This one has me stumped and I think we might need to Lee to clear this one up because it probably has something to do with the inner workings of how agk works I bet.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 13th May 2013 14:33
you know with hands on AppGameKit book there are 40 pages (follows with it) explain a variety of examples to use draw line command including creating objects wireframe.

I haven't purchased this book but I wish TGC sells us those pages separately. it's well worth it. and maybe we get more things right from there.

Login to post a reply

Server time is: 2024-11-24 15:01:48
Your offset time is: 2024-11-24 15:01:48