|
Post by bigbass on May 9, 2013 16:28:45 GMT 1
Thank you Peter! For adding goo to HUG and providing a great sample demo Hug allows for easy syntax and easy reading! to keep with the easy to use idea of HUG a small suggestion we just use the simple color names for the getting started demo Thanks for the quick modification to add goo I just started looking at coding in goo yesterday and now its in HUG 'goo-hello.bac
'image used in demo 'http://www.basic-converter.org/baconeyes3.png
INCLUDE "hug.bac", INIT, WINDOW, CANVAS, DISPLAY, ATTACH, HUGOPTIONS, CIRCLE, PIXEL, LINE, SQUARE, OUT, PICTURE
INIT
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GOO")
win = WINDOW("Goo Canvas", 500, 400)
canvas = CANVAS(500, 400)
ATTACH(win, canvas, 0, 0)
CIRCLE("red", 50, 50, 100, 100, 0)
LINE("green", 300, 10, 100, 350)
SQUARE("blue", 10, 300, 50, 50, TRUE)
OUT("<b>Hello</b> GOO Canvas", "blue", "yellow", 0, 0)
PICTURE("./baconeyes3.png", 300, 100, 128, 128)
FOR x = 0 TO 50 PIXEL("blue", 100+x, 40) NEXT
DISPLAY
|
|
|
Post by vovchik on May 9, 2013 17:42:55 GMT 1
Dear Peter,
I also want to say "thanks". Time now to test things out....
With kind regards, vovchik
|
|
|
Post by alexfish on May 9, 2013 18:28:17 GMT 1
Hi all
Here is a little Demo
The original code is From Peter
The purpose of the demo is to find the ROOT for the Canvas , This is important if wanting to add to the canvas
Have also add a Rectangle , it is different from a normal type
Have also added a simple Animation
INCLUDE "hug86.bac" ' the above line is important / just a reminder U need Latest HUG 86 ' if have saved it as hug.bac then change the INCLUDE to hug.bac
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GOO")
' For File IMPORTS example Goo$=HUGLIB$("goo")
'@ the import line for ANIMATION IMPORT "goo_canvas_item_animate(long,double,double,double,double,int,int,int,int)" FROM Goo$ TYPE void
' setting for animation CONST GOO_CANVAS_ANIMATE_FREEZE = 0 CONST GOO_CANVAS_ANIMATE_RESET = 1 CONST GOO_CANVAS_ANIMATE_RESTART = 2 CONST GOO_CANVAS_ANIMATE_BOUNCE = 3
SUB ANIMATE
'@ goo_canvas_item_animate(rect,x,y,scale,rotation, TRUE, time,time-step, Animation-Type) goo_canvas_item_animate(rect,200,200, 1, 0, TRUE, 1000,5, GOO_CANVAS_ANIMATE_BOUNCE) END SUB
win = WINDOW("Goo Canvas", 500, 600)
canvas = CANVAS(500, 400)
ATTACH(win, canvas, 0, 0)
CIRCLE("#FF0000", 50, 50, 100, 100, 0)
LINE("#0000FF", 300, 10, 100, 350)
SQUARE("#FFFF00", 10, 300, 50, 50, TRUE)
OUT("<b>Hello</b> GOO Canvas", "#FF00FF", "#0000FF", 0, 0)
FOR x = 0 TO 50 PIXEL("#FF00FF", 100+x, 40) NEXT
'@ Add buton but = BUTTON("Animate",100,30) ATTACH(win,but,20,410) '@ Add Call back to Button for animation CALLBACK (but , ANIMATE)
' the CANVAS ID IS THE EBOX = hug_widget_image(STR$(ebox)) Root_Canvas=goo_canvas_get_root_item(hug_widget_image(STR$(canvas)))
' Add A rectangle to the Canvas with ROUNDED CORNERS rect = goo_canvas_rect_new(Root_Canvas,50,50,80, 80,"fill-color" ,"brown","radius-x", 6.0, "radius-y", 6.0,"stroke-color", "black","line-width" ,1.0,NULL) DISPLAY
Now should be able to try other example code
Try this line
goo_canvas_item_animate(rect,200,200, 2, 180, TRUE, 1000,5, GOO_CANVAS_ANIMATE_BOUNCE)
alter the size of the rectangle to
rect = goo_canvas_rect_new(Root_Canvas,50,50,40, 40,"fill-color" ,"brown","radius-x", 6.0, "radius-y", 6.0,"stroke-color", "black","line-width" ,1.0,NULL)
and the animate line to
goo_canvas_item_animate(rect,500,500,2,180, TRUE, 1000,5, GOO_CANVAS_ANIMATE_BOUNCE)
Have Fun
Alex
|
|
|
Post by alexfish on May 9, 2013 21:59:49 GMT 1
Hi All
GOO CANVAS "FIFTEEN" Version 2
'***************************************************** ' ************************************************************** ' PROGRAM: PROGRAM: Fifteen : Goo Canvas Demo ' PURPOSE: goocanvas animation demo ' AUTHORS: .org alexfish (BaCon Converter Forum) ' .org vovchik(Puppy Linux Forums) ' DATE: 06-05-2013 ' LICENSE: GLP3 ' ************************************************************** '*****************************************************
' *********************** ' INCLUDES ' ***********************
INCLUDE "hug86.bac"
' *********************** ' END INCLUDES ' ***********************
' *********************** ' IMPORTS ' ***********************
IMPORT "goo_canvas_item_set_child_properties(long,long,...)" FROM HUGLIB$("goo") TYPE void IMPORT "goo_canvas_table_new(long,...)" FROM HUGLIB$("goo") TYPE long IMPORT "goo_canvas_text_new(long,char*,double,double,double,int,...)" FROM HUGLIB$("goo") TYPE long
' *********************** ' END IMPORTS ' ***********************
' *********************** ' INITIALIZATION ' ***********************
' hug options HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GOO") ' some goo cavas widgets properties need ' to have declares set as TYPE CONST GTK_ANCHOR_CENTER = 0 DECLARE PIECE_SIZE TYPE double PIECE_SIZE = 50 DECLARE color$[16] DECLARE sets[5][5] DECLARE colour ASSOC STRING DECLARE selwidget ASSOC NUMBER DECLARE i TYPE NUMBER DECLARE rect[16] TYPE NUMBER DECLARE text[16] TYPE NUMBER ' set the rect array to 0 FOR t = 0 TO 15 rect[t] = 0 NEXT t ' ----- ' define colors ' ----- color$[ 0] = "#FFFFFF" color$[ 1] = "#56FF00" color$[ 2] = "#43C102" color$[ 3] = "#43AA0E" ' ----- color$[ 4] = "#368E08" color$[ 5] = "#FF4D00" color$[ 6] = "#D14C13" color$[ 7] = "#B24110" ' ----- color$[ 8] = "#933811" color$[ 9] = "#4100FF" color$[10] = "#4312D2" color$[11] = "#4722B2" ' ----- color$[12] = "#22037A" color$[13] = "#FAF80D" color$[14] = "#E7E60F" color$[15] = "#C9C80C"
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB SELECTED(long widget, NUMBER event, NUMBER textdat) ' ------------------ ' find the white first FOR i = 15 TO 0 STEP -1 y = i / 4 x = i % 4 wigmove = sets[y][x] st$ = colour(STR$(wigmove)) IF st$ = "#FFFFFF" THEN tmpx = x tmpy = y i_first = 1 tempwigmove = wigmove row_up = x - 1 row_down = x + 1 col_left = y - 1 col_right = y + 1 BREAK END IF NEXT i ' ----- ' main checking FOR i = 15 TO 0 STEP -1 y = i / 4 x = i % 4 b = sets[y][x] IF b = widget THEN pos_x = x pos_y = y i_second = i BREAK END IF NEXT i ' ----- ' check squares row_up = pos_x - 1 row_down = pos_x + 1 col_left = pos_y - 1 col_right = pos_y + 1 IF (row_up > -1 ) & (row_up < 3) THEN b = sets[pos_y][row_up] st$ = colour(STR$(b)) IF st$ = "#FFFFFF" THEN movwidget = selwidget(STR$(tempwigmove)) swap = selwidget(STR$(widget)) ' swap the numbers goo_canvas_item_set_child_properties(table, text[movwidget], \ "row", pos_x, "column", pos_y, NULL) goo_canvas_item_set_child_properties(table, text[swap], "row", \ pos_x - 1, "column", pos_y, NULL) sets[pos_y][pos_x] = tempwigmove sets[pos_y][pos_x - 1] = widget END IF END IF ' ----- IF (row_down > 0 ) & (row_down < 4) THEN b = sets[pos_y][row_down] st$ = colour(STR$(b)) IF st$ = "#FFFFFF" THEN movwidget = selwidget(STR$(tempwigmove)) swap = selwidget(STR$(widget)) ' swap the numbers goo_canvas_item_set_child_properties(table, text[movwidget], \ "row", pos_x, "column", pos_y, NULL) goo_canvas_item_set_child_properties(table, text[swap], \ "row", pos_x + 1, "column", pos_y, NULL) sets[pos_y][pos_x] = tempwigmove sets[pos_y][pos_x + 1] = widget END IF END IF ' ----- IF (col_left > -1) & (col_left < 3) THEN b = sets[col_left][pos_x] st$ = colour(STR$(b)) IF st$ = "#FFFFFF" THEN movwidget = selwidget(STR$(tempwigmove)) swap = selwidget(STR$(widget)) ' swap the numbers goo_canvas_item_set_child_properties(table, text[movwidget], \ "row", pos_x, "column", pos_y, NULL) goo_canvas_item_set_child_properties(table, text[swap], \ "row", pos_x, "column", pos_y - 1, NULL) sets[pos_y][pos_x] = tempwigmove sets[pos_y - 1][pos_x] = widget END IF END IF ' ----- IF (col_right > 0 ) & (col_right < 4) THEN b = sets[col_right][pos_x] st$ = colour(STR$(b)) IF st$ = "#FFFFFF" THEN movwidget = selwidget(STR$(tempwigmove)) swap = selwidget(STR$(widget)) ' swap the Numbers goo_canvas_item_set_child_properties(table, text[movwidget], \ "row", pos_x, "column", pos_y, NULL) goo_canvas_item_set_child_properties(table, text[swap], \ "row", pos_x, "column", pos_y + 1, NULL) sets[pos_y][pos_x] = tempwigmove sets[pos_y + 1][pos_x] = widget END IF END IF END SUB
' ------------------ FUNCTION CREATE_CANVAS_FIFTEEN() ' ------------------ LOCAL text$ TYPE char ' create the table and add tiles + text numbers table = goo_canvas_table_new(root_canvas1,"row-spacing", 1.0, \ "column-spacing", 1.0, NULL) FOR i = 15 TO 0 STEP -1 y = i / 4 x = i % 4 ' make the tiles from rectangles rect[i] = goo_canvas_rect_new(table, 0, 0, PIECE_SIZE, PIECE_SIZE, \ "fill-color" , "#DBDBDB", "radius-x", 6.0, "radius-y", 6.0, \ "stroke-color", "black", "line-width" , 1.0, NULL) ' set the item in the table goo_canvas_item_set_child_properties (table, rect[i] , "row", \ x, "column", y, NULL) NEXT i FOR i = 15 TO 0 STEP -1 y = i / 4 x = i % 4 ' add TEXT as number text[i] = goo_canvas_text_new(table, STR$(i), 0, 0, PIECE_SIZE, \ GTK_ANCHOR_CENTER, "font", "Sans bold 24", "fill-color", \ color$[i], NULL) ' set the height of the text; this property is not set by default g_object_set(text[i], "use-markup", TRUE, 0) ' fix vertical centring g_object_set(text[i], "text", CONCAT$("<span rise='-37000'>", STR$(i), "</span>"), 0) g_object_set(text[i], "height", PIECE_SIZE, NULL) ' assoc the text with the number selwidget(STR$(text[i])) = i ' assoc the text with its color colour(STR$(text[i])) = color$[i] ' get the text and print it g_object_get(text[i], "text", ADDRESS(text$), NULL) PRINT "TEXT : ", text$ ' set the item in the table goo_canvas_item_set_child_properties(table, text[i] , "row", x, \ "column", y, NULL) ' store the text in array sets[y][x] = text[i] ' goo canvas items can have callbacks, so here set the callback ' for the TEXT; the sub is 'SELECTED' g_signal_connect_data(text[i], "button-press-event", SELECTED, 0, 0, 0) NEXT i ' set first tile to no text so it cannot be seen g_object_set(text[0], "text", "", NULL) RETURN TRUE END FUNCTION
' ------------------ SUB MK_GUI() ' ------------------ win = WINDOW("Fifteen", 207, 247) canvas1 = CANVAS(207, 207) ATTACH(win, canvas1, 0, 0) ' the canvas id is the ebox = hug_widget_image(STR$(ebox)) root_canvas1 = goo_canvas_get_root_item(hug_widget_image(STR$(canvas1))) ' create a goo canvas table + add tiles and numbers fifteen = CREATE_CANVAS_FIFTEEN() but1 = BUTTON("New", 65, 30) PROPERTY(but1, "tooltip-text", "Start a new game.") ATTACH(win, but1, 0, 212) but2 = BUTTON("Quit", 65, 30) PROPERTY(but2, "tooltip-text", "Quit this game.") ATTACH(win, but2, 142, 212) CALLBACK(but2, QUIT) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
There is a challenge Here
First one to add a random number Generator May get a Karma Point , as in May be
Since , Think Peter may WIN this one
Have Fun
Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 10, 2013 2:30:07 GMT 1
Any objection to using what would get converted to anyways? Rand()
|
|
|
Post by alexfish on May 10, 2013 2:38:50 GMT 1
Any objection to using what would get convert to anyways? Rand()Hi John Think a bit of C good Idea , at some point may have to use c with Goo Noticed a nice bit of c in the New Hug , BR Alex
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 10, 2013 2:55:19 GMT 1
Remind me the first week of Oct. to tell the neighborhood kids that stopping at your house on Holloween would be a bust.
|
|
|
Post by alexfish on May 10, 2013 3:19:27 GMT 1
Remind me the first week of Oct. to tell the neighborhood kids that stopping at your house on Holloween would be a bust. ::: new version with button awaits you , it may save a bust but1 = BUTTON("New", 65, 30) PROPERTY(but1, "tooltip-text", "Start a new game.") ATTACH(win, but1, 0, 212) or can Score Brownie points if use this developer.gnome.org/glib/2.31/glib-Random-Numbers.htmlHTH BR Alex PS:: Thanks Vovchik
|
|
|
Post by vovchik on May 10, 2013 13:18:32 GMT 1
Dear Alex (et al.), I just learned how to do radial gradients using cairo. Looks good, I think, and easy to do With kind regards, vovchik Attachments:
|
|
|
Post by bigbass on May 10, 2013 15:28:00 GMT 1
RANDOM number generatorhere is the simplest example using PROTO using just a window so as not to cloud what is happening "borrowed" the one liner rand from here wingtk.sourceforge.net/ishan/sliders.htmlevery time you start a window this *could be a callback button also * the random number is generated in the terminal P.S I wasn't fishing for a karma point (and it was a stolen idea not an original one) but I do like a puzzle though '--- set up for compiling embedded library GTK PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
'--- this replaces the need for IMPORT. the TYPE is not needed '--- place all the functions that you will use here
PROTO gtk_init PROTO gtk_window_new PROTO gtk_window_set_title PROTO g_signal_connect_data, PROTO g gtk_widget_show_all PROTO gtk_main PROTO gtk_main_quit
' get the needed missing values GTK_WINDOW_TOPLEVEL = 0
'=============== SUB exit_prog '=============== gtk_main_quit END SUB
'--- random number generator shamelessly stolen from a game :D '--- the number % 15 makes number 0-15 you can change the 15 '------------------------------------------------- myrand = abs(g_rand_int ( g_rand_new () )) % 15; '-------------------------------------------------- PRINT "myrand = " PRINT myrand
gtk_init(0, 0) window = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_title(window, "Hello World!")
'--- Connect the main window to the destroy ---> replace with SUB exit_prog g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0) gtk_widget_show_all(window) gtk_main
|
|
|
Post by alexfish on May 10, 2013 15:47:48 GMT 1
Thanks joe would like to see Peter beat at his own Game now need to apply to the code , to the game but it will not matter how it is implemented , I know U be good at getting external info into a UI. or making includes. BR Alex ....maybe a 2cudos reward for a lost treasure
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 10, 2013 17:13:16 GMT 1
I was going to offer 3 days/2 nights in Vegas but your offer trumps mine in spades. ;D
Any luck getting ScriptBasic for Windows under Wine going?
|
|
|
Post by vovchik on May 10, 2013 17:19:10 GMT 1
Dear guys,
I am not certain I understand this random discussion. BaCon always had:
number = RANDOM(16)
that would give you a random number from 0-15. Or
number = RANDOM(16) + 1
that would give you a random number from 1-16.
You can also use /dev/urandom, or the relevant bits of a shuffle routine, such as mine below, if you want a series of numbers from 0 to 15 with no repetition:
' ***************** ' DECLARATIONS ' *****************
GLOBAL Deck[53] TYPE NUMBER GLOBAL Cards_Played TYPE NUMBER GLOBAL Suit$[5] TYPE STRING GLOBAL SuitName$[5] TYPE STRING GLOBAL CardName$[14] TYPE STRING GLOBAL MyValue TYPE NUMBER GLOBAL MySuit TYPE NUMBER GLOBAL MyCardName$ TYPE STRING GLOBAL My_Card TYPE NUMBER GLOBAL My_Suit$ TYPE STRING GLOBAL MyCardShortName$ TYPE STRING GLOBAL MyCardImgFile$ TYPE STRING GLOBAL PlayAgain$ TYPE STRING GLOBAL StartMoney TYPE NUMBER GLOBAL QuitCount TYPE NUMBER GLOBAL GamesTotal TYPE NUMBER GLOBAL PlayerName$ TYPE STRING GLOBAL Insurance$ TYPE STRING
' ***************** ' END DECLARATIONS ' *****************
' ***************** ' INIT VARS ' *****************
Cards_Played = 0
Suit$[1] = "c" Suit$[2] = "d" Suit$[3] = "h" Suit$[4] = "s"
SuitName$[1] = "Clubs" SuitName$[2] = "Diamonds" SuitName$[3] = "Hearts" SuitName$[4] = "Spades"
CardName$[1] = "Ace" CardName$[2] = "Two" CardName$[3] = "Three" CardName$[4] = "Four" CardName$[5] = "Five" CardName$[6] = "Six" CardName$[7] = "Seven" CardName$[8] = "Eight" CardName$[9] = "Nine" CardName$[10] = "Ten" CardName$[11] = "Jack" CardName$[12] = "Queen" CardName$[13] = "King"
MyCardName$ = "" MyCardShortName$ = "" MyCardImgFile$ = ""
' For betting purposes and continuation PlayAgain$ = "Y" StartMoney = 500 QuitCount = 0 GamesTotal = 1
' ***************** ' END INIT VARS ' *****************
' ***************** ' FUNCTIONS ' *****************
FUNCTION Print_Deck(STRING MyLabel$) ' this exists only for checking the shuffling routine PRINT NL$, MyLabel$, NL$ FOR i = 1 TO 52 PRINT Deck[i]," "; NEXT i PRINT NL$ RETURN TRUE END FUNCTION
FUNCTION Init_Deck FOR i = 1 TO 52 Deck[i] = i NEXT i RETURN TRUE END FUNCTION
FUNCTION Shuffle_Deck SEED NOW FOR i = 1 TO 10 FOR j = 1 TO 52 k = MOD(RND, 52) + 1 temp = Deck[j] Deck[j] = Deck[k] Deck[k] = temp NEXT j NEXT i RETURN TRUE END FUNCTION
FUNCTION Draw_Card Cards_Played = Cards_Played + 1 My_New_Card = Deck[Cards_Played] RETURN My_New_Card END FUNCTION
FUNCTION Identify_Card MyValue = MOD((My_Card - 1),13) + 1 IF My_Card < 14 AND My_Card > 0 THEN MySuit = 1 END IF IF My_Card > 13 AND My_Card < 27 THEN MySuit = 2 END IF IF My_Card > 26 AND My_Card < 40 THEN MySuit = 3 END IF IF My_Card > 39 AND My_Card < 53 THEN MySuit = 4 END IF MySuitName$ = CONCAT$(" of ", SuitName$[MySuit]) My_Suit$ = Suit$[MySuit] MyCardName$ = CardName$[MyValue] IF MyValue < 2 OR MyValue > 10 THEN SELECT MyValue CASE 1 MyCardShortName$ = "a" CASE 11 MyCardShortName$ = "j" CASE 12 MyCardShortName$ = "q" CASE 13 MyCardShortName$ = "k" END SELECT ELSE MyCardShortName$ = STR$(MyValue) END IF MyCardImgFile$ = CONCAT$("data/img/", MyCardShortName$, My_Suit$, ".gif") RETURN TRUE END FUNCTION
' ***************** ' END FUNCTIONS ' *****************
' ***************** ' MAIN ' *****************
Init_Deck Print_Deck("Original Deck:") Shuffle_Deck Print_Deck("Shuffled Deck:") PRINT FOR i = 1 TO 40 My_Card = Draw_Card() Identify_Card PRINT i,". "; PRINT "Card drawn: ", My_Card, " Value: ", MyValue, " ", MyCardName$, MySuitName$, " (",My_Suit$,") "; PRINT "File name: ", MyCardImgFile$ NEXT i PRINT END
' ***************** ' END MAIN ' *****************
With kind regards, vovchik
|
|
|
Post by alexfish on May 10, 2013 18:15:00 GMT 1
Hey Vovchik Correct: we have a button to have New Game The Numbers Are 0 TO 15 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 so need a random function generator to do as you mentioned Here assuming Bacon does more or less the same as this ' *********************** '@ GLIB IMPORT defines for Random Numbers Glib$=HUGLIB$("glib")
IMPORT "g_rand_new" FROM Glib$ TYPE long IMPORT "g_rand_int_range(long,int,int)" FROM Glib$ TYPE int
LOCAL G_rand_1 TYPE long
DECLARE RANDOM_0 TYPE int G_rand_1=g_rand_new() DECLARE my_rand[16] FOR n= 0 TO 15 my_rand[n]=-1 NEXT 'my_rand[0] =g_rand_int_range(G_rand_1,0,15)
FOR t = 0 TO 15 my_rand[t] = g_rand_int_range(G_rand_1,0,15) PRINT " Random Generated : ",my_rand[t] NEXT
FOR n = 0 TO 15 PRINT " Random Stored in array 'my_rand[",n,"] : ",my_rand[n ] NEXT
FREE G_rand_1 The Array must hold 16 different numbers , the when button New Game, set the Tiles(text) accordingly Best Results may get a Karma. Still say Peter will win ;D I always Like to do something different + leaning a useful bit of how-to Have Fun Alex
|
|
|
Post by bigbass on May 10, 2013 19:45:29 GMT 1
Here is a new spin on things using PROTO
and using some C and Bacon mixed without USEC or even importing g_rand_int just using the BaCon compiler
I added an extra system call for fun notice lower case spelling system
random-proto.bac
'--- set up for compiling embedded library GTK PRAGMA LDFLAGS `pkg-config --cflags --libs gtk+-2.0`
'--- random number generator shamelessly stolen from a game :D '--- the number % 15 makes number 0-15 you can change the 15 '------------------------------------------------- myrand = abs(g_rand_int ( g_rand_new () )) % 15; '--------------------------------------------------
PRINT "myrand = " ,myrand
PRINT "--------------"
'--- maybe a loop is needed FOR i = 1 TO 15 myrand = abs(g_rand_int ( g_rand_new () )) % 15; PRINT myrand NEXT i
'--- how about some more real C printed in BaCon return_value = system ("ls -l /") PRINT return_value
|
|