|
Post by alexfish on Apr 18, 2023 10:28:20 GMT 1
Test Animation
'TEST ANIMATION INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") '============================================== FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================ 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 '============================================================ LOCAL PTR TYPE double FUNCTION Draw
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) cairo_translate(cr,MOUSE(0),MOUSE(1)) cairo_rotate(cr,RAD(PTR)) SQUARE2(cr,"#FF00006F",-50,-50,100,100,1) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) SYNC INCR PTR,5 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(20,Draw) DISPLAY
IF use -PTR the rotation should reverse
|
|
|
Post by alexfish on Apr 18, 2023 10:52:01 GMT 1
Test Image Animation Change the file to your file in PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100)
The PICTURE resizes the Image, so no need to estimate , try fist then .... 'TEST ANIMATION2 INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) cairo_translate(cr,MOUSE(0),MOUSE(1)) cairo_rotate(cr,RAD(PTR))
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) SYNC INCR PTR,5 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(20,Draw) DISPLAY
Now You Can Spin Those Wheels , saved as pngEllipse the Torus Attachments:toroid.png.bz2 (16.98 KB)
|
|
|
Post by alexfish on Apr 18, 2023 14:34:53 GMT 1
Animation 3
rotating Torus following a circular path
The Fastest Torus in Town
'TEST ANIMATION3 INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy TYPE double
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,xx+300,yy+300 ) cairo_rotate(cr,RAD(-PTR))
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) 'SYNC INCR PTR,2 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY
|
|
|
Post by alexfish on Apr 18, 2023 14:46:25 GMT 1
MAKE A YOYO
'TEST ANIMATION4 YOYO INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy TYPE double
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,xx+300,yy+300 ) cairo_rotate(cr,RAD(-PTR))
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) LINE("FF0000",0,0,xx+300,yy+300) 'SYNC INCR PTR,2 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY
|
|
|
Post by alexfish on Apr 18, 2023 14:55:06 GMT 1
BUNGIE JUMP
'TEST ANIMATION3 BUNGIE INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy TYPE double
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,300,yy+300 ) cairo_rotate(cr,RAD(-PTR))
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) LINE("FF0000",0,0,300,yy+300) LINE("FF0000",600,0,300,yy+300) 'SYNC INCR PTR,2 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY
|
|
|
Post by alexfish on Apr 18, 2023 15:02:53 GMT 1
FLYING DOUGHNUT could be a bird a pair of wings + birds head to stay still'ish , 'TEST ANIMATION3 FLYING INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy TYPE double
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,300,yy+300 ) cairo_rotate(cr,RAD(-PTR))
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) LINE("FF0000",0,xx+300,300,yy+300) LINE("FF0000",600,xx+300,300,yy+300) 'SYNC INCR PTR,2 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY That's WrapYou mean something like 'TEST ANIMATION4 FLYING INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME") FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy TYPE double
LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#FFFFFF",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,300,yy+300 ) cairo_rotate(cr,RAD(-PTR))
'PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf) LINE("FF0000",100,yy+300,300,300) LINE("FF0000",500,yy+300,300,300) 'SYNC INCR PTR,2 RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY 'YES' but where is it head 'It came without one ' Have Fun + BR Alex
|
|
|
Post by alexfish on Apr 18, 2023 15:33:23 GMT 1
Next A Clone of PacMan (c) Return of BacPacBoy
|
|
|
Post by alexfish on Apr 18, 2023 20:11:17 GMT 1
Looking for sounds and images :: py games has a good collection in code-the-classics look in
/usr/share/code-the-classics/ Or find link to github Post#1
More on this Next:: games
+ how to play the sounds
|
|
|
Post by alexfish on Apr 19, 2023 7:14:23 GMT 1
Q:: you mentioned , cairo available for openGL
A:: yes , but not really for this thread
for instance ON gl thread
Here can draw the bits in cairo and get the data:: as mentioned in the posts
This sub can be adapted to get the data from the surface rather than a pixbuf or either , if have save your images:: also in there will have to unref the pix buf
Example::
SUB LoadGLTextures() LOCAL pix LOCAL boundTexture = 0 TYPE GLuint pix = gdk_pixbuf_new_from_file("./basic.png",0) x= gdk_pixbuf_get_width(pix) y = gdk_pixbuf_get_height(pix) data=(unsigned char*) gdk_pixbuf_get_pixels(pix) 'gdk_pixbuf_unref(pix) PRINT x , " : " , y
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*) &boundTexture) glGenTextures(1, &texture) glBindTexture(GL_TEXTURE_2D, texture) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
END SUB
the bit you are looking for is
data=(unsigned char*) BR Alex
|
|
|
Post by alexfish on Apr 19, 2023 11:52:41 GMT 1
Q: how can I time the Direct draw function to be in limits of timeout
A: BaCon TIMER in mls IE 1000 = 1 sec full demo ; launch from terminal , use toroid.png in previous posts
'TEST ANIMATION4 timer INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME")
FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy TYPE double LOCAL tms,tmf tms = TIMER LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#000000",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,300,-yy+300 ) cairo_rotate(cr,RAD(-PTR)) IF (-yy+300 > 300) THEN LINE("#FFFF00",100,(xx/2)+300,300,-yy+300) LINE("#FFFF00",500,(xx/2)+300,300,-yy+300) LINE("#FFFF00",150+50,(xx/2)+300,300,-yy+300) LINE("#FFFF00",450,(xx/2)+300,300,-yy+300) ELSE LINE("#FF00FF",100,(xx/2)+300,300,-yy+300) LINE("#FF00FF",500,(xx/2)+300,300,-yy+300) LINE("#FF00FF",150+50,(xx/2)+300,300,-yy+300) LINE("#FF00FF",450,(xx/2)+300,300,-yy+300) END IF
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf)
'SYNC INCR PTR,2 tmf = TIMER PRINT "Time " , tmf-tms RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Timer",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY
|
|
|
Post by alexfish on Apr 19, 2023 14:50:50 GMT 1
Q:: if those lines are meant to look like wings is so they look crap
A:: See code Flapping Wings
'TEST ANIMATION5 timer INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME")
FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
SUB PICTURE2 (cr,STRING hug_file$, int hug_xpos, int hug_ypos, int hug_xsize, int hug_ysize)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER) gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr) g_object_unref(buf) g_object_unref(buf2)
END SUB '============================================================ LOCAL PTR TYPE double FUNCTION Draw LOCAL angle ,xx,yy,df TYPE double LOCAL tms,tmf tms = TIMER df = 5 LOCAL surf surf = SURFACE() cr = cairo_create (surf) SQUARE("#000000",0,0,600,600,1) angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_translate(cr,300,-yy+300 ) cairo_rotate(cr,RAD(-PTR)) IF (-yy+300 > 300) THEN LINE("#FFFF00",100,(xx/2)+300,300,-yy+300) LINE("#FFFF00",100,(xx/2)+300,200,(xx/df)+300) LINE("#FFFF00",500,(xx/2)+300,300,-yy+300) '================================================== LINE("#FFFF00",150+50,(xx/df)+300,300,-yy+300) LINE("#FFFF00",400,(xx/df)+300,300,-yy+300) LINE("#FFFF00",400,(xx/df)+300,500,(xx/2)+300) ELSE
LINE("#FF00FF",100,(xx/2)+300,300,-yy+300) LINE("#FF00FF",100,(xx/2)+300,200,(xx/df)+300) LINE("#FF00FF",500,(xx/2)+300,300,-yy+300) '================================================== LINE("#FF00FF",150+50,(xx/df)+300,300,-yy+300) LINE("#FF00FF",400,(xx/df)+300,300,-yy+300) LINE("#FF00FF",400,(xx/df)+300,500,(xx/2)+300) END IF
PICTURE2(cr,HOME$ & "/toroid.png", -50,-50,100,100) cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf)
'SYNC INCR PTR,2 tmf = TIMER 'PRINT "Time " , tmf-tms RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Elipse",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY
That a Wrap
Your ToDo make bit like clip/path :: Add png wings or feathers + stick a birds head in the middle
|
|
|
Post by alexfish on Apr 19, 2023 16:34:11 GMT 1
PAINT surface LINE PATH CLOSE PATH /FILL ANIMATION
A shorter and faster way than above posts That use LINE by LINE
'TEST LINE Fill ANIMATION6 timer INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME")
FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================ LOCAL PTR TYPE double
FUNCTION Draw LOCAL angle ,xx,yy,df TYPE double LOCAL tms,tmf tms = TIMER df = 5 LOCAL surf
surf = SURFACE() cr = cairo_create (surf) cairo_set_source_rgb(cr,1,1,1) 'No need to draw rect : just paint it cairo_paint(cr) cairo_new_path(cr)
angle = 2 * PI * PTR / 360 xx = (400/2)*COS(angle) yy = (400/2)*SIN(angle)
cairo_set_line_width (cr,1)
IF (-yy+300 > 300) THEN cairo_set_source_rgba(cr,1,0,0,0.5)
cairo_move_to (cr,100,(xx/2+300)) cairo_line_to(cr,300,-yy+300) cairo_line_to(cr,200,(xx/df)+300) cairo_close_path (cr) cairo_fill(cr)
cairo_move_to (cr,500,(xx/2+300)) cairo_line_to(cr,300,-yy+300) cairo_line_to(cr,400,(xx/df)+300) cairo_close_path (cr) cairo_fill(cr)
ELSE cairo_set_source_rgba(cr,0,0,1,0.5)
cairo_move_to (cr,100,(xx/2+300)) cairo_line_to(cr,300,-yy+300) cairo_line_to(cr,200,(xx/df)+300) cairo_close_path (cr) cairo_fill(cr)
cairo_move_to (cr,500,(xx/2+300)) cairo_line_to(cr,300,-yy+300) cairo_line_to(cr,400,(xx/df)+300) cairo_close_path (cr) cairo_fill(cr) END IF
cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf)
INCR PTR,2 tmf = TIMER 'PRINT "Time " , tmf-tms RETURN TRUE END FUNCTION '============================================================ win = WINDOW("paine path line fill",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY
Task do some bits in center , like make delta wing , head of a eagle , cockpit .... can use stoke if wish
On Rpi = 2 , 3 ml seconds 0.002 , 0.003 sec
Added: Pilot
Want to be a pilot
Pilot trainer bits
@
'cairo_set_line_width (cr,1) cairo_translate(cr,600,0) 'cairo_scale(cr,0.5,0.5) cairo_rotate(cr,RAD(90))
IF (-yy+300 > 300) THEN
|
|
|
Post by Pjot on Apr 19, 2023 17:21:28 GMT 1
Thanks Alex, I have tried a few of your demos and they work fine in my Linux Mint 21 BR Peter
|
|
|
Post by alexfish on Apr 19, 2023 18:28:16 GMT 1
Thanks Peter
added pilot bit to the code above
Pilot trainer bits
Thanks again + BR Alex
|
|
|
Post by alexfish on Apr 19, 2023 20:42:23 GMT 1
And a CURVE to If want any more on this one It ain,t Gona Happen 'TEST CURVE timer INCLUDE "hug35.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVASCAIRO") HOME$= GETENVIRON$("HOME")
FUNCTION SURFACE() LOCAL pix, context, ebox,surface REM Get the associated canvas pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) RETURN ( hug_widget_surface( STR$(pix)))
END FUNCTION
'============================================================
FUNCTION Draw
LOCAL tms,tmf
LOCAL surf
surf = SURFACE() cr = cairo_create (surf) cairo_set_source_rgb(cr,1,1,1) cairo_paint(cr)
cairo_set_source_rgba(cr,1,0,0,0.5) cairo_new_path(cr) cairo_translate(cr,200,200) cairo_curve_to(cr,-200,100,0,400,200,100) cairo_close_path(cr) cairo_fill(cr) 'cairo_stroke(cr) 'IMPORT "cairo_curve_to (long, double,double,double, double, double, double)" /* cairo_curve_to () void cairo_curve_to (cairo_t *cr, double x1, double y1, double x2, double y2, double x3, double y3); Adds a cubic Bézier spline to the path from the current point to position (x3 , y3 ) in user-space coordinates, using (x1 , y1 ) and (x2 , y2 ) as the control points. After this call the current point will be (x3 , y3 ).
If there is no current point before the call to cairo_curve_to() this function will behave as if preceded by a call to cairo_move_to(cr , x1 , y1 ).
Parameters cr
a cairo context
x1
the X coordinate of the first control point
y1
the Y coordinate of the first control point
x2
the X coordinate of the second control point
y2
the Y coordinate of the second control point
x3
the X coordinate of the end of the curve
y3
the Y coordinate of the end of the curve */ cairo_surface_flush(surf) cairo_destroy(cr) gtk_image_set_from_surface (hug_gui_properties.canvas,surf)
OUT("I finally get a inverted HUMP","#FF0000","#00FFFF",20,20) tmf = TIMER 'PRINT "Time " , tmf-tms RETURN TRUE END FUNCTION '============================================================ win = WINDOW("Two Bottle Later",1000,800) but = BUTTON("draw",75,20) ATTACH(win,but,3,0) can = CANVAS(600,600) ATTACH(win,can,0,33)
TIMEOUT(10,Draw) DISPLAY Pick of IMPROVED VERSION Attachments:
|
|