[cairo-commit] cairo-demo/gameoflife Makefile,1.1,1.2 gameoflife.cpp,1.1,1.2
Carl Worth
commit at pdx.freedesktop.org
Tue Nov 18 06:32:40 PST 2003
Committed by: cworth
Update of /cvs/cairo/cairo-demo/gameoflife
In directory pdx:/tmp/cvs-serv4822
Modified Files:
Makefile gameoflife.cpp
Log Message:
* gameoflife.cpp (advance): Fix casts to eliminate warnings.
(draw): Fix to use 2*M_PI (radians), not 360 (degrees).
(draw): Fix to erase entire cell.
(render): Always draw the complete grid after drawing each cell.
(main): Change window title to "Conway's Game of Life".
* Makefile (clean): Add clean target to Makefile.
Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile 17 Nov 2003 20:55:39 -0000 1.1
--- Makefile 18 Nov 2003 14:32:38 -0000 1.2
***************
*** 4,5 ****
--- 4,7 ----
g++ -g -Wall -I/usr/include/X11/Xft -I/usr/include/freetype2 -L/usr/X11R6/lib -lX11 -lXft -lcairo -o gameoflife gameoflife.cpp
+ clean:
+ rm -f gameoflife
Index: gameoflife.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/gameoflife.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** gameoflife.cpp 17 Nov 2003 20:55:39 -0000 1.1
--- gameoflife.cpp 18 Nov 2003 14:32:38 -0000 1.2
***************
*** 43,47 ****
if (color)
cairo_set_rgb_color(cr,r, g, b);
! cairo_arc(cr,x+width/2.0,y+height/2.0,radius,0,360);
cairo_fill(cr);
}
--- 43,47 ----
if (color)
cairo_set_rgb_color(cr,r, g, b);
! cairo_arc(cr,x+width/2.0,y+height/2.0,radius,0,2*M_PI);
cairo_fill(cr);
}
***************
*** 53,57 ****
} else if (future == DEAD) {
cairo_set_rgb_color(cr,LONG_MAX , LONG_MAX, LONG_MAX);
! cairo_rectangle(cr, x+1, y+1, width-2, height-2);
cairo_fill(cr);
}
--- 53,57 ----
} else if (future == DEAD) {
cairo_set_rgb_color(cr,LONG_MAX , LONG_MAX, LONG_MAX);
! cairo_rectangle(cr, x, y, width, height);
cairo_fill(cr);
}
***************
*** 171,177 ****
}
! cellR = (long) cellR -128/256. * LONG_MAX + (random() % 256) / 256. * LONG_MAX;
! cellG = (long) cellG -128/256. * LONG_MAX + (random() % 256) / 256. * LONG_MAX;
! cellB = (long) cellB - 128/256. * LONG_MAX + (random() % 256) / 256. * LONG_MAX;
if ((cellR == cellG) && (cellG == cellB) && (cellB == LONG_MAX))
--- 171,177 ----
}
! cellR = (long) (cellR -128/256. * LONG_MAX + (random() % 256) / 256. * LONG_MAX);
! cellG = (long) (cellG -128/256. * LONG_MAX + (random() % 256) / 256. * LONG_MAX);
! cellB = (long) (cellB - 128/256. * LONG_MAX + (random() % 256) / 256. * LONG_MAX);
if ((cellR == cellG) && (cellG == cellB) && (cellB == LONG_MAX))
***************
*** 205,210 ****
{
int modheight = height - 30;
!
!
if (clear)
{
--- 205,209 ----
{
int modheight = height - 30;
!
if (clear)
{
***************
*** 212,232 ****
label->render();
XFillRectangle(dpy, p, gc, 0,0,width, modheight);
!
! for (int col = 0; col <=cols; col++)
! {
! cairo_move_to(cr, col * width / cols, 0);
! cairo_rel_line_to(cr, 0, modheight);
! cairo_stroke(cr);
! }
! for (int row = 0; row <= rows; row++)
! {
! cairo_move_to(cr, 0, row * modheight / rows);
! cairo_rel_line_to(cr,width, 0);
! cairo_stroke(cr);
! }
! }
for (int col = 0; col < cols; ++col)
for (int row = 0; row < rows; ++row)
cell[row*cols + col].draw(cr,col * width/cols, row * modheight / rows, width / cols, modheight / rows, clear, color);
XCopyArea(dpy, p, d, gc, 0, 0, width, modheight, x,30);
return 0;
--- 211,233 ----
label->render();
XFillRectangle(dpy, p, gc, 0,0,width, modheight);
! }
!
for (int col = 0; col < cols; ++col)
for (int row = 0; row < rows; ++row)
cell[row*cols + col].draw(cr,col * width/cols, row * modheight / rows, width / cols, modheight / rows, clear, color);
+
+ for (int col = 0; col <=cols; col++)
+ {
+ cairo_move_to(cr, col * width / cols, 0);
+ cairo_rel_line_to(cr, 0, modheight);
+ cairo_stroke(cr);
+ }
+ for (int row = 0; row <= rows; row++)
+ {
+ cairo_move_to(cr, 0, row * modheight / rows);
+ cairo_rel_line_to(cr,width, 0);
+ cairo_stroke(cr);
+ }
+
XCopyArea(dpy, p, d, gc, 0, 0, width, modheight, x,30);
return 0;
***************
*** 316,320 ****
/*XStoreName - Chapter 14 'ICCCM', Xlib Manual *
* sets the name for Title, etc. */
! XStoreName(dpy, w, "Goodbye Cruel World");
/* Complicated procedure to add a close button on the WM decors */
decorateWindow(dpy,w);
--- 317,321 ----
/*XStoreName - Chapter 14 'ICCCM', Xlib Manual *
* sets the name for Title, etc. */
! XStoreName(dpy, w, "Conway's Game of Life");
/* Complicated procedure to add a close button on the WM decors */
decorateWindow(dpy,w);
More information about the cairo-commit
mailing list