How to Create a Sphere with Pen

Материал из Поле цифровой дидактики

This article explains how to create a sphere with pen in Scratch.

The Process

Method One: Using a Light Source

Step 1: Create a sprite which will be the "Light Source", and create the pen sprite.

Step 2: Create the following code in the pen sprite:

whenclickedgeneratesphereofsize100definegeneratesphereofsizespheresizesetvto0repeatspheresizecreatecircleofsizevRemembertocheckthe"runwithoutscreenrefresh"!changevby0.01enddefinecreatecircleofsizecirclesizerepeat360pendownsetpencolorto5Thecolorofthespheresetpenbrightnessto100-distancetoLightSourceturn1degreesmovecirclesizestepsend

Method Two: Pen Sprite Only

Step 1: Create the pen sprite.

Step 2: Do the same as Step 2, method 1, but replace the last script with this one:

definecreatecircleofsizecirclesizerepeat360movecirclesizestepspendownsetpencolorto5reddishorangesetpenbrightnesstosqrtofcenterx-xposition*centerx-xposition+centery-yposition*centery-ypositionRemember,(centerx)isthexpositionofwhereitwillbeshaded,and(centery)istheypositionofwhereitwillbeshaded.turn1degreesend

Method 3: Wireframe

Another method for a wireframe 3d sphere is shown below:

definegotoxyzrc_xrc_yrc_zr_xr_yr_zcam_xcam_ycam_zfsgotox:x-rc_x*cosofr_y-z-rc_z*sinofr_y*cosofr_z-y-rc_y*cosofr_x-x-rc_x*sinofr_y+z-rc_z*cosofr_y*sinofr_x*sinofr_z-cam_x*fs/fs+y-rc_y*sinofr_x+x-rc_x*sinofr_y+z-rc_z*cosofr_y*cosofr_x-cam_zy:x-rc_x*cosofr_y-z-rc_z*sinofr_y*sinofr_z+y-rc_y*cosofr_x-x-rc_x*sinofr_y+z-rc_z*cosofr_y*sinofr_x*cosofr_z-cam_y*fs/fs+y-rc_y*sinofr_x+x-rc_x*sinofr_y+z-rc_z*cosofr_y*cosofr_x-cam_zdefineLooperaseallsetito0repeat12setjto90repeat6Linecosofi*100*cosofjsinofj*100sinofi*100*cosofj+5000cosofi*100*cosofj+30sinofj+30*100sinofi*100*cosofj+30+5000changejby30endchangeiby30endsetjto120repeat5setito0repeat12Linecosofi*100*cosofjsinofj*100sinofi*100*cosofj+5000cosofi+30*100*cosofjsinofj*100sinofi+30*100*cosofj+5000changeiby30endchangejby30enddefineLineX1Y1Z1X2Y2Z2gotoX1Y1Z1pendowngotoX2Y2Z2penupwhenclickedsetpencolortosetpensizeto5foreverLoopenddefinegotoxyzgotoxyz005000mouseymousex/30000240

Examples

See Also