MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

strange effect: program works only when board clicked

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93335] strange effect: program works only when board clicked
  • From: Karl Scherer <karlscherer333 at yahoo.co.nz>
  • Date: Tue, 4 Nov 2008 06:17:45 -0500 (EST)

The following notebook is a wittled-down version of a game where one can move tiles (polygons) around. 
Problem:
As the code is now, changing the "challenge" option, say from 1 to 14, changes the board setup. That is fine.
However,when I add another line of similar code,
namely the one that is commented out at the moment:
(* ,cols[[10]],Translate[tiles[[10]],p[[10]]] *)
Then changing the challenge option from 1 to 14 does not cause the board pieces to be rearranged anymore.
That rearrangement then only occurs after moving a locator.

What is going on??
Please send any answers to my email address:
k a r l s c h e r e r 3 3 3 @ y a h o o . c o . n z
(without the blanks; the blanks protect against malware looking for email addresses).

Thanks a lot, Karl
So here is the code:

 
========================================================
INITIALIZATION CODE:

snap[{p_,q_}] :={Floor[p +.5],Floor[q +.5]};  (* find nearest grid point*)
\


(* ----------- DEFINE tiles  ------------- *)
tiles={
Polygon[{{0,0},{0,1},{3,1},{3,-1},{1,-1},{1,0}}],
Polygon[{{0,0},{0,2},{2,2},{2,0}}],
Polygon[{{0,0},{0,1},{2,1},{2,-1},{1,-1},{1,0}}],
Polygon[{{0,0},{0,3},{1,3},{1,2},{2,2},{2,1},{1,1},{1,0}}],
Polygon[{{0,0},{0,3},{1,3},{1,2},{2,2},{2,1},{1,1},{1,0}}],
Polygon[{{0,0},{0,1},{3,1},{3,-1},{1,-1},{1,0}}],
Polygon[{{0,0},{0,2},{1,2},{1,3},{3,3},{3,2},{2,2},{2,1},{1,1},{1,0}}]\
,
Polygon[{{0,0},{0,1},{1,1},{1,2},{2,2},{2,0}}],
Polygon[{{0,0},{0,2},{1,2},{1,3},{2,3},{2,1},{1,1},{1,0}}],
Polygon[{{0,0},{0,1},{3,1},{3,0}}],
Polygon[{{0,0},{0,3},{2,3},{2,1},{1,1},{1,0}}],
Polygon[{{0,0},{0,1},{2,1},{2,2},{3,2},{3,0}}],

Polygon[{{0,0},{0,1},{1,1},{1,0}}]
};



(* 'locator1' = locator positions at start of some challenges *)
(* pts[] = current positons of locators *)
locators1={ 
{4.5,2.5},{2.5,3.5},{4.5,8.5},
{2.5,7.5},{7.5,3.5},{7.5,2.5},
{6.5,7.5},{1.5,5.5},{5.5,3.5},
{6.5,6.5},{3.5,5.5},{1.5,1.5}
};

(* 'locator2' = locator positions at start of some other challenges *)
locators2={{4.5,2.5},{4.5,4.5},{6.5,4.5},
{1.5,6.5},{3.5,5.5},{5.5,8.5},
{7.5,5.5},{2.5,2.5},{8.5,4.5},
{2.5,1.5},{1.5,2.5},{2.5,8.5}};

(* tile positions at start of some challenges *)
(* p = current positions of tiles *)
p1={{4,2},{2,3},{4,8},
{2,7},{7,3},{7,2},
{6,7},{1,5},{5,3},
{6,6},{3,5},{1,1}};

(* tile positions at start of some other challenges *)
p2={{4,2},{4,4},{6,4},
{1,6},{3,5},{5,8},
{7,5},{2,2},{8,4},
{2,1},{1,2},{2,8}};

cols={Cyan,Blue,Purple,Green,
Yellow,Orange,Brown,RGBColor[.8,.3,.2],
Gray,Magenta,Pink,RGBColor[.4,.0,.0],Black};

MANIPULATE:

(* reset Locators  *)
For[i=1,i<=12,i++,pts[[i]]=p[[i]]+{.5,.5}];   

If[9>=ch>1,{r[[9,3]]=13}];
If[9>=ch>2,{r[[9,4]]=13}];
If[9>=ch>3,{r[[9,5]]=13}];
If[9>=ch>4,{r[[9,6]]=13}];
If[9>=ch>5,{r[[9,7]]=13}];
If[9>=ch>6,{r[[9,8]]=13}];
If[9>=ch>7,{r[[9,9]]=13}];
If[ch==9,{r[[1,9]]=13}];

If[16>=ch>=10,{r[[9,1]]=13,r[[9,3]]=13,r[[2,9]]=13}];
If[16>=ch>=11,{r[[9,2]]=13}];
If[16>=ch>=12,{r[[9,4]]=13}];
If[16>=ch>=13,{r[[9,9]]=13}];
If[16>=ch>=14,{r[[9,8]]=13}];
If[16>=ch>=15,{r[[1,1]]=13}];
If[ch==16,{r[[1,9]]=13}];

If[ch!=chold,{
chold=ch,
If[ch<10,{p=p1,pts=locators1}],  (* first type of setup *)
If[ch>9,  {p=p2,pts=locators2}]        (* second type of setup *)
}];


Graphics[{


(* display tiles: *)
EdgeForm[Thick],
cols[[1]],Translate[tiles[[1]],p[[1]]],
cols[[2]],Translate[tiles[[2]],p[[2]]],
cols[[3]],Translate[tiles[[3]],p[[3]]],
cols[[4]],Translate[tiles[[4]],p[[4]]],
cols[[5]],Translate[tiles[[5]],p[[5]]],
cols[[6]],Translate[tiles[[6]],p[[6]]],
cols[[7]],Translate[tiles[[7]],p[[7]]],
cols[[8]],Translate[tiles[[8]],p[[8]]],
cols[[9]],Translate[tiles[[9]],p[[9]]]
(*
,
cols[[10]],Translate[tiles[[10]],p[[10]]] *)

},

PlotRange->{{.8,20.2},{.8,10.2}}    ,
ImageSize->{500,400} 
], (* end graphics *)

{{ch,chold,"challenge"},Range[16], ControlType->PopupMenu},
{{pts,locators1},{1.1,1.1},{9.9,9.9},Locator},
{{p,p1}, ControlType->None}, (* positions of handles *)
{{chold,1}, ControlType->None},

ControlPlacement->Left,
SaveDefinitions->True
]


  • Prev by Date: Re: Trinomial decics x^10+ax+b = 0; Help with Mathematica code
  • Next by Date: Re: Eliminating common factors?
  • Previous by thread: Trouble solving system of first order, two variable PDEs in
  • Next by thread: bar chart