Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tutorial] Simple Draw Commands (Pixel Graphics)
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Asok




PostPosted: Fri Mar 14, 2003 2:00 am   Post subject: [Tutorial] Simple Draw Commands (Pixel Graphics)

For those of you who want to make graphic output in turing without importing images (for that tutorial go here: http://www.compsci.ca/bbs/viewtopic.php?t=191 ), here's a short tutorial to show you the basics. NOTE: All commands are case sensitive so you must do them as shown.

First off, the turing screen is measured in pixels from (0,0) in the bottom left corner to (maxx,maxy) in the top right corner where maxx and maxy equal to whatever the window resolution is at such as 640x480. Anyways, the x-axis measures from left to right (horizontally) the y-axis measures from bottom to top (vertically).

In order to pin point a specific pixel on the screen you would use the Draw.Dot command. In the following x and y would be equal to the coordinates, colour is equal to the colour of the dot. If you do not see the dot it is because either your coordinates are actually beyond the viewable field, or your colour is equal to the colour of the background.
code:
Draw.Dot (x,y,colour)


In order to draw a line from point A to point B on the screen you would need to use the Draw.Line command. In the following x1 and y1 would be equal to the coordinates of point A, and x2 and y2 would be equal to the coordinates of point B, colour is equal to the colour of the line.
code:
Draw.Line (x1,y1,x2,y2,colour)


Drawing a rectangle/box is fairly simple to understand, it uses the Draw.Box command. The Draw.Box command works very similarly to the Draw.Line command, point A is the bottom left corner of the box, point B is the top right corner. The same variables apply.
code:
Draw.Box (x1,y1,x2,y2,colour)


Drawing a star is the same concept as the box however instead of a box, a star will be in the area you define for it. This uses the Draw.Star command. Imagine an invisible box as the space that the star will be drawn in.
code:
Draw.Star (x1,y1,x2,y2,colour)


Being the canadians that we are, turing also has a built in Maple Leaf that works exactly like the star. This uses the Draw.MapleLeaf command. Take note of the capital L because it will not recognise it if it is lowercase.
code:
Draw.MapleLeaf (x1,y1,x2,y2,colour)


Drawing an oval/circle is different in concept. It uses the Draw.Oval command. The following has a few variables in the parameter, x and y are the coordinates for the center of the circle. xr and yr are for the radius of the oval on the x-axis and the radius of the oval on the y-axis. NOTE: If you want a perfect circle xr and yr need to have the same value. colour is the colour of the oval.
code:
Draw.Oval (x,y,xr,yr, colour)


Now you will notice that all the commands previously only showed an outline of the image. There are two ways to fill an image the first way is the simple way. Each command for objects has a command with a Fill prefex to it with the same set of parameters and variables. These commands include:
  • Draw.FillBox
  • Draw.FillStar
  • Draw.FillMapleLeaf
  • Draw.FillOval

The other method uses the Draw.Fill command, this is useful if you have created a geometric image (ie. a Triangle from connecting 3 lines). The variables x and y are the coordinates of anywhere inside the object, fillcolour is the colour of the fill, bordercolour is the colour of the border of the object. NOTE: It is not drawing the border, it is stopping at it when it hits this colour to avoid filling outside of the border. You can have a different colour fill than the colour of the outline of the object. The Draw.Fill command fills the enclosed area surrounding the given pixel, if your object is not properly enclosed the fill will leak on to the rest of the image.
code:
Draw.Fill (x,y,fillcolour, bordercolour)

An example of the correct usage is here:
code:
Draw.Line (20,20,80,20,black)
Draw.Line (80,20,50,60,black)
Draw.Line (50,60,20,20,black)
Draw.Fill (30,30,green,black)

The Output is a green triangle with a black outline.

This pretty much covers all the basics. Enjoy! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Mar 14, 2003 2:35 am   Post subject: (No subject)

hey Asok, can you do me a favour and when you get back to school, ask Shannon if she still has my animation project from grade 10? Its a really cool example of how to draw stuff in turing...

actually ask if you can upload a bunch of those. Then we can host our own turing animation contest Very Happy
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Asok




PostPosted: Fri Mar 14, 2003 11:05 am   Post subject: (No subject)

I would think the other way on that idea, it's too open for playgerism, all the animations would need to be in .exe format.
Tony




PostPosted: Fri Mar 14, 2003 12:00 pm   Post subject: (No subject)

umm... ya... submited animations would have to be an exe with their usename and stuff attached. I'd still have to think up the requirements. Well talk after march break when everyone comes back Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mysterymaker




PostPosted: Mon Oct 12, 2009 1:10 pm   Post subject: RE:[Tutorial] Simple Draw Commands (Pixel Graphics)

how do u draw a crumpled hat and, a bat and a pumpkin?
Insectoid




PostPosted: Wed Oct 14, 2009 9:00 am   Post subject: RE:[Tutorial] Simple Draw Commands (Pixel Graphics)

First of all, this is necroing.

What is a drawing of a crumpled hat or bat but a collection of lines and arcs?
landfarm




PostPosted: Tue Nov 10, 2009 6:32 pm   Post subject: RE:[Tutorial] Simple Draw Commands (Pixel Graphics)

Is it possible to include drawing round objects in this tutorial as well? This is because I saw something like : Draw.ThickLine (round, xc,)..... etc, etc. Just wondering if it would make the tutorial even better
iii




PostPosted: Sun Jan 10, 2010 8:07 pm   Post subject: Re: [Tutorial] Simple Draw Commands (Pixel Graphics)

What about arcs?
Zren




PostPosted: Mon Jan 11, 2010 1:21 am   Post subject: Re: [Tutorial] Simple Draw Commands (Pixel Graphics)

iii @ Sun Jan 10, 2010 8:07 pm wrote:
What about arcs?

http://compsci.ca/holtsoft/doc/draw_arc.html

And for anything else (Polygons, Dashed Lines, Thick Lines):
http://compsci.ca/holtsoft/doc/drawmodule.html
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: