2013-08-01 48 views
1

欣赏任何帮助,想出一个Livecode脚本块来绘制和填充一组等边三角形。在Livecode中绘制,填充和分组三角形的脚本?

我正在开发一款开源应用程序,可帮助人们用分形模式创建和分享故事。

一个主要挑战是绘制三角形,将表示一个故事的下列元素:

  • 吸引
  • 挑战
  • 机会(状态改变来解决张力)
  • 策略
  • 测试
  • 决定

以上六个标准故事元素中的每一个都将在应用程序中显示为等边三角形。反过来,每个元素都将与独特的颜色相关联 - 黄色,红色,橙色,紫色,蓝色或绿色。

我很想用一个Livecode脚本来绘制六个相合的三角形 - 非常像馅饼切片 - 形成代表整个叙述的六边形。

每个彩色片段的透明度(混合水平)将指示故事的作者或被邀请的评论者认为故事元素完整的程度。

我的希望是拿出在Livecode一个脚本,将:

  • 迅速地将6个三角形,形成六边形

  • 填充每个三角形,其相关联的颜色(每种颜色会具有几乎透明的90%的初始混合水平)

  • 基于其填充颜色的名称为六个三角形中的每一个分配唯一短名称

  • 将这六个三角形分组,以便它们可以一起拖到屏幕上的新位置。

是否有任何脚本(或块)可以帮助解决这个问题?深深感谢任何示例代码或链接,以帮助缩短我的Livecode学习曲线。

最佳,

马克·弗雷泽

======最新进展! ====== [8月2日,6点东部]

我刚刚发现和改编大学劳埃德Rieber多边形生成脚本。格鲁吉亚创造六边形。有没有办法调整它,以便它可以创建一个等边三角形,然后可以复制并旋转以填充六边形?

on mouseUp 
global tpoints 
if exists(grc "HexagonCanvas" of this card) then delete grc "HexagonCanvas" 
lock screen 
create grc "HexagonCanvas" 
set the loc of grc "HexagonCanvas" to "140,140" 
set the opaque of grc "HexagonCanvas" to true 
-- resize the new grc 
get the rect of grc "HexagonCanvas" 
add 80 to item 4 of it 
set the rect of grc "HexagonCanvas" to it 
put the topleft of grc "HexagonCanvas" into TL 
put the topright of grc "HexagonCanvas" into TR 
put the bottomleft of grc "HexagonCanvas" into BL 
put the bottomright of grc "HexagonCanvas" into BR 
put the width of grc "HexagonCanvas" into twidth 
put the height of grc "HexagonCanvas" into theight 
put trunc(twidth/4) into twidthquart 
put trunc(theight/2) into theighthalf 
#=========set the points for the "free" hexagon polygon================== 
put empty into tpoints 
put (item 1 of TL + twidthquart, item 2 of TL) into tpoints 
# for the first line of tpoints "put into" 
put Cr& (item 1 of TL, item 2 of TL + theighthalf) after tpoints 
put CR& (item 1 of BL + twidthquart, item 2 of BL) after tpoints 
put CR& (item 1 of BR - twidthquart, item 2 of BR) after tpoints 
put Cr& (item 1 of BR, item 2 of BR - theighthalf) after tpoints 
put CR& (item 1 of TR - twidthquart, item 2 of TR) after tpoints 
put CR& (item 1 of TL + twidthquart, item 2 of TL) after tpoints 
set the points of grc "HexagonCanvas" to tpoints 
set the style of grc "HexagonCanvas" to "polygon" 
set the backgroundColor of grc "HexagonCanvas" to blue 
set the blendlevel of grc "HexagonCanvas" to "60" 
choose browse tool 
end mouseUp 
+0

我已经添加了下面的代码绘制6个triagles。看看它。 –

回答

0

参考

http://en.wikipedia.org/wiki/Equilateral_triangle

迭代步骤

我把你发现的脚本,并与一些光调整它工作得很好。有一个

polygon polygonName, px, py, pColor 

脚本被称为4次通过鼠标上的脚本。它以不同的颜色绘制4个六边形。

多边形脚本不符合其名称,因为它只能绘制六边形。

然后是一个使用三角形脚本六次的mouseup脚本。

on mouseup 
    polygon "hex1", 100, 300, "green" 
    polygon "hex2", 240, 300, "yellow" 
    polygon "hex3", 380, 300, "red" 
    polygon "hex4", 520, 300, "brown" 
end mouseup 

on polygon polygonName, px, py, pColor 
    global tpoints 
    local TL 
    local TR 
    local BL 
    local BR 
    local twidth 
    local theight 
    local twidthquart 
    local theighthalf 
if exists(grc polygonName of this card) then delete grc polygonName 
lock screen 
create grc polygonName 

set the loc of grc polygonName to px,py 

set the opaque of grc polygonName to true 
-- resize the new grc 
get the rect of grc polygonName 
add 80 to item 4 of it 
set the rect of grc polygonName to it 
put the topleft of grc polygonName into TL 
put the topright of grc polygonName into TR 
put the bottomleft of grc polygonName into BL 
put the bottomright of grc polygonName into BR 
put the width of grc polygonName into twidth 
put the height of grc polygonName into theight 
put trunc(twidth/4) into twidthquart 
put trunc(theight/2) into theighthalf 
#=========set the points for the "free" hexagon polygon================== 
put empty into tpoints 
put (item 1 of TL + twidthquart, item 2 of TL) into tpoints 
# for the first line of tpoints "put into" 
put Cr& (item 1 of TL, item 2 of TL + theighthalf) after tpoints 
put CR& (item 1 of BL + twidthquart, item 2 of BL) after tpoints 
put CR& (item 1 of BR - twidthquart, item 2 of BR) after tpoints 
put Cr& (item 1 of BR, item 2 of BR - theighthalf) after tpoints 
put CR& (item 1 of TR - twidthquart, item 2 of TR) after tpoints 
put CR& (item 1 of TL + twidthquart, item 2 of TL) after tpoints 
set the points of grc polygonName to tpoints 
set the style of grc polygonName to "polygon" 
set the backgroundColor of grc polygonName to pColor 
set the blendlevel of grc polygonName to "60" 
choose browse tool 
end polygon 

下一个迭代步骤

要继续各种方式都是可能的。

一个容易遵循的方法是修改多边形脚本,以便它在三角形而不是六角形上工作。作为参数,它需要的三角形的位置(以下为“钟盘公约或给予以度扇区)

坐标

​​

R =半径 H =高度

H * H + (R/2)×(R/2)= R * R

代码其中提请6个三角形

`

on mouseUp 
    global tOffset 
    put 140 into tOffset 
    triangle "triangle1", -50,100, 0,0, -100, 0, "red" 
    triangle "triangle2", 0,0, -50, 100, 50,100, "green" 
    triangle "triangle3", 50, 100, 100, 0, 0,0, "blue" 
    triangle "triangle4", 0, 0, 100, 0, 50, -100, "yellow" 
    triangle "triangle5", 0, 0, 50, -100, -50, -100, "orange" 
    triangle "triangle6", 0, 0, -50, -100, -100, 0, "purple" 
end mouseUp 


on triangle polygonName, pax, pay, pbx, pby, pcx, pcy, pColor 

    global tpoints 
    global tOffset 

    if exists(grc polygonName of this card) then delete grc polygonName 

    lock screen 

    create grc polygonName 
    set the loc of grc polygonName to pax,pay 
    set the opaque of grc polygonName to true 

    put empty into tpoints 

    put (tOffset+pax, tOffset+pay) into tpoints 

    put Cr& (tOffset+pbx, tOffset+pby) after tpoints 

    put Cr& (tOffset+pcx, tOffset+pcy) after tpoints 

    set the points of grc polygonName to tpoints 

    set the style of grc polygonName to "polygon" 
    set the backgroundColor of grc polygonName to pColor 
    set the blendlevel of grc polygonName to "20" 

    choose browse tool 
end triangle 

维基

我做了这个一个社区维基答案,使人们可以在更新的代码粘贴容易。

1

这其中最难的部分是即时绘图。你当然可以编写一个例程来创建你的六边形馅饼,但是最好画一次,只显示或隐藏它。

事物本身将成为一组六个三角形,每一个都可以得到解决,并已其属性设置,颜色,blendLevel等

如果你需要这个小工具的多个副本,您可以克隆组,并且随意重命名它及其三角形组件。

一个警告。如果按照这种方式进行操作,则必须意识到,对于所有对象类中的单独组,关键字“last”不稳定。因此,您引用这个新组的能力(将最后一组的名称设置为“yourNewGroupname”)受到限制。有一个解决方法,使用模板组,但是,工作得很好。我建议您阅读“last”下的字典中的用户注释:

----引用组时,“last”关键字不稳定。因此,如果创建了多个组,则引用“最后”组可能不会返回最后创建的组。使用“templateGroup”是一种解决方法,因为在创建新组时,可以将templateGroup的名称设置为唯一的名称,并且能够按名称查找最后一个组。此外,使用适当的脚本捕获“newGroup”消息可用于查找最后一组。

希望这有助于...

编辑。

您是否熟悉相关属性? “backColor”设置颜色,“blendLevel”设置,以及blendLevel等?你有没有创建过一个三角形的图形,并命名它?你有没有分组对象?

+0

何时不稳定? – Jacque

+0

很难依赖组的“最后”标识符。大多数情况下,当处理其他组中的团队时,或者当他们被引擎自动分层时(例如在使用“停止编辑”后)。 – BvG

+0

克雷格,非常感谢您的见解。到目前为止,我已经成功地绘制下面的脚本六边形 - 在dragSpeed设置为0 拖 上mouseUp事件 选择行工具 从200,200到从300267 300267 拖动,从300367 300367 拖动200433 阻力从200433从100367 100367 拖动100267 拖动从100267至200,200 选择浏览工具 结束mouseUp事件 但我不明白如何命名并保存新的图形为多边形,所以我可以做的其余部分: - 将grc“HexagonCanvas”的backgroundColor设置为蓝色 - 将grc“HexagonCanvas”的混合级别设置为“60” –

0

非常勤奋。真。

我打算使用多边形工具创建一个三角形图形。您可以将图形的边数设置为3并命名为“t1”。您可能需要将其调整为等边显示。这是一个完整的对象,可以复制五次。每个新的对象都可以相应地命名(“t2”,“t3”等)并旋转,以便将它们组装到一个漂亮的六角形中。

现在您可以根据需要设置每个图形的backColor和blendLevel。确保每个图形的“不透明”属性设置为“true”。如果你将六个分组,你可以克隆新的组,但你必须管理后代三角形的名称。

回到你以前的努力。你可以看到,即使你使用直线创建了一个漂亮的图形,也不会有简单的方法来隔离单独的三角形部分。多边形对象很好地修复了这个问题。

Craig