Re: Not understanding the principles of drawing areas and primitives etc... Colors?



> Whether it is or not, it would be nice if somebody could give
me > a (c language) source snippet on how to set up colors and 
> colormaps for a widget and then draw a red line on it...

It's pretty simple, but I do not and will not willingly use 
C. Here's an example which draws lines, rectangles, circles, 
arcs, etc.. in various colors. 

use Gtk (*)
use Math (rand)

enum DRAWING_OPS 
     CLR LINES POINTS ARCS RECTS;;

app = application("Drawing for Qu")
win = window()

panel = vbox()
win.add(panel)

btnbox = hbutton_box()  btnbox.set_layout(GTK_BUTTONBOX_SPREAD)

btnbox.add([button('Clear' @draw CLR)
            button('Lines' @draw LINES)
            button('Points'@draw POINTS)
            button('Arc'   @draw ARCS)
            button('Rect'  @draw RECTS)])
       
panel.pack_end(btnbox)

canvas = drawing_area()
canvas.size(300,300)
panel.add(canvas)

win.show_all

drawing_window = canvas.window 
context = gc(drawing_window) 

app.main

sub draw(a:Int,b:Int)->Int

(x,y) = get_size(drawing_window)
fill = rand(2)
context.set_fg(rand(255),rand(255),rand(255))

switch b
  
  case CLR
     context.set_fg(rand(255),rand(255),rand(255))
     draw_rect(drawing_window,context,true,0,0,x,y)
     break
  
  case LINES 
     for i in 1..rand(10) # changes drawing color randomly;
      context.set_fg(rand(255),rand(255),rand(255))
      context.set_line_attributes(rand(10),rand(2),rand(3),rand(2))
     
draw_line(drawing_window,context,rand(x),rand(y),rand(x),rand(y))
     ;; 
     break
  
  case POINTS        
     for i in 1..rand(1000) # lots o' dots
       context.set_fg(rand(255),rand(255),rand(255))
       draw_point(drawing_window,context,rand(x),rand(y));; 
     break
  
  case ARCS 
    
draw_arc(drawing_window,context,fill==1,rand(x/2),rand(y/2),rand(x),rand(y),0,64*rand(360))
break
  
  case RECTS  
    
draw_rect(drawing_window,context,(fill==1),rand(x/2),rand(y/2),rand(x),rand(y))
break
;;
return 1
;;





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]