Drawing functions

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

Drawing functions

Postby Novice » Sun Feb 11, 2007 11:49 pm

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:
Attachments
drawing_functions.rar
Sorry for the zip .c files are not allowed?!
For those who don't know how to include this:
1.Open your project
2.Open global code script editor
3.Click file->load and browse to this file
4.Click load
5.Give it a name and click add
6.Enjoy!
(1.33 KiB) Downloaded 1074 times
drawing-functions.png
Some basic idea what this could be used like.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Game A Gogo » Mon Feb 12, 2007 12:01 am

this is cool!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby makslane » Tue Feb 13, 2007 2:11 pm

Great!
Moved to the Game Demos forum.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Tue Feb 13, 2007 7:05 pm

incredible! :D :D :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby DilloDude » Wed Feb 14, 2007 2:45 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Sgt. Sparky » Fri Feb 16, 2007 12:58 am

yeah, It would be nice if there was a square with rounded sides :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby DilloDude » Fri Feb 16, 2007 2:56 am

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?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Novice » Fri Feb 16, 2007 2:07 pm

It has nothing to do with degrees everything is counted in radians.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Sgt. Sparky » Fri Feb 16, 2007 2:48 pm

Sin and Cos use Pi, Try those :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Game A Gogo » Sat Feb 17, 2007 12:24 am

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;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby DilloDude » Sun Feb 18, 2007 11:06 pm

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.)
Attachments
N-Gon loop tunnel.PNG
Made from a loop with N-Gons.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Sun Feb 18, 2007 11:31 pm

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?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Mon Feb 19, 2007 12:50 am

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.
Attachments
Spiral.PNG
A result of the DrawSpiral function; this one doesn't oven need a loop to look cool!
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Mon Feb 19, 2007 12:11 pm

I've made some more now, I've figured out the elipse with rotations, and I've also made a DrawCogwheel function.
Attachments
Cogwheel Loop.PNG
A loop of cogwheels
Elipses.PNG
A collection of elipses
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Sgt. Sparky » Mon Feb 19, 2007 7:46 pm

incredible! :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Next

Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron