Skip to content

Instantly share code, notes, and snippets.

@dela3499
Created September 7, 2015 04:02
Show Gist options
  • Save dela3499/6fc6c6ad1fdf61f31122 to your computer and use it in GitHub Desktop.
Save dela3499/6fc6c6ad1fdf61f31122 to your computer and use it in GitHub Desktop.
Radial Display
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Window
import Signal
import Color exposing (..)
main =
Signal.map (view x) Window.dimensions
view: List (List Float) -> (Int, Int) -> Element
view values (w, h) =
let myRadius =
(toFloat w)
n =
List.length values
theta =
(degrees (360 / (toFloat n)))
slices =
List.map (viewSlice myRadius theta) values
rotations =
List.map (\i -> (toFloat i) * theta) [0 .. n - 1]
translations =
List.map (\angle -> fromPolar (myRadius / 2, angle)) rotations
rotatedSlices =
List.map3
(\slice rot trans -> slice |> rotate rot)
slices rotations translations
in
collage w h rotatedSlices
colorize: Float -> Color
colorize value =
greyscale value
viewSlice: Float -> Float -> List Float -> Form
viewSlice r theta values =
let n =
List.length values
myHeight =
(r - 5) / (toFloat n)
radii =
List.map (\i -> 5 + (toFloat i) * myHeight) [0 .. n - 1]
widths =
List.map (\radius -> radius * theta * 1.2) radii
colors =
List.map greyscale values
in
group (List.map3 (viewElem myHeight) widths radii colors)
viewElem: Float -> Float -> Float -> Color -> Form
viewElem myHeight myWidth y myColor =
rect myWidth myHeight
|> filled myColor
|> move (0, y + (myHeight / 2))
x = [[ 0.78850164, 0.78567492, 0.66518608, 0.46202997, 0.56305188,
0.4180357 , 0.66174217, 0.04651411, 0.38450637, 0.01277796,
0.89161334, 0.38702346, 0.12734916, 0.19461942, 0.48310085,
0.59757723, 0.06882845, 0.78342893, 0.05192115, 0.7534541 ,
0.40624794, 0.65135081, 0.3843746 , 0.52720578, 0.96414063,
0.52831548, 0.9747363 , 0.54637277, 0.88159052, 0.16201127,
0.94160658, 0.40024535, 0.77190802, 0.12696357, 0.76500495,
0.65935472, 0.80558971, 0.68607086, 0.62767428, 0.4608355 ,
0.56147242, 0.80610973, 0.4034452 , 0.89822858, 0.65921534,
0.59238572, 0.47865374, 0.21989549, 0.74373552, 0.04828633],
[ 0.92983901, 0.6539017 , 0.77010575, 0.43565265, 0.66456893,
0.05124884, 0.13018082, 0.02628051, 0.89995854, 0.82903107,
0.22270383, 0.00290627, 0.00725543, 0.5426323 , 0.94379156,
0.14606663, 0.61146889, 0.0061845 , 0.80081742, 0.8838196 ,
0.83707064, 0.33686566, 0.94033699, 0.45705589, 0.16324231,
0.24545397, 0.08444439, 0.64830884, 0.94587501, 0.16856232,
0.00565126, 0.74900741, 0.76780512, 0.72053308, 0.53742492,
0.65070348, 0.43697895, 0.49261408, 0.32959059, 0.70358305,
0.69978946, 0.38557076, 0.60070632, 0.88010589, 0.57113097,
0.7959642 , 0.42118635, 0.40162576, 0.11835118, 0.6333864 ],
[ 0.01404831, 0.34071367, 0.38525729, 0.50731677, 0.91263987,
0.80373931, 0.1201633 , 0.19676922, 0.70857649, 0.46011478,
0.92756162, 0.97073815, 0.53610651, 0.78140115, 0.16488027,
0.46475329, 0.99622419, 0.04455459, 0.74331273, 0.70146784,
0.43273814, 0.96827353, 0.6837484 , 0.44462024, 0.00181599,
0.25962986, 0.3637457 , 0.06753365, 0.71862356, 0.93761418,
0.53617878, 0.52833279, 0.15540535, 0.99734548, 0.72743805,
0.82546148, 0.23700762, 0.94072105, 0.76884864, 0.57119625,
0.76376935, 0.10297796, 0.10425963, 0.98272903, 0.68020876,
0.7502741 , 0.82577228, 0.67796996, 0.34609941, 0.28956496],
[ 0.6779997 , 0.2231648 , 0.63960612, 0.58689333, 0.30677327,
0.44915696, 0.13590896, 0.12465884, 0.25639806, 0.71195867,
0.87830095, 0.57328041, 0.51088325, 0.5803485 , 0.40248129,
0.09403778, 0.28530844, 0.92842585, 0.24062789, 0.1020987 ,
0.81980545, 0.86007718, 0.09884644, 0.11935142, 0.84459537,
0.17643856, 0.25820605, 0.24393548, 0.24086763, 0.56345729,
0.14346392, 0.65017255, 0.11951007, 0.87509566, 0.52279889,
0.59876313, 0.17327608, 0.4537816 , 0.09961001, 0.61975549,
0.12986071, 0.35546058, 0.19378116, 0.44844858, 0.31361334,
0.2147325 , 0.15576017, 0.904741 , 0.17591396, 0.30044356],
[ 0.4052892 , 0.12238506, 0.67243259, 0.72416013, 0.2947762 ,
0.81783213, 0.32578277, 0.74442254, 0.96490662, 0.48441598,
0.18557121, 0.2464936 , 0.62939075, 0.27550551, 0.36592435,
0.04335992, 0.47301063, 0.4122946 , 0.50178897, 0.03601984,
0.31107492, 0.86146625, 0.67595214, 0.34448798, 0.56517758,
0.89378867, 0.03078774, 0.55171669, 0.54548501, 0.52022409,
0.80328585, 0.16171931, 0.09331273, 0.58208213, 0.50031265,
0.8309553 , 0.32027844, 0.72651823, 0.63397003, 0.17745539,
0.59008389, 0.05071288, 0.83072499, 0.76507051, 0.58546167,
0.47900437, 0.43787052, 0.7103099 , 0.18193437, 0.20822732],
[ 0.83398534, 0.79804627, 0.81793696, 0.61864831, 0.92654325,
0.48574829, 0.05529399, 0.82401316, 0.3633606 , 0.81057728,
0.18425291, 0.46784416, 0.30382154, 0.84324378, 0.18235222,
0.72303786, 0.29071995, 0.37587366, 0.57435479, 0.04368573,
0.0655708 , 0.25691851, 0.76025344, 0.86910863, 0.23013374,
0.71874187, 0.97241918, 0.60197031, 0.85264951, 0.7952477 ,
0.16143564, 0.12711599, 0.11524302, 0.27766358, 0.47006495,
0.5686808 , 0.45744375, 0.72135812, 0.85865356, 0.65268204,
0.84567992, 0.32182554, 0.70506918, 0.73612165, 0.495408 ,
0.07970116, 0.58098382, 0.32050293, 0.1155291 , 0.38560602],
[ 0.54536514, 0.49674408, 0.8600775 , 0.96101712, 0.85862277,
0.68062288, 0.69783472, 0.84395855, 0.47004808, 0.53977092,
0.26140435, 0.51505805, 0.89295236, 0.94586574, 0.97609924,
0.13323713, 0.94517086, 0.13428643, 0.42705979, 0.53348015,
0.13933038, 0.02930957, 0.4088558 , 0.48270344, 0.95599553,
0.12366773, 0.44970958, 0.65308181, 0.89947809, 0.04768237,
0.44401825, 0.87235852, 0.4519052 , 0.48169752, 0.20778223,
0.49690265, 0.15597296, 0.3352125 , 0.40383625, 0.76125587,
0.63625961, 0.87388411, 0.58379994, 0.36299466, 0.86959998,
0.61672271, 0.27185154, 0.2541064 , 0.94513975, 0.4575825 ],
[ 0.82202751, 0.44145732, 0.7608861 , 0.47384497, 0.54503419,
0.28216248, 0.95320514, 0.36274755, 0.94292782, 0.793087 ,
0.28929188, 0.34577497, 0.05423201, 0.53532173, 0.17492978,
0.79778958, 0.88755894, 0.69562477, 0.83523813, 0.38732087,
0.1272515 , 0.2260504 , 0.68209555, 0.90339316, 0.68070205,
0.72060844, 0.67189931, 0.26812377, 0.88246145, 0.97998925,
0.15234512, 0.65257338, 0.35946598, 0.52336726, 0.27934403,
0.83166743, 0.35470187, 0.67660895, 0.95752452, 0.98892133,
0.76109701, 0.51699526, 0.93806601, 0.63609705, 0.2139607 ,
0.54748172, 0.52997784, 0.02009588, 0.6386041 , 0.41397525],
[ 0.1706418 , 0.30019973, 0.54426774, 0.9701519 , 0.27077796,
0.40454545, 0.85205766, 0.95945558, 0.42667216, 0.09585835,
0.52474878, 0.15136556, 0.73383294, 0.46309038, 0.79381815,
0.76144058, 0.6985866 , 0.40959273, 0.22714922, 0.01391129,
0.91006269, 0.61967314, 0.5177921 , 0.20346065, 0.63106722,
0.31588465, 0.023599 , 0.32114859, 0.43327568, 0.57210091,
0.42401258, 0.61753713, 0.7583835 , 0.38048512, 0.54644394,
0.08077685, 0.64817948, 0.89881034, 0.29265002, 0.53819616,
0.52528905, 0.47554468, 0.98941814, 0.37363244, 0.20061467,
0.95237727, 0.92300333, 0.5615016 , 0.95282381, 0.43530029],
[ 0.9170948 , 0.15178519, 0.27721321, 0.61829106, 0.48384272,
0.20347145, 0.28598081, 0.02371391, 0.37825494, 0.2466062 ,
0.71118802, 0.56019481, 0.24191478, 0.60038427, 0.40458801,
0.69502993, 0.01545253, 0.06323693, 0.29465249, 0.1974177 ,
0.85397113, 0.9878806 , 0.74924048, 0.03306747, 0.38329307,
0.55282875, 0.77905045, 0.93386959, 0.18114138, 0.50604074,
0.59642451, 0.20141842, 0.26386674, 0.31399353, 0.35591548,
0.0563152 , 0.58255527, 0.7682376 , 0.66259949, 0.01174781,
0.96690939, 0.2570097 , 0.66292666, 0.81552472, 0.52769143,
0.49682879, 0.20254036, 0.28423896, 0.3473782 , 0.10692788]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment