2013-08-01 50 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