Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,39 @@
fastgraphics
clg
color red
call DrawCircle(150,100,100)
refresh
color blue
call DrawCircle(200,200,50)
refresh
#Function DrawCircle
#1st param = X-coord of center
#2nd param = Y-coord of center
#3rd param = radius
Function DrawCircle(x0,y0,radius)
x=radius
y=0
decisionOver2=1-x
while x>=y
plot( x + x0, y + y0)
plot( y + x0, x + y0)
plot(-x + x0, y + y0)
plot(-y + x0, x + y0)
plot(-x + x0, -y + y0)
plot(-y + x0, -x + y0)
plot( x + x0, -y + y0)
plot( y + x0, -x + y0)
y++
if decisionOver2<=0 then
decisionOver2+=2*y+1
else
x--
decisionOver2+=2*(y-x)+1
end if
end while
return 0
End Function

View file

@ -0,0 +1,72 @@
@echo off
setlocal enabledelayedexpansion
%== Initializations ==%
set width=50
set height=30
set /a allowance=height+2
mode %width%,%allowance%
echo Rendering...
set "outp="
for /l %%i in (1,1,%height%) do (
for /l %%j in (1,1,%width%) do (
set "c[%%i][%%j]= "
)
)
%== Set the parameters for making circle ==%
call :DrawCircle 20 20 10
call :DrawCircle 10 30 15
%== Output result ==%
for /l %%i in (1,1,%height%) do (
for /l %%j in (1,1,%width%) do (
set "outp=!outp!!c[%%i][%%j]!"
)
)
cls
echo !outp!
pause>nul
exit /b
%== The main function ==%
:DrawCircle
set x0=%1
set y0=%2
set radius=%3
set x=!radius!
set y=0
set /a decisionOver2 = 1 - !x!
:circle_loop
if !x! geq !y! (
set /a "hor=x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
set /a y+=1
if !decisionOver2! leq 0 (
set /a "decisionOver2 = !decisionOver2! + (2 * y^) + 1"
) else (
set /a x-=1
set /a "decisionOver2 = !decisionOver2! + 2 * (y - x^) + 1"
)
goto circle_loop
)
goto :EOF

View file

@ -0,0 +1,26 @@
(defn draw-circle [draw-function x0 y0 radius]
(letfn [(put [x y m]
(let [x+ (+ x0 x)
x- (- x0 x)
y+ (+ y0 y)
y- (- y0 y)
x0y+ (+ x0 y)
x0y- (- x0 y)
xy0+ (+ y0 x)
xy0- (- y0 x)]
(draw-function x+ y+)
(draw-function x+ y-)
(draw-function x- y+)
(draw-function x- y-)
(draw-function x0y+ xy0+)
(draw-function x0y+ xy0-)
(draw-function x0y- xy0+)
(draw-function x0y- xy0-)
(let [[y m] (if (pos? m)
[(dec y) (- m (* 8 y))]
[y m])]
(when (<= x y)
(put (inc x)
y
(+ m 4 (* 8 x)))))))]
(put 0 radius (- 5 (* 4 radius)))))

View file

@ -0,0 +1,10 @@
(let [circle-points (atom [])]
(letfn [(draw-fn [x y]
(swap! circle-points #(conj % [x y])))]
(draw-circle draw-fn 10 10 7))
(let [empty-grid (vec (repeat 20 (vec (repeat 20 " "))))
grid (reduce (fn [grid xy] (assoc-in grid xy "x"))
empty-grid
@circle-points)]
(doseq [line grid]
(println (clojure.string/join line)))))

View file

@ -1,43 +1,43 @@
/*REXX pgm plots 3 circles using midpoint/Bresenham's circle algorithm. */
@. = '·' /*fill the array with middle-dots*/
minX=0; maxX=0; minY=0; maxY=0 /*initialize minimums & maximums.*/
call drawCircle 0, 0, 8, '#' /*plot 1st circle with pound char*/
call drawCircle 0, 0, 11, '$' /* " 2nd " " dollar " */
call drawCircle 0, 0, 19, '@' /* " 3rd " " commer. at*/
border=2 /*BORDER: shows N extra grid pts*/
minX=minX-border*2; maxX=maxX+border*2 /*adjust min&max X to show border*/
minY=minY-border ; maxY=maxY+border /* " " " Y " " " */
if @.0.0==@. then @.0.0='' /*maybe define plot's axis origin*/
/* [↓] define horizontal grid. */
do gx=minX to maxX; if @.gx.0==@. then @.gx.0=''; end /*gx*/
do gy=minY to maxY; if @.0.gy==@. then @.0.gy=''; end /*gy*/
/* [↑] define the vertical grid.*/
do y=maxY by -1 to minY; aRow= /* [↓] draw grid from top to bot.*/
do x=minX to maxX /* [↓] " " " left──►right*/
aRow=aRow || @.x.y /*build a grid row, char by char.*/
end /*x*/ /* [↑] a grid row should be done*/
say aRow /*display signal row of the grid.*/
/*REXX program plots three circles using midpoint/Bresenham's circle algorithm*/
@. = '·' /*fill the array with middle─dots char.*/
minX=0; maxX=0; minY=0; maxY=0 /*initialize the minimums and maximums.*/
call drawCircle 0, 0, 8, '#' /*plot 1st circle with pound character.*/
call drawCircle 0, 0, 11, '$' /* " 2nd " " dollar " */
call drawCircle 0, 0, 19, '@' /* " 3rd " " commercial at. */
border=2 /*BORDER: shows N extra grid points.*/
minX=minX-border*2; maxX=maxX+border*2 /*adjust min and max X to show border*/
minY=minY-border ; maxY=maxY+border /* " " " " Y " " " */
if @.0.0==@. then @.0.0='' /*maybe define the plot's axis origin. */
/*define the plot's horizontal grid──┐ */
do h=minX to maxX; if @.h.0==@. then @.h.0=''; end /* ◄───────────┘ */
do v=minY to maxY; if @.0.v==@. then @.0.v=''; end /* ◄──────────┐ */
/*define the plot's vertical grid───┘ */
do y=maxY by -1 to minY; aRow= /* [↓] draw grid from top ──► bottom.*/
do x=minX to maxX /* [↓] " " " left ──► right. */
aRow=aRow || @.x.y /*build a grid row, one char at a time.*/
end /*x*/ /* [↑] a grid row should be finished. */
say aRow /*display a single row of the grid. */
end /*y*/
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────────DRAWCIRCLE subroutine──────────────*/
drawCircle: procedure expose @. minX maxX minY maxY
parse arg xx,yy,r,plotChar; f=1-r; fx=1; fy=-2*r; y=r
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
drawCircle: procedure expose @. minX maxX minY maxY /* [↓] Y is defined as R*/
parse arg xx,yy,r 1 y,plotChar; f=1-r; fx=1; fy=-2*r /*get the X,Y coördinates*/
do x=0 while x<y /*════════════════════════════════════════*/
if f>=0 then do; y=y-1; fy=fy+2; f=f+fy; end
fx=fx+2; f=f+fx
call plotPoint xx+x, yy+y, plotChar
call plotPoint xx+y, yy+x, plotChar
call plotPoint xx+y, yy-x, plotChar
call plotPoint xx+x, yy-y, plotChar
call plotPoint xx-y, yy+x, plotChar
call plotPoint xx-x, yy+y, plotChar
call plotPoint xx-x, yy-y, plotChar
call plotPoint xx-y, yy-x, plotChar
end /*x*/ /* [↑] place plot points ══► plot*/
do x=0 while x<y /*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒*/
if f>=0 then do; y=y-1; fy=fy+2; f=f+fy; end /**/
fx=fx+2; f=f+fx /**/
call plotPoint xx+x, yy+y /**/
call plotPoint xx+y, yy+x /**/
call plotPoint xx+y, yy-x /**/
call plotPoint xx+x, yy-y /**/
call plotPoint xx-y, yy+x /**/
call plotPoint xx-x, yy+y /**/
call plotPoint xx-x, yy-y /**/
call plotPoint xx-y, yy-x /**/
end /*x*/ /* [↑] place plot points ══► plot.▒▒▒▒▒▒▒▒▒▒▒▒▒*/
return
/*──────────────────────────────────PLOTPOINT subroutine────────────────*/
plotPoint: procedure expose @. minX maxX minY maxY
parse arg xx,yy,@.xx.yy; minX=min(minX,xx); maxX=max(maxX,xx)
minY=min(minY,yy); maxY=max(maxY,yy)
/*────────────────────────────────────────────────────────────────────────────*/
plotPoint: parse arg c,r; @.c.r=plotChar /*assign a character to be plotted.*/
minX=min(minX,c); maxX=max(maxX,c) /*find the minimum and maximum X. */
minY=min(minY,r); maxY=max(maxY,r) /* " " " " " Y. */
return