From 7620a054f4dee0c0e307554bca0ecddd8855ea0e Mon Sep 17 00:00:00 2001 From: Chris Rees Date: Mon, 29 Aug 2016 22:08:50 -0400 Subject: [PATCH] Add functions to aid in drawing circles --- src/.sdl_renderer.erl.swp | Bin 0 -> 28672 bytes src/sdl_renderer.erl | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/.sdl_renderer.erl.swp diff --git a/src/.sdl_renderer.erl.swp b/src/.sdl_renderer.erl.swp new file mode 100644 index 0000000000000000000000000000000000000000..3c1f116309cf34a1a63380a09afee124dfcefdd5 GIT binary patch literal 28672 zcmeI4ZHy#E8OIwukOe`bCPs-++#TKw*ZT?tva+kQyK}c=c4wBJ**A`5oSo_29d2%V z=nbBTt(k7(K}uRk%{^P6k5T^~P1E83>% z(D4p`qmyGZlbP(?M6Unxfu4$0EL0-T_!2L$ch#~FI<-R4>@_RpBW1hSbV`+hUdJx> z;z!;#t0mJm?H<#PE+(>UbxD3mm9 z2Irkl6MMY>Z_NK6`>>`x0vr$rFP@`m&x7xSE5YgDp|g<=V<uY1&KR*WgL;bMRyE zJ#Ygkfeg45d>WhvUOP+Eo&vuBKLpWBU=R2VI1~K!3{86-+y;(@f z7D65cUj@@32j0Qr#w*}Ka1+P^1H6Srkw?H!zydfGJcWgh--ElsZJ+{5pa^z>chL@i z0{4QOz>T0AQ2RWK#gGTUqoAu~7gqB%t6X)Rm?1(YbT-8g#C5I9`^ARXp>m05%NNUb zv0}y!EcCFs9%d9u<+`J@d7bs?yfBgO7dFRJy^L|zJ*;&*HM7X%%#C1;SX^f?#auS+ zc0Z{EW*ubLGemg|nzn5rYY#lJ&7xU8Y_el}^40QE-d(ZHLJ46YZhnu>4AWhw6R~CR zvPbLU(ISHgB`LUOGgu@xTdtO@Rh^{}JaR;5`znQH2QqlsqEpGEE);#tI;b<>k@c{J zp4XxzicneQbq#u(kh=#O1?87uLM*-zhlit9z3RerUK8J0N5goIEW^)g{gCh^U$P;E z?VwbxNN4#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QjmWW1{6R)C>x$hJhO-`bJ8b zd<%7kkF4nXn+0(zL8Sjyd{XAskZ;!698^MYy*p%xus-m4QPkiP{m|Cdy$%-i_~J@F z;PJNOn{K~gS#D45w$>o|gkN*>3y#W<>LME?`XWo2WSh6Oi!|$$<$?s ztl#P`(!m0;;K5tg5ci?R`i8f>(JmOmFIbj)ySoUV^T>U~n?+$9;r6sk4hb!?$%Z#) zQ`^_Qd99(I5->cR7G-tE{?XQcU!ZV3q7#JelLrbp3`QzQR?s_rd*0LYDrvc@ebcu| z4Qc4*lFfb}8lJDS8O^IJw3a8j?#7uS-00X7-qX#5=KnWiZhse``9G$W{O`%eF|n^U zN&%&SQa~x76i^B%1(X6x0i}RaKq;UUPztkSZfIy SK(qi>C esdl2:create_renderer(Window, Index, Flags), receive {'_nif_thread_ret_', Ret} -> Ret end. +-spec draw_circle(renderer(), integer(), integer(), integer()) -> ok | sdl:error(). +draw_circle(Renderer, X, Y, Radius) -> + Points = midpoint_circle(X, Radius, Y, 0, 0), + draw_points(Renderer, Points). + +-spec midpoint_circle(integer(), integer(), integer(), integer(), integer()) -> list(). +midpoint_circle(X0, X, Y0, Y, Err) when X >= Y -> + Points = [#{x => X0 + X, y => Y0 + Y}, #{x => X0 + Y, y => Y0 + X}, #{x => X0 - Y, y => Y0 + X}, + #{x => X0 - X, y => Y0 + Y}, #{x => X0 - X, y => Y0 - Y}, #{x => X0 - Y, y => Y0 - X}, + #{x => X0 + Y, y => Y0 - X}, #{x => X0 + X, y => Y0 - Y}], + New_Y = Y + 1, + Tmp_Err = Err + 1 + (2 * New_Y), + Midpoint_Values = determine_midpoint_values(X, Tmp_Err), + Points ++ midpoint_circle(X0, maps:get(x, Midpoint_Values), Y0, New_Y, maps:get(err, Midpoint_Values)); + +midpoint_circle(_, _, _, _, _) -> + []. + +-spec determine_midpoint_values(integer(), integer()) -> map(). +determine_midpoint_values(X, Err) when 2 * (Err - X) + 1 > 0 -> + New_X = X - 1, + New_Err = Err + 1 - (2 * New_X), + #{x => New_X, err => New_Err}; + +determine_midpoint_values(X, Err) -> + #{x => X, err => Err}. + -spec draw_line(renderer(), point(), point()) -> ok | sdl:error(). draw_line(Renderer, #{x:=X1, y:=Y1}, #{x:=X2, y:=Y2}) -> draw_line(Renderer, X1, Y1, X2, Y2).