2013-10-30 9 views
5

यहां मेरा कोड थोड़ा सा पैटर्न है जो ऐसा कुछ दिखता है। (मुझे पता नहीं है कि सबसे कुशल कोड नहीं है)। अब, मैं starsanimate का उपयोग करके घूमना चाहता हूं। लेकिन मुझे यकीन नहीं है कि एक प्रोग्राम में display और animate का उपयोग कैसे करें। किसी भी सहायता की सराहना की जाएगी। धन्यवाद।हास्केल में चमक के साथ एनिमेटिंग

Gloss Image

import Graphics.Gloss 

main = display (InWindow "Gloss" (700,700) (0,0)) 
      black (picture 100) 
picture :: Float -> Picture 
picture 0 = text "Value cannot be 0" 
picture number = scale 6.5 6.5 (color rose $ drawpicture number) 

orangered, orangered2, orangered3 :: Color 
orangered = makeColor 1.0 0.251 0.0 0.7 
orangered2 = makeColor 1.0 0.251 0.0 0.5 
orangered3 = makeColor 1.0 0.251 0.0 0.3 

intervalsmall = [0,11.25,22.5,33.75,45,56.25,67.5,78.75] 
intervalbig = [0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5] 
xlist = [2,4..50] 
ylist = [0,2..48] 

squares = pictures[rotate x (line [(-50,0),(0,50),(50,0),(0,-50),(-50,0)]) | x <- intervalsmall] 
stars = pictures[rotate x ((pictures [line [(-8.5,0),(0,50),(8.5,0)],line[(0,50),(0,0)]])) | x <- intervalbig] 
grid = pictures[line [(0,y),(x,50)] | x <- xlist, y <- ylist, x-y==2] 
insidegrid = pictures[ 
    translate 0 (-50) grid, 
    rotate 90 (translate 0 (-50) grid), 
    rotate 180 (translate 0 (-50) grid), 
    rotate 270 (translate 0 (-50) grid)] 

drawpicture :: Float -> Picture 
drawpicture number = pictures [ 
    color red (pictures [circle 50,circle 8.5]), 
    line [(-50,-50),(-50,50),(50,50),(50,-50),(-50,-50)], 
    squares, 
    scale 0.7 0.7 squares, 
    scale 0.49 0.49 squares, 
    scale 0.347 0.347 squares, 
    scale 0.242 0.242 squares, 
    color orange stars, 
    color orange (scale 0.178 0.178 stars), 
    rotate 11.25 (scale 0.178 0.178 stars), 
    translate (-50) 0 grid, 
    rotate 90 (Translate (-50) 0 grid), 
    rotate 180 (Translate (-50) 0 grid), 
    rotate 270 (Translate (-50) 0 grid), 
    color orangered insidegrid, 
    color orangered2 (rotate 45 insidegrid), 
    color orangered3 (rotate 22.5 insidegrid), 
    color orangered3 (rotate 67.5 insidegrid) 
    ] 

उत्तर

4

यह अगर आप प्रत्येक दृश्य तत्व के लिए अलग से ड्रॉ कार्य आसान है, लेकिन बुनियादी जवाब है: चेतन करने के लिए यह सिर्फ animate समारोह और rotate छवि घटकों आप इच्छा के लिए "चाल" का उपयोग करें:

import Graphics.Gloss 

main = animate (InWindow "Gloss" (700,700) (0,0)) 
      black picture 

picture :: Float -> Picture 
picture 0 = text "Value cannot be 0" 
picture number = scale 6.5 6.5 (color rose $ drawpicture number) 

orangered, orangered2, orangered3 :: Color 
orangered = makeColor 1.0 0.251 0.0 0.7 
orangered2 = makeColor 1.0 0.251 0.0 0.5 
orangered3 = makeColor 1.0 0.251 0.0 0.3 

intervalsmall = [0,11.25,22.5,33.75,45,56.25,67.5,78.75] 
intervalbig = [0,22.5,45,67.5,90,112.5,135,157.5,180,202.5,225,247.5,270,292.5,315,337.5] 
xlist = [2,4..50] 
ylist = [0,2..48] 

squares = pictures[rotate x (line [(-50,0),(0,50),(50,0),(0,-50),(-50,0)]) | x <- intervalsmall] 
stars = pictures[rotate x ((pictures [line [(-8.5,0),(0,50),(8.5,0)],line[(0,50),(0,0)]])) | x <- intervalbig] 
grid = pictures[line [(0,y),(x,50)] | x <- xlist, y <- ylist, x-y==2] 
insidegrid = pictures[ 
    translate 0 (-50) grid, 
    rotate 90 (translate 0 (-50) grid), 
    rotate 180 (translate 0 (-50) grid), 
    rotate 270 (translate 0 (-50) grid)] 

rotVal :: Float -> Float 
rotVal x = x - (x/(2*pi)) 

drawpicture :: Float -> Picture 
drawpicture number = pictures [ 
    rot $ color red (pictures [circle 50,circle 8.5]), 
    line [(-50,-50),(-50,50),(50,50),(50,-50),(-50,-50)], 
    rot $ squares, 
    rot $ scale 0.7 0.7 squares, 
    rot $ scale 0.49 0.49 squares, 
    rot $ scale 0.347 0.347 squares, 
    rot $ scale 0.242 0.242 squares, 
    rot $ color orange stars, 
    rot (color orange (scale 0.178 0.178 stars)), 
    rot (rotate 11.25 (scale 0.178 0.178 stars)), 
    translate (-50) 0 grid, 
    rotate 90 (Translate (-50) 0 grid), 
    rotate 180 (Translate (-50) 0 grid), 
    rotate 270 (Translate (-50) 0 grid), 
    rot $ color orangered insidegrid, 
    rot $ color orangered2 (rotate 45 insidegrid), 
    rot $ color orangered3 (rotate 22.5 insidegrid), 
    rot $ color orangered3 (rotate 67.5 insidegrid) 
    ] 
    where rot = rotate (rotVal number) 
0

यह सब आप के लिए लिखने के लिए बहुत ज्यादा है, लेकिन तुम सिर्फ अपनी तस्वीर कार्य करने के लिए एक और तर्क यह है कि एक Float है और समय का प्रतिनिधित्व करता जोड़ने के लिए। तो display को animate द्वारा प्रतिस्थापित किया जाएगा। इसलिए।

main = animate (InWindow "Gloss" (700,700) (0,0)) 
      black (picture 100) 

picture :: Float -> Float -> Picture 
picture number time = -- whatever you have to do 

आपको इस बार पैराम लेने के लिए अपने मदद ड्राइंग कार्यों को बदलना होगा। आइए मान लें कि आप पूरे विचार को 5 सेकंड में घुमाने के लिए चाहते हैं, आप इस बार गुणा कर सकते हैं और कोण angle = time*(pi*2/5) प्राप्त कर सकते हैं, तो आप केंद्र से नए एक्स और वाई पदों की गणना करने के लिए ट्रिगर फ़ंक्शंस के लिए इस कोण का उपयोग कर सकते हैं।

संबंधित मुद्दे