Page 1 of 2

Drawing functions

PostPosted: Sun Feb 11, 2007 11:49 pm
by Novice
Hi everyone, here is a .c file that I made today.
It defines four new drawing functions:
-Draw elipse
-Draw square
-Draw triangle
-Draw 5-point star
All of these shapes can be rotated (except the ellipse), resized, thickened, colored, moved.
Script editor syntax:
Code: Select all
void draw_elipse(int xe, int ye,//coordinates on canvas                 
                 short int xrad,short int yrad,//x and y radius
                 short int thicknes,//line thicknes should be 1-15
                 short int red,short int green,short int blue)//color should be 0-255

ex:

//this will draw a squashed red elipse 2 pixels thick at canvas coordinates 100,100
draw_elipse(100,100,40,20,2,255,0,0);

Code: Select all
void draw_square(int xs, int ys,//canvas coordinates
                 short int size,//size
                 short int thicknes,//1-15
                 float rotation,//0-2
                 short int red,short int green,short int blue)//0-255

ex:

//This will draw a small rotated square
draw_square(200,200,10,1,0,255,255,255);

Code: Select all
void draw_triangle(int xt, int yt,//Canvas coordinates
                   short int size,//Size
                   short int thicknes,//1-15
                   float rotation,//Rotation should be 0-2 (limit it to these values if changing
                                  //dynamicaly
                   short int red, short int green, short int blue)//color

ex:

//this will draw a medium triangle tree pixels thick and slightly rotated
draw_triangle(500,100,40,3,1,0,200,200);

Code: Select all
void draw_star(int xs, int ys,
               short int size,
               short int thicknes,
               float rotation,//0-2
               short int red, short int green, short int blue)//0-255

ex:

//This will draw a large rotated star
draw_star(400,100,50,1,1.5,0,0,255);

You should be careful not to call these functions to often as they can slow down your game.
For more info about the functions look at the c file, it is somewhat commented. I tried to optimize it as much as i could, if anyone can do better please do and post here. Shapes are not fillable because it really slows things down.

Please post your opinions and comments. Bye :wink:

PostPosted: Mon Feb 12, 2007 12:01 am
by Game A Gogo
this is cool!

PostPosted: Tue Feb 13, 2007 2:11 pm
by makslane
Great!
Moved to the Game Demos forum.

PostPosted: Tue Feb 13, 2007 7:05 pm
by Sgt. Sparky
incredible! :D :D :D

PostPosted: Wed Feb 14, 2007 2:45 am
by DilloDude
Looks great! I could think of some other additions to add to it, but Ican't try them now, as the computer I use is not set up at the moment. But I might do them later.

PostPosted: Fri Feb 16, 2007 12:58 am
by Sgt. Sparky
yeah, It would be nice if there was a square with rounded sides :D

PostPosted: Fri Feb 16, 2007 2:56 am
by DilloDude
One thing I cannot figure out, in parts with cos and sin:
Code: Select all
(xs+(size*cos(ang1*pi))
it is using ang1 * pi. The pi is to convert from degrees to radians, but ang1 is an angle from 0-2. Shouldn't it be from 0-360, or am I missing something?

PostPosted: Fri Feb 16, 2007 2:07 pm
by Novice
It has nothing to do with degrees everything is counted in radians.

PostPosted: Fri Feb 16, 2007 2:48 pm
by Sgt. Sparky
Sin and Cos use Pi, Try those :D

PostPosted: Sat Feb 17, 2007 12:24 am
by Game A Gogo
when i use sin and cos, i just multiply by the size i want it to, so you could make something like this
Code: Select all
cos(ang1)*size;

PostPosted: Sun Feb 18, 2007 11:06 pm
by DilloDude
I've started work on some more drawing functions. So far, I have
  • N-Gon: draws a regular N-sided polygon.
  • N-Star: draws an N-pointed star, with customizable inner and outer radius. (You can use a two-pointed star to make a rhombus)

When put in loops, you can make some really fancy images.
When I have made some more, I'll post the code, along with an example GED.(The image that uses the stars is too big, so you'll have to wait until I release it.)

PostPosted: Sun Feb 18, 2007 11:31 pm
by DilloDude
What I'd like to do is an elipse that can be rotated. I can think of one way, but it involes using cos and sin twice for each point. Can anyone think of a more efficient way?

PostPosted: Mon Feb 19, 2007 12:50 am
by DilloDude
I have just added another one: DrawSpiral. This draws a spiral, witha gradient colour, from inside to outside. You can specify the number of turns (positive or negative) and the radius, as well as rotation, inside colour and outside colour.

PostPosted: Mon Feb 19, 2007 12:11 pm
by DilloDude
I've made some more now, I've figured out the elipse with rotations, and I've also made a DrawCogwheel function.

PostPosted: Mon Feb 19, 2007 7:46 pm
by Sgt. Sparky
incredible! :D