Drawing two Chessboards

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaisen2100
Posts: 4
Joined: Mon Oct 23, 2006 10:55 pm
Contact:

Drawing two Chessboards

Post by kaisen2100 » Mon Jan 26, 2009 1:44 am

Hello, i am having a problem.

I am trying to draw two 10x10 chessboards.

i managed to draw the two boards perfectly, but it only works inside revolution. When i compile the program in windows xp, the boards are not drawn.

The program simply dont draw anything.

I want draw the chess board at anytime, and if there is any image created, delete ir and draw again the boards (may be with other colors, size, etc)

Here is my code, can you tell me what's worng please? thanks

Code: Select all

on mouseUp
   
   # Si ya existe, borrar imagen aterior
   if exists (image "board") then 
      delete image "board"
   end if
   
   # Definir los bordes de la imagen y definir nombre "board", luego crear imagen
   set the rectangle of templateimage to 4, 4, 678, 342
   set the name of the templateimage to "board"
   create image "board"
   
   # Dibujar los bordes de la imagen con el color de fondo blanco
   choose the rectangle tool
   set the pencolor to "black"
   # color de fondo
   set the brushcolor to "white" 
   drag from 4, 4 to 677, 341
   
   # Dibujar cada uno de los cuadrados
   # de los cuadros a partir del borde
   repeat with x = 0 to 9
      repeat with y = 0 to 9
         
         # Determinar si debemos dibujar un cuadrado blanco o negro
         if ((x + y) mod 2 = 0) then
            set the brushcolor to "white" 
         else
            set the brushcolor to "black"
         end if
         
         # Dibujar los cuadrados de la primera "board"
         # el "+12" es debido a 4 pixels del inicio de la imagen en "4,4" + 8 de separacaion a partir del borde
         drag from (x * 32) + 12, (y * 32) + 12 to ((x * 32) + 32 + 12) , ((y * 32) + 32 + 12)
         
         # Dibujar los cuadrados de la segunda "board"
         # el "+12" es debido a 4 pixels del inicio de la imagen en "4,4" + 8 de separacaion a partir del borde
         # el "+336" es igual al tamaño * 10 celulas + 16 pixels de separacion entre las 2 boards
         # 32 * 10 = 320 + 16 = 336
         drag from (x * 32) + 12 + 336, (y * 32) + 12 to ((x * 32) + 32 + 12) + 336 , ((y * 32) + 32 + 12)
         
      end repeat
   end repeat
   
   # Colocar el raton en modo normal
   choose the browse tool 
     
end mouseUp
Ignore the comments ... they are in Spanish :) and the numbers i use ... well those are just to not forgter what does each number ... just ignore the 32 + 12 +bla bla ... :)''thanks

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Jan 26, 2009 7:08 am

I'm not sure about the cause of your problem, but can't help but wonder: why are you drawing the chessboard by hand, and not just using a group of rectangle graphics? If you still want to create an image out of that, you could use export snapshot from group "Chessboard"

The fun part about Revolutin is that you don't have to write your own 'paintComponent' method as you have to do in Java - once an image is there, it stays put, just like other controls, unless you explicitly delete them. And if you have a multiple document interface, you can make a single template stack, and clone that stack, rather than having to recreate it from scratch.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

gmccarthy
Posts: 62
Joined: Sat Feb 17, 2007 4:56 am

Problem with standalones & Drawing two Chessboards

Post by gmccarthy » Mon Jan 26, 2009 9:24 am

Hi kaisen2100,

There are differences between the default settings for the development environment and standalones.
Sometimes the dictionary doesn't have all of these differences documented.

DEFAULTS DEVELOPMENT:
penwidth,penheight ,linesize 1
filled true
DEFAULTS standalone:
penwidth,penheight ,linesize 0
filled false

I suggest that you make sure that you set all the properties that are relevant for the tasks you are doing especially if you want to use them in a standalone.

Here are some relevant standalone dafaults that you should consider setting to your own values.
DEFAULTS standalone:
penwidth,penheight,linesize 0
filled false
pencolor 0,0,0
penpattern 136
brushcolor 255,255,255
brushpattern 136
Grid true
gridSize 4
dragSpeed 0


So, set the linesize to 1 and filled to true.


--------------
set the linesize to 1
set the filled to "true"
---------------

Hope this helps,

Gerard McCarthy

kaisen2100
Posts: 4
Joined: Mon Oct 23, 2006 10:55 pm
Contact:

Post by kaisen2100 » Mon Jan 26, 2009 10:43 pm

Hello ...
@gmccarthy: i added the lines you told me ...that solves the problem

@Janschenkel: i dont know if using square graphics will use much memory, because the board will have 200 squares plus 120 images (120 pieces). That will give me 320 individual objects ... may be that will use much RAM than just an image drawed "by hand" plus the 120 image pieces.

What you mean with " export snapshot from group "Chessboard"" ... i dont have any groups ...

I think i like most the idea of having just 1 image for the board and 1 image for each piece instread of working with 200 squares ... If you have any other in how to draw a chess please tell me :) i am new and i dont know all the commands that Revolution have.

By the way ... how can i draw text directly in an image/card or other control? i cant find any "drawtext x1,y1,x2,y2" function ...

I like RunRev ... but i lacks a solid reference manual with all the objects, properties and methods that we can use ... for new people using RunRev, a PDF doc with alll the objects, properties, commands, methods, etc is very useful.

The reference for any programming language helps knowing how to do the things faster ... if RunRev Enterprise have 1500+ commands ... i want to see ALL of them in a PDF document :)

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Jan 27, 2009 6:05 am

In Revolution, you don't usually write your own drawing or 'paint' methods - you combine graphics and image controls, plopping down as many as you need - and in the case of a chessboard, which is only drawn once, you'd either use Photoshop to create one image to import, or you could group all the controls involved, make a snapshot image, and delete the group.

As for documentation, you can always filter the contents of the Revolution dictionary on the basis of the object type. The Revolution User Guide is organized by topic, as well. The thing is, Revolution isn't like Delphi or Java or .NET - it comes with its own learning and unlearning curve. But once you get the hang of it, you can be extremely productive with it.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

kaisen2100
Posts: 4
Joined: Mon Oct 23, 2006 10:55 pm
Contact:

Post by kaisen2100 » Wed Jan 28, 2009 12:12 pm

thanks for the help ...

the point is, i want the user beign able to change the colors of the board, and changing the pieces at any time during the runtime, thats why i draw the image "by hand" and not loading any pre-created image.

May be i can do the board using graphic groups ...

Post Reply