|
Post by alexfish on Apr 12, 2023 21:47:57 GMT 1
Hi All
More or less done , and for the Now. as regards hug GTK3 originaly by Joe version hug GTK3.5 patched by the me from the GTK3 and remains as patched ... possible more on that one later after testing and by name the Author remains the Author, I hope
Hence as of the now ,there is No DEFAULT canvas in the GTK3.5
As to part of the why, GTK2 GTK2 has a default canvas , and from my side have enter Cairo bits in the ORIGINAL MY copy of hug.bac for ease of use, by name HUG , and no need for -DEVS
Updated :: neither lib has HUGLIB$ call to Pixbuf IE: for gtk
MYGTK$ = HUGLIB$("gtk")
and to the SO
INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO")
cairo patch hug gtk2 follows later 2.5 and the name space =
INCLUDE "hug25.bac" HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO")
and by name space most of the hug image lib bits will be in 3.5 and 2.5 the original imager includes will be greatly reduced
seen by
ELIF HUG_CANVAS_TYPE =3 THEN once in the cairo will be available for GL quote from cairo docs
+ tk and fltk can use cairo BR Alex
|
|
|
Post by alexfish on Apr 12, 2023 22:41:41 GMT 1
and to the file when Released
demo code to test that Doughnut INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME")
SUB MYCIRCLE(STRING hug_color$, int hug_x, int hug_y, int hug_xsize, int hug_ysize, NUMBER hug_fill,rot) pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix))
LOCAL surface,cr surface = hug_widget_surface( STR$(pix)) cr = cairo_create (surface)
IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF cairo_set_line_width (cr,0.005) cairo_translate (cr, hug_x, hug_y) cairo_rotate(cr,rot) cairo_scale (cr,hug_xsize/2,hug_ysize/2) cairo_arc (cr, 0, 0, 1.0, 0.0, 2.0 * M_PI)
IF hug_fill THEN cairo_fill(cr) ELSE cairo_stroke(cr) END IF
cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) )
END SUB
win = WINDOW("Elipse",1000,800) can = CANVAS(1000,800) ATTACH(win,can,0,0) SQUARE("000000",0,0,1000,800,1) FOR t = 0 TO 350 STEP 2 MYCIRCLE("#FFFF00",1000/2,800/2,500,200,0,t) NEXT DISPLAY
Animated with white = Alex's BigBang Theory 'Some Doughnut' had to clip this picky down BR Alex Attachments:
|
|
|
Post by alexfish on Apr 13, 2023 12:28:44 GMT 1
Furth Resource Samples Cairo.org HERE
|
|
|
Post by alexfish on Apr 14, 2023 2:42:39 GMT 1
Need to find which gtk3 version installed
apt-cache policy libgtk-3-0 | grep Installed
hug3.5 NEEDS >= 3.10
BR Alex
|
|
|
Post by alexfish on Apr 15, 2023 16:42:37 GMT 1
HUG3.5 NEW LIB AT POST #1 Added For historical purposes ' My Pet Hate' a real hate of GTK3 read about here HEREHave Fun + BR Alex
|
|
|
Post by alexfish on Apr 16, 2023 8:26:15 GMT 1
Found another hick
using INIT within code
so for now do not use INIT
Peters 15 Puzzle
INCLUDE "hug35.bac" HUGOPTIONS("CANVASCAIRO") HUGOPTIONS("NOSCALING") DECLARE Situation[6][6] DECLARE Move
'---------------------------------------------------------------------------------------------
SUB Randomize_Board
LOCAL i, x, y
' Initialize situation FOR y = 0 TO 5 FOR x = 0 TO 5 IF x = 0 OR x = 5 OR y = 0 OR y = 5 THEN Situation[x][y] = -1 ELSE Situation[x][y] = x+(y-1)*4 END IF NEXT NEXT Situation[4][4] = 0
' Start randomization FOR i = 1 TO 200
' Find the empty space FOR y = 1 TO 4 FOR x = 1 TO 4 IF Situation[x][y] = 0 THEN BREAK 2 NEXT NEXT
' Decide which direction to swap SELECT RANDOM(4) CASE 0 IF Situation[x][y-1] = -1 THEN CONTINUE Situation[x][y] = Situation[x][y-1] Situation[x][y-1] = 0 CASE 1 IF Situation[x+1][y] = -1 THEN CONTINUE Situation[x][y] = Situation[x+1][y] Situation[x+1][y] = 0 CASE 2 IF Situation[x][y+1] = -1 THEN CONTINUE Situation[x][y] = Situation[x][y+1] Situation[x][y+1] = 0 CASE 3 IF Situation[x-1][y] = -1 THEN CONTINUE Situation[x][y] = Situation[x-1][y] Situation[x-1][y] = 0 END SELECT NEXT
END SUB
'---------------------------------------------------------------------------------------------
SUB Draw_Board
LOCAL x, y
FOR y = 1 TO 4 FOR x = 1 TO 4 IF Situation[x][y] = 0 THEN SQUARE("#FFFFFF", (x-1)*70, (y-1)*70, 70, 70, 1) ELSE SQUARE("#8080FF", (x-1)*60+(x-1)*10+5, (y-1)*60+(y-1)*10+5, 60, 60, 1) SQUARE("#0000FF", (x-1)*60+(x-1)*10, (y-1)*60+(y-1)*10, 60, 60, 1) SQUARE("#000000", (x-1)*60+(x-1)*10, (y-1)*60+(y-1)*10, 60, 60, 0) OUT(STR$(Situation[x][y]), "#FFFF00", "#0000FF", (x-1)*65+(x-1)*5+24, (y-1)*65+(y-1)*5+24) END IF NEXT NEXT
END SUB
'---------------------------------------------------------------------------------------------
SUB Clicked
LOCAL x, y, xpos, ypos, solved
xpos = MOUSE(0) ypos = MOUSE(1)
IF xpos > 0 AND xpos < 70 THEN x = 1 IF xpos > 70 AND xpos < 140 THEN x = 2 IF xpos > 140 AND xpos < 210 THEN x = 3 IF xpos > 210 AND xpos < 280 THEN x = 4
IF ypos > 0 AND ypos < 70 THEN y = 1 IF ypos > 70 AND ypos < 140 THEN y = 2 IF ypos > 140 AND ypos < 210 THEN y = 3 IF ypos > 210 AND ypos < 280 THEN y = 4
' Check validity of move IF Situation[x][y] != 0 THEN IF Situation[x][y-1] = 0 THEN Situation[x][y-1] = Situation[x][y] Situation[x][y] = 0 INCR Move END IF IF Situation[x+1][y] = 0 THEN Situation[x+1][y] = Situation[x][y] Situation[x][y] = 0 INCR Move END IF IF Situation[x][y+1] = 0 THEN Situation[x][y+1] = Situation[x][y] Situation[x][y] = 0 INCR Move END IF IF Situation[x-1][y] = 0 THEN Situation[x-1][y] = Situation[x][y] Situation[x][y] = 0 INCR Move END IF Draw_Board END IF
' Check game end FOR y = 1 TO 4 FOR x = 1 TO 4 IF Situation[x][y] = x+(y-1)*4 THEN INCR solved NEXT NEXT
IF solved = 15 THEN TEXT(enddlg, "Well done, solved in " & STR$(Move) & " moves!") SHOW(enddlg) END IF
END SUB
'---------------------------------------------------------------------------------------------
SUB Handle_Answer(NUMBER dialog, int button)
HIDE(dialog)
IF button = GTK_RESPONSE_YES THEN Randomize_Board Draw_Board Move = 0 END IF
END SUB
'---------------------------------------------------------------------------------------------
SUB Show_Question
SHOW(infdlg)
END SUB
'---------------------------------------------------------------------------------------------
window = WINDOW("The Fifteen-puzzle", 300, 350) frame = FRAME(290, 290) ATTACH(window, frame, 5, 5) PROPERTY(window, "icon-name", "gtk-about")
canvas = CANVAS(280, 280) ATTACH(window, canvas, 10, 10) CALLBACK(canvas, Clicked)
exitbutton = STOCK("gtk-quit", 90, 40) ATTACH(window, exitbutton, 205, 305) CALLBACK(exitbutton, QUIT)
newbutton = STOCK("gtk-new", 90, 40) ATTACH(window, newbutton, 5, 305) CALLBACK(newbutton, Show_Question)
txt = MARK("Created with\n BaCon!", 90, 40) ATTACH(window, txt, 100, 305)
infdlg = MSGDIALOG("Create another game?", 300, 130, 2, 4) CALLBACK(infdlg, Handle_Answer)
enddlg = MSGDIALOG("Well done!", 300, 100, 0, 2) CALLBACK(enddlg, HIDE)
Randomize_Board Draw_Board
FOCUS(exitbutton) DISPLAY
|
|
|
Post by alexfish on Apr 16, 2023 8:35:53 GMT 1
Well
think that method may Be Here for good I think says He
bit of trade off for compatibility on different BaCon version's
Reason :: tested one version of bacon 4. series and standard hug.bac A call to the HUGLIB & get an ERROR lib not found
the exec size here for the fifteen puzzel is only '337.8 KiB '
ADDED can Peter's fractal program as a speed test , but pixel by pixel
using need header then test against hug.bac
REM --------------------------------------------------------------------------------------------------
INCLUDE "hug.bac" HUGOPTIONS("NOSCALING") REM --------------------------------------------------------------------------------------------------
REM REM H.U.G. test program - PvE August 2009, GPL. REM REM --------------------------------------------------------------------------------------------------
INCLUDE "hug35.bac" HUGOPTIONS("CANVASGCAIRO") HUGOPTIONS("NOSCALING") REM --------------------------------------------------------------------------------------------------
CONST MaxIters = 100 CONST xSize = 480 CONST ySize = 330 CONST Black = -1 CONST Left = -2.0 CONST Right = 1.0 CONST Top = 1.0 CONST Bottom = -1.0 '.732 '1.246 SUB Draw_Fractal ts = TIMER 'SQUARE("#FF00006F",100,100,200,200,1) LOCAL x, y, count TYPE short LOCAL zr, zi, cr, ci TYPE long double LOCAL rsquared, isquared TYPE long double
DISABLE(start_but) DISABLE(clear_but)
REM Information to user OUT("Please wait...", "#0000FF", "#FFFFFF", 10, 300) SYNC FOR y = 0 TO ySize FOR x = 0 TO xSize zr = 0.0 zi = 0.0 cr = Left + x * (Right - Left) / xSize
ci = Top + y * (Bottom - Top) / ySize rsquared = zr * zr isquared = zi * zi
FOR count = 0 TO MaxIters zi = zr * zi * 2 zi = zi + ci
zr = rsquared - isquared zr = zr + cr
rsquared = zr * zr isquared = zi * zi NEXT IF rsquared + isquared <= 4.0 THEN PIXEL(PixelCol$[ROUND((rsquared + isquared)*4)], x, y) SYNC END IF NEXT
NEXT st = TIMER PRINT st -ts SQUARE ("#FFFFFF", 10, 300, 150, 20, TRUE) OUT("Drawing ready.", "#FF00FF", "#FFFFFF", 10, 300) ENABLE(clear_but) ENABLE(start_but)
END SUB
REM --------------------------------------------------------------------------------------------------
SUB Clear_Fractal
SQUARE ("#FFFFFF", 0, 0, 480, 330, TRUE)
END SUB
REM --------------------------------------------------------------------------------------------------
SUB Quit_Prog
QUIT
END SUB
REM --------------------------------------------------------------------------------------------------
REM Get some colors GLOBAL PixelCol$[17] TYPE STRING
FOR i = 0 TO 16 READ PixelCol$[i] NEXT
DATA "#800000", "#800080", "#8000FF", "#808000", "#808080", "#8080FF", "#80FF00", "#80FF80", \ "#80FFFF", "#FF0000", "#FF0080", "#FF00FF", "#FF8000", "#FF8080", "#FF80FF", "#FFFF00", "#000000"
REM Create the GUI mainwin = WINDOW("Drawing a fractal", 500, 400)
frame = FRAME(490, 340) ATTACH (mainwin, frame, 5, 5) canvas = CANVAS(480, 330) ATTACH (mainwin, canvas, 10, 10)
start_but = STOCK("gtk-execute", 100, 40) ATTACH(mainwin, start_but, 5, 355) CALLBACK (start_but, Draw_Fractal)
clear_but = STOCK("gtk-clear", 100, 40) ATTACH(mainwin, clear_but, 120, 355) CALLBACK (clear_but, Clear_Fractal)
labl = MARK("H.U.G. for BaCon!", 120, 40) ATTACH(mainwin, labl, 240, 355)
quit_but = STOCK("gtk-quit", 100, 40) ATTACH(mainwin, quit_but, 395, 355) CALLBACK (quit_but, Quit_Prog) 'SQUARE ("#FFFFFF", 0, 0, 480, 330, TRUE) DISPLAY
Have Fun + Alex
|
|
|
Post by alexfish on Apr 16, 2023 18:52:58 GMT 1
This Demo RountRect is from libx11 thread using cairo t for how to do colours are posted + read the include hug35 file Also Demo IMPORT function RRECT , possible better than 2 demos on cairo.org Note The Placement + test rotation if want it will be a tough call, but here are the values of multiplier on the PI : note them since this demo does the negative * positive arcs Also if have checked the svg demo Square Peg in a round Hole change the rx=10.0 ry=10.0 with rx=width/2 ry=height/2 = ellipse cheat sheet + try stroke instead of fill INCLUDE "hug35.bac"
HUGOPTIONS("CANVASCAIRO") HUGOPTIONS("NOSCALING")
'========================================================== cairo$= HUGLIB$("cairo") IMPORT "cairo_new_sub_path(long)" FROM cairo$ TYPE void '==========================================================
SUB RRECT(double x ,double y,double width , double height) LOCAL pix, ebox, context
' Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) LOCAL surface,cr
surface = hug_widget_surface( STR$(pix))
'LOCAL *cr TYPE cairo_new_path LOCAL rx,ry TYPE double rx=10.0 ry=10.0
c=cairo_create(surface) cairo_new_path(c) /* Draw the top-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 1.5 * PI, 2.0 * PI) cairo_restore (c) cairo_line_to (c, x + width,y + height - ry) /* Draw the bottom-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.0, 0.5 * PI) cairo_restore (c) /* Draw the line left across the bottom. */ cairo_line_to (c, x + rx, y + height) /* Draw the bottom-left arc. */ cairo_save (c) cairo_translate (c,x + rx,y +height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.5 * PI, PI) cairo_restore (c) /* Draw the line up the left side. */ cairo_line_to (c,x, y + ry) /* Draw the top-left arc. */ cairo_save (c) cairo_translate (c,x + rx, y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, PI, 1.5 * PI) cairo_restore (c) cairo_close_path (c) cairo_set_source_rgb(c,0.705, 0.196, 0.18) cairo_fill(c) /* a custom shape that could be wrapped in a function */ /* parameters like cairo_rectangle */
cairo_destroy(c) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) END SUB
win = WINDOW("R-RECT",600,600) can = CANVAS(600,600) ATTACH(win,can,0,0) RRECT(50,50,200,200) DISPLAY
Have Fun + BR Alex Picky using stroke and RRect RRECT(50,50,200,300) So setting rx ry to 0 = SQUARE : test dims to get a line : api = line,square,rectangle, roundrect, circle & ellipse from one function + in base API have line width CAIRO_LINE_WIDTH (double) CAIRO_LINE_WIDTH = 0.5 CAIRO_LINE_WIDTH = 2.5 Attachments:
|
|
|
Post by alexfish on Apr 16, 2023 21:37:45 GMT 1
same theme but check the arc INCLUDE "hug35.bac"
HUGOPTIONS("CANVASCAIRO") HUGOPTIONS("NOSCALING")
SUB RRECT2(double x ,double y,double width , double height) LOCAL pix, ebox, context
' Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) LOCAL surface,c
surface = hug_widget_surface( STR$(pix))
'LOCAL *cr TYPE cairo_new_path LOCAL rx,ry TYPE double rx=width/2 ry=height/2 /* void cairo_arc (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2); */ c=cairo_create(surface) cairo_new_path(c) /* Draw the top-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 1.5 * PI, 2.0 * PI) cairo_restore (c) cairo_line_to (c, x + width,y + height - ry) /* Draw the bottom-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 0.0, 0.0, 0.5 * PI) cairo_restore (c) /* Draw the line left across the bottom. */ cairo_line_to (c, x + rx, y + height) /* Draw the bottom-left arc. */ cairo_save (c) cairo_translate (c,x + rx,y +height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 0.0, 0.5 * PI, PI) cairo_restore (c) /* Draw the line up the left side. */ cairo_line_to (c,x, y + ry) /* Draw the top-left arc. */ cairo_save (c) cairo_translate (c,x + rx, y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, PI, 1.5 * PI) cairo_restore (c) cairo_close_path (c) cairo_set_source_rgb(c,0.705, 0.196, 0.18) cairo_stroke(c)
/* a custom shape that could be wrapped in a function */ /* parameters like cairo_rectangle */
cairo_destroy(c) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) END SUB
win = WINDOW("R-RECT",600,600) can = CANVAS(600,600) ATTACH(win,can,0,0) FOR t = 1 TO 600 STEP 600/20 RRECT2(t,50,50,70) NEXT DISPLAY saving the bits : under this scheme we are cairo surface :: other bits about using pixbuf are noted in previous posts but to highlight some bits data = cairo_image_surface_get_data (cs) buf = gdk_pixbuf_new_from_data(data, 0,TRUE,8,cairo_image_surface_get_width(cs),cairo_image_surface_get_height(cs) ,cairo_image_surface_get_stride (cs),0,0)
and can manipulate the bits as in the previous posts hence can use pix buf save or after manipulating ,or find out what bits is in a particular pixel has (rgba) wise use image set from pixbuf and see the results in the canvas so saving example SUB Save_Image() LOCAL pix
' Get the associated canvas pix = hug_gui_properties.canvas LOCAL surface surface = hug_widget_surface( STR$(pix)) cairo_surface_write_to_png(surface,"/path/to/file") END SUB And as a final Wrap if test all the canvas types with fractal demo per pixel : this canvas is quicker by a fair margin + try doing the R-Rect demos and yes including the gl ones in the other canvases Attachments:
|
|
|
Post by alexfish on Apr 17, 2023 10:31:49 GMT 1
Q :: how to embed cairo surface in the cairo canvas
A :: look at PICTURE in the lib has
gdk_cairo_set_source_pixbuf
instance of surface
cairo_set_source_surface
cairo_set_source_surface(cr, surface, x, y) Arguments cr [cairo_t *] a cairo context
surface [cairo_surface_t *] a surface to be used to set the source pattern
x [double] User-space X coordinate for surface origin
y [double] User-space Y coordinate for surface origin
|
|
|
Post by alexfish on Apr 17, 2023 12:49:35 GMT 1
To Get Started with translate rotate INCLUDE "hug35.bac"
HUGOPTIONS("CANVASCAIRO") HUGOPTIONS("NOSCALING")
SUB LINER (STRING hug_color$, int cx, int cy, int width,double rot )
LOCAL pix, context, ebox
REM Get the associated canvas pix = hug_gui_properties.canvas
ebox = hug_widget_ebox(STR$(pix))
LOCAL surface surface = hug_widget_surface( STR$(pix))
LOCAL cr
cr = cairo_create (surface) IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF cairo_set_line_width (cr,1) cairo_translate (cr,cx,cy) cairo_rotate(cr,rot) cairo_move_to (cr,0,0) cairo_line_to(cr,-width/2,0) cairo_move_to (cr,0,0) cairo_line_to(cr,width/2,0) cairo_stroke(cr)
cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) )
END SUB SUB Save_Image() LOCAL pix
' Get the associated canvas pix = hug_gui_properties.canvas LOCAL surface surface = hug_widget_surface( STR$(pix)) cairo_surface_write_to_png(surface,"/home/pi/all.png") END SUB LOCAL t TYPE double win = WINDOW("R-RECT",600,600) can = CANVAS(600,600) ATTACH(win,can,0,0) FOR t = 0 TO 360 STEP 10 'LINER("#FF0000",400,300,300,t) NEXT
FOR t = 0 TO 360 STEP 2 LINER("#FF0000",300,300,300,RAD(t)) NEXT LINE("#000000",50,50,300,50) Save_Image
DISPLAY
Attachments:
|
|
|
Post by alexfish on Apr 17, 2023 20:11:11 GMT 1
now we Know how the translate/rotate does
the same func with single draw of line and bits that form a box
INCLUDE "hug35.bac" HOME$ = GETENVIRON$("HOME") HUGOPTIONS("CANVASCAIRO") HUGOPTIONS("NOSCALING")
SUB LINER (STRING hug_color$, int cx, int cy, int width,double rot )
LOCAL pix, context, ebox
REM Get the associated canvas pix = hug_gui_properties.canvas
ebox = hug_widget_ebox(STR$(pix))
LOCAL surface surface = hug_widget_surface( STR$(pix))
LOCAL cr
cr = cairo_create (surface) IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF cairo_set_line_width (cr,1) cairo_translate (cr,cx,cy) cairo_rotate(cr,rot)
cairo_move_to (cr,0,0) cairo_line_to(cr,width/2,0) cairo_stroke(cr)
cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) )
END SUB
SUB Save_Image() LOCAL pix
' Get the associated canvas pix = hug_gui_properties.canvas LOCAL surface surface = hug_widget_surface( STR$(pix)) cairo_surface_write_to_png(surface,HOME$ & "/box.png") END SUB
LOCAL t TYPE double win = WINDOW("R-RECT",600,600) can = CANVAS(600,600) ATTACH(win,can,0,0)
LINER("#FF0000",300,300,-100,RAD(0)) LINER("#FF00FF",300,300,100,RAD(90)) LINER("#FFFF00",300,350,-100,RAD(0)) LINER("#000000",250,300,-100,RAD(-90))
Save_Image
DISPLAY
Play around with the bits doe rotation first to find your feet the first to bit are CX & CY and result of draw = 50% of width to get the total width need a - and a +
LINER("#FF0000",CX,CY,-100,RAD(0))
Next rotation around CX/CY
|
|
|
Post by alexfish on Apr 17, 2023 21:23:57 GMT 1
Now Flying INCLUDE "hug35.bac" HOME$ = GETENVIRON$("HOME") HUGOPTIONS("CANVASCAIRO") HUGOPTIONS("NOSCALING")
SUB RLINER (STRING hug_color$, int cx, int cy, int width,int hugx,int hugy,double rot )
LOCAL pix, context, ebox
REM Get the associated canvas pix = hug_gui_properties.canvas
ebox = hug_widget_ebox(STR$(pix))
LOCAL surface surface = hug_widget_surface( STR$(pix))
LOCAL cr
cr = cairo_create (surface) IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF cairo_set_line_width (cr,1)
cairo_translate (cr,cx,cy) cairo_rotate(cr,rot) cairo_move_to (cr,hugx,hugy) cairo_line_to(cr,width,0) cairo_stroke(cr)
cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) )
END SUB SUB Save_Image() LOCAL pix
' Get the associated canvas pix = hug_gui_properties.canvas LOCAL surface surface = hug_widget_surface( STR$(pix)) cairo_surface_write_to_png(surface,HOME$ & "/box.png")
END SUB
LOCAL t TYPE double win = WINDOW("R-RECT",600,600) can = CANVAS(600,600) ATTACH(win,can,0,0) FOR t = 0 TO 360 STEP 10 'LINER("#FF0000",400,300,300,t) NEXT
RLINER("#FF0000",300,300,100,0,100,RAD(0)) RLINER("#FF00FF",300,300,100,0,100,RAD(90)) RLINER("#FF0000",300,300,100,0,100,RAD(180)) RLINER("#FF00FF",300,300,100,0,100,RAD(270))
Save_Image
DISPLAY Attachments:
|
|
|
Post by alexfish on Apr 17, 2023 21:55:32 GMT 1
Using the above Make a Wheel wit Tyre 'Wheel FOR t = 0 TO 360 STEP 20 RLINER("#FF0000",300,300,100,0,100,RAD(0+t)) RLINER("#FF00FF",300,300,100,0,0,RAD(90+t)) NEXT and 'Wheel FOR t = 0 TO 359 RLINER("#FF00FF",300,300,200,0,0,RAD(0+t)) RLINER("#FF00FF",300,300,100,0,100,RAD(0+t)) RLINER("#FF00FF",300,300,100,0,0,RAD(90+t)) NEXT 2 wheels = * tip of the daythe code said copy write : so I copied it and write it Attachments:
|
|
|
Post by alexfish on Apr 18, 2023 7:47:35 GMT 1
and Finally
INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME")
SUB SQUARE2 (long cr, STRING hug_color$, int hug_x, int hug_y, int hug_xsize, int hug_ysize, int hug_fill)
IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF
cairo_rectangle(cr, hug_x, hug_y,hug_xsize,hug_ysize)
IF hug_fill THEN cairo_fill(cr) ELSE cairo_set_line_width (cr,1) cairo_stroke(cr) END IF
END SUB
SUB Draw
LINE("#0000FF",0,300,600,300) LINE("#0000FF",300,0,300,600) LOCAL pix, context, ebox,surface
REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix))
surface = hug_widget_surface( STR$(pix)) cr = cairo_create (surface)
cairo_translate(cr,300,300) cairo_rotate(cr,RAD(22.5)) SQUARE2(cr,"#FF00006F",-50,-50,100,100,1) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) )
END SUB
win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) CALLBACK(but,Draw) can = CANVAS(980,750) ATTACH(win,can,0,33)
DISPLAY
HAVE FUN
cairo_rotate(cr,RAD(22.5)) SQUARE2(cr,"#FF00006F",-50,-50,100,100,1) cairo_rotate(cr,RAD(22.5)) SQUARE2(cr,"#FF00006F",-50,-50,100,100,1) cairo_surface_flush(surface) BR Alex
PS :: can guess what is the task
Similar
|
|