# -------------------------------------------------- # SkCylinder v. 2.0 # Skrypt na tworzenie kół, okręgów i walców # # Autor: Kormic # -------------------------------------------------- function skCylinder_squaredDistance(loc1: location, loc2: location) :: number: return ((x-loc of {_l1} - x-loc of {_l2})^2 + (z-loc of {_l1} - z-loc of {_l2})^2) function skCylinder_drawCircle(centerLoc: location, radius: number) :: blocks: set {_pi} to 3.141592 set {_blocksApprox} to ceil(2 * {_pi} * {_radius}) set {_angleInterval} to 360 / {_blocksApprox} loop {_blocksApprox} times: set {_x} to (x-loc of {_centerLoc}) + {_radius} * sin({_angleInterval} * loop-number) set {_z} to (z-loc of {_centerLoc}) + {_radius} * cos({_angleInterval} * loop-number) add block at location at ({_x}, (y-loc of {_centerLoc}), {_z}) in (world of {_centerLoc}) to {_blocks::*} return {_blocks::*} function skCylinder_drawDisk(centerLoc: location, radius: number) :: blocks: set {_sqRadius} to {_radius} * {_radius} loop (2 * {_radius} + 1) times: loop (2 * {_radius} + 1) times: set {_x} to (x-loc of {_centerLoc}) - {_radius} + (loop-number-1) - 1 set {_z} to (z-loc of {_centerLoc}) - {_radius} + (loop-number-2) - 1 set {_currLoc} to location({_x}, (y-loc of {_centerLoc}), {_z}, world of {_centerLoc}) set {_sqDist} to skCylinder_squaredDistance({_centerLoc}, {_currLoc}) if {_sqDist} > {_sqRadius}: continue add block at {_currLoc} to {_blocks::*} add skCylinder_drawCircle({_centerLoc}, {_radius}) to {_blocks::*} return {_blocks::*} function skCylinder_drawCylinder(startLoc: location, radius: number, height: integer, filled: boolean) :: blocks: set {_centerLoc} to {_startLoc} loop {_height} times: if {_filled} is true: add skCylinder_drawDisk({_centerLoc}, {_radius}) to {_blocks::*} else: add skCylinder_drawCircle({_centerLoc}, {_radius}) to {_blocks::*} remove 1 from (y-loc of {_centerLoc}) return {_blocks::*}