9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Pietro Gagliardi <pietro10@mac.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] Suggestion: Programming Tutorial for /sys/doc
Date: Fri,  2 Nov 2007 15:44:49 -0400	[thread overview]
Message-ID: <DC2B1E62-D5FC-451B-9BA2-8259381AE92C@mac.com> (raw)
In-Reply-To: <472B7691.4010807@kix.in>

Here's a little bit of (heavily) commented code that simply sets up  
the screen and draws a line. This should be more than enough to get  
you started (it's almost how I started).

	/* necessary headers */
	#include <u.h>
	#include <libc.h>
	#include <draw.h>
	#include <cursor.h>

	/* main routine */
	void main(int argc, char *argv[])
	{
		int c;
		void draw_line(void);

		/* int initdraw(err_func, default_font, program_name)
			If err_func is 0, use default
			If default_font is 0, use default */
		if (initdraw(0, 0, "program name") < 0)
			sysfatal("could not initialize graphics");
		draw_line();
		for (;;) /* not the best way to wait for a key hit
				I don't want to go into events here */
			if (read(0, &c, 1) == 1)
				break;
		exits(0); /* graphics is automatically terminated */
	}

So here's how you draw a line:

	void draw_line(void)
	{
		/* this is how to create a color - see allocimage(2) for a complete  
list */
		Image *black_color = allocimage(display, Rect(0, 0, 1, 1),
			RGB24, 1, DBlack);
		Point a = Pt(3, 2), b = Pt(400, 900);

		/* line(destination, from, to, from_end_type, to_end_type, thickness,
			source_color, point_to_use);
				To get the thickness of the line, use the equation
					1 + (2 * thickness)
				In this case, the thickness is 1.
				Other choices for end types are Enddisc and Endarrow.
				Plan 9 is more powerful than this, however. You can take any
				color from any image or create more elaborate arrows with
				ARROW() as the type parameter. You can even mix and match
				types. But this is more advanced. Refer to draw(2).
		*/
		line(screen, a, Endsquare, Endsquare, 0,
			black_color, Pt(0, 0));
	}

Just stick that in the code section.

On Nov 2, 2007, at 3:12 PM, Anant Narayanan wrote:

> Pietro Gagliardi wrote:
>> cover in a clear way, so I think a tutorial should be put in. I  
>> already
>> started writing one, and I think it would benefit from being in
>>     - graphics and controls
>
> While I am mostly able understand the other concepts you mention from
> existing documentation, I find graphics (libdraw) to be somewhat
> cryptic. I've always felt the need for a tutorial-style  
> introduction on
> how to do graphics in Plan 9.
>
> The current solution seems to be mostly be: "Read the code". Which  
> isn't
> really as good.
>


      reply	other threads:[~2007-11-02 19:44 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-01 20:11 Pietro Gagliardi
2007-11-01 20:23 ` don bailey
2007-11-01 20:47 ` Anthony Sorace
2007-11-01 21:00   ` Pietro Gagliardi
2007-11-01 21:22     ` Federico Benavento
2007-11-02 13:10       ` Iruata Souza
2007-11-02 13:34         ` David Leimbach
2007-11-02 13:39           ` erik quanstrom
2007-11-02 16:44             ` geoff
2007-11-02 18:00               ` erik quanstrom
2007-11-02 19:34                 ` geoff
2007-11-02 20:57                   ` David Leimbach
2007-11-03  2:44                 ` Gorka Guardiola
2007-11-03  8:49                   ` Sander van Dijk
2007-11-03 15:24                     ` Eldanen
2007-11-03 21:43                       ` erik quanstrom
2007-11-03 23:40                         ` Eldanen
2007-11-06 14:39                         ` [9fans] Font Michaelian Ennis
2007-11-06 14:46                           ` Anant Narayanan
2007-11-06 14:50                             ` erik quanstrom
2007-11-07 18:12                               ` Michaelian Ennis
2007-11-06 14:56                           ` Martin Neubauer
2007-11-05 11:59                     ` [9fans] Suggestion: Programming Tutorial for /sys/doc Gorka Guardiola
2007-11-02 18:09             ` David Leimbach
2007-11-02 18:47         ` Pietro Gagliardi
2007-11-02 20:11           ` Iruata Souza
2007-11-02 18:52         ` Pietro Gagliardi
2007-11-01 21:27     ` Uriel
2007-11-02  1:44     ` Anthony Sorace
2007-11-02  7:53       ` Uriel
2007-11-01 21:24 ` ISHWAR RATTAN
2007-11-02  3:07 ` Joel C. Salomon
2007-11-02  8:19 ` fernanbolando
2007-11-02 10:03   ` roger peppe
2007-11-02 13:07     ` Eric Van Hensbergen
2007-11-02 12:42   ` erik quanstrom
2007-11-02 15:39 ` Douglas A. Gwyn
2007-11-02 19:12 ` Anant Narayanan
2007-11-02 19:44   ` Pietro Gagliardi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DC2B1E62-D5FC-451B-9BA2-8259381AE92C@mac.com \
    --to=pietro10@mac.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).