From mboxrd@z Thu Jan 1 00:00:00 1970 Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <472B7691.4010807@kix.in> References: <02597431-3833-4DDD-8720-E0B2761DBE88@mac.com> <472B7691.4010807@kix.in> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Pietro Gagliardi Subject: Re: [9fans] Suggestion: Programming Tutorial for /sys/doc Date: Fri, 2 Nov 2007 15:44:49 -0400 To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Topicbox-Message-UUID: e736c2c6-ead2-11e9-9d60-3106f5b1d025 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 #include #include #include /* 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. >