Color fill a shape - My head hurts!

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Color fill a shape - My head hurts!

Post by Lagi Pittas » Tue Jan 17, 2017 4:41 pm

Hi

I haven't spent days but enough time to know I don't know what I'm doing - no databases to be found anywhere.

Just for starters I have this code

Code: Select all

on MouseUp
   local lnCardWidth, lnCardHeight, lnX, lnY, lnSize
   
   set the backgroundcolor of this card to" WHITE"
   
   put the width  of this card into lnCardWidth
   put the height of this card into lnCardHeight
   
   -- Get rid of any images
   repeat with lnX = the number of graphics down to 1
      delete graphic lnX
   end repeat
   
   create graphic 1
   set the style     of graphic 1 to "oval"
   set the opaque    of graphic 1 to TRUE
   set the linesize  of graphic 1 to 1
   set the textcolor of graphic 1 to "BLACK"
   
   -- Get the centre
   put lnCardWidth / 2 into lnX
   put lnCardHeight / 2 into lnY
   
   set the backgroundColor of graphic 1  to "WHITE" 
   
   YinYang lnX, lnY, 300
   
end  MouseUp


on YinYang pX, pY, pSize
   lock screen
   
   set the location  of graphic 1 to pX, pY
   set the width     of graphic 1 to pSize
   set the height of graphic 1 to pSize
   
   set the style of the templateGraphic to "line"
 
  set the points of the templategraphic to (pX, pY +pSize / 2,  px ,pY - pSize / 2)
  create graphic
   
   unlock screen
end YinYang

All I want to do is color the left half of the circle in Black - Now knowing this is livecode there are probably 10 ways to do this - 2 or 3 will do '-) . The simplest is always the best - "make it work then make it better"

I'm using LC v 6.7.11

Regards Lagi

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Color fill a shape - My head hurts!

Post by [-hh] » Tue Jan 17, 2017 5:09 pm

Hi Lagi,
see here a yinyang-clock, made with graphics:
http://hyperhh.de/html5/YinYang-8.0.2X.html
Download the stack by replacing "X.html" with ".zip"

Hermann

For your opening question: Make TWO halfcircles (use startangle and arcangle), one black one white.
You can't have ONE graphic filled with TWO different colors.
shiftLock happens

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Re: Color fill a shape - My head hurts!

Post by Lagi Pittas » Wed Jan 18, 2017 11:16 am

Thanks Hermann


The full circles I could do but I though there might have been a flood fill like the below BBC Basic for windows

Code: Select all

      procyinyang(700, 400, 300)
      end

      def procyinyang(xpos%, ypos%, size%)
      circle xpos%, ypos%, size%
      line xpos%, ypos%+size%, xpos%, ypos%-size%
      fill xpos%+size%/2, ypos%
      circle fill xpos%, ypos%-size%/2, size%/2+2
      gcol 15
      circle fill xpos%, ypos%+size%/2, size%/2+2
      circle fill xpos%, ypos%-size%/2, size%/6+2
      gcol 0
      circle fill xpos%, ypos%+size%/2, size%/6+2
      circle xpos%, ypos%, size%
      endproc
Nostalgia isn't what it used to be ...

Anyway I thought maybe the bucket paint in the tool palette would do that but I can't see how to use it.

Regards Lagi

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Color fill a shape - My head hurts!

Post by [-hh] » Wed Jan 18, 2017 6:07 pm

That's not you, the paint tools are partially defunct in LC 8/9:
In LC 8 there is no line tool, in LC 9 choosing the oval tool yields rectangle etc.

So start with LC 6.
Create an image. If not, then an image of card's size will be created for you when using a paint tool.
You can _long_ click on the tools, some have a menu:
Choose oval tool, line tool, then use bucket tool (this does the 'flood fill', as you say).
But that's all bitmap ...
shiftLock happens

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Color fill a shape - My head hurts!

Post by MaxV » Thu Jan 19, 2017 10:53 am

All you need is this:

########CODE to copy and paste#######
create graphic 1
set the style of graphic 1 to "oval"
set the opaque of graphic 1 to TRUE
set the linesize of graphic 1 to 1
set the foregroundcolor of graphic 1 to "BLACK"
set the arcAngle of graphic 1 to 180
set the angle of graphic 1 to 90
set the backgroundColor of graphic 1 to "BLACK"
#####END OF CODE generated by http://tinyurl.com/j8xf3xq #####

It works also with livecode 9.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply