You are on page 1of 30
Computer Graphics (22318) Vi VIL. vu. @ Relevant Affective domain related Outcome(s) a. Experiment with graphics environment. b. Follow safety/ethical practices. ¢. Maintain tools and equipment. Minimum Theoretical Background Flood Fill Algorithm In Flood Fill algorithm we start with some seed and examine the neighboring pixel however pixels are checked for a specified interior color instead of boundary color and is replaced by a new color. Tt can be done using 4 connected or 8 connected region method. Procedure: Flood-fill (node, target-color, replacement-color): 1. Iftarget-color is equal to replacement-color, return. 2. Ifthe color of node is not equal to target-color, return. 3. Set the color of node to replacement-color. 4. Perform Flood-fill (one step to the south of node, target-color, replacement-color) Perform Flood-fill (one step to the north of node, target-color, replacement-color), Perform Flood-fill (one step to the west of node, target-color, replacement-color) Perform Flood-fill (one step to the east of node, target-color, replacement-color). 5. Retum Example circle(100,100,50); floodfill(100,100,RED); Fills the circle with red colour. Algorithm iPCget Pixel Ce,4) == 01d Coloue) purpixel CX 4, NeW -colow ze); poco Oe +1, Y, NeW Coloe) ; ood iil Cx -1 : ' » 4, New-Loloe)s Food Pil) Cua) %, NeW-COloO8)* ’ ’ d Food A CU-1, 4 Mew-coloe): a : 2 ‘Maharashtra State Board of Technical Education a ® Flood -Fii! Cpurx, PUFY, old coloue , New Colodé) RR #incude 2 Stdigh> te indude < conio.h> +4 include < graphics. bo || FE B includes dos.h> in ae hee a vin tk nea maloo. 4 —= = wot gd= DETEcT , 9m} initgraph (é gd, 49m %C! NEC BGT): ciecle Cx 200, 200, 2) 5 Pood Ail ¢200, 200,12, 05 : Qetch os Clos egra ph Cds Void Flood fill Cine x int y ine Lilicolo~ , Nt oldcolo-~e) = i - if Cgetplxel Cx, ¥) == old Core) coloe)3 FloodAll Cx 41,4, Fillcoloe ,Oldcolee);_ Flood er) Ce-1, 4, filcote, oldeaioe) + | Adod FUCK, V4, Filcoloe aldcole at) Rood Fill Ox Yas Neolo-e , aldcoloe)s a ©. soe ds. frafey one oe of) ere oe ee cer ae BCT eT ST Ha EL (Start) flow Chart | a Lpurcixel svtine ) j ied bounducry- iN ¢ b-tolo-) SV get i€_(yetsixel cx, uo! = b-colo# £2 Qerpinel cx, vols £ coloe) Pusphe el: Cx, M Fico.) boundgty ej ctl, y, colo 16 -coledy houndd-ey Pill Crt, VP coloe , Dicoloe) 5_ boundazy-CiilO%, 413, Bcolos b-coloe)s — boundary Fir Ge, U1 fcolo-e, b-coloe) j_ boundory- itl Cres, Vt! F.colot ,b-Caloes boundary. FiliCe=1, Yat Lcolee!, becologys boundary. fy Oe rr U-IS 2 colog h-colawy boundary-fin) <- 1,415 Uf. Cold | b-colbeJs 1 : aL. 3 a Plowchat START a hia “Getpie ©) Ox, yy FR LE 03-4) i, PutrPioce | _0¢ Fb) bei) Orb MR bd > eA CX Ut) 2 Raat ont eA ree ee waa ae RTT aT HB _|ae-inct ude _¢oraphicsh> pci cml» € by — pail) Cr Nhs Fd “b- Fi C Ha), Le yuk 1b \— i vend: 7 seb et Lr incude. wepiashp tt +: include &Conso.n> v # include < dos-h> —_— Void boundorysine Cine, inks, i £s\\- Color, or boundary-Colo-’) 4 pupio maint tanie ior _gd = DET ECT_r>— invigwuph (2 9d, 2g r micas ay cimcle (200,200,295 if pboundury-Cii (299,200, 4,154 _9etch O50 \ Computer Graphics (22318) 2. Identify type of polygon in following diagrams OBAUW 3.Give the basie difference between flood fill and boundary fill, (Space for Answers) BN -7.L4 Commechi ga. Daly Gora r=. Dro. MiG. AC so. AG YS G Conmect.ecl..D2aa.QlS..Al0M la Qhord...kD.Mee defalad..coch..d0..Me.... REG A.. GENE... WE... cashed Nash. .Cam F823 02>. dad S8.. I KOM oo am Gn. Connetech. Pag e025. Sa.tkesS.ACchniqus. Bn Cganec.29. WU NS... L@..HE.. PAH MG. LEAL AL QU.2 Maelo runtrdgilad Ona... Met. SIRE... ME... Corer @rat.. PINS BS. LIC MALL. doing, 99. b9.- 5 03) ZANE. BMogons cosa). Ona. Soa rnadd c4..£8\). Aigo Sen 11D Sa..RooelpAl algaasdwm de. }.Ae..02€0..£8 efrener Leite OED. OMMEA.LOL Meron Bing\e..colauy. O\-tre... Pw endo aid ‘Ss WG H AME. CAO Goossen meMloced...Laitr..0.eu2 Color DT -w.@. Wh erate lS colored Lod..404Y.. COL OVAL conf SYTHE. Td. Criose.. Paiut ere AME. AB. CMA lB tese POG Ae kPocedd. Loidr..ero 7 Wide Wo Colo —~ | Color Mahorashira State Board of Technical L'ducation Computer Graphics (22318) t QI. and teacher shall allot Q. i/ Q.ii from the following: Use Point VITT to X and XT to XV for all relevant programming exercise use pages provided or attach more pages if needed.) m to draw pentagon and fill it with red color using boundary fill 8-connected method, m to draw trapezoid and fill it with blue color using boundary fill 08 algorithm with 4-connected method. (Space for Answers) ALinclude.. Uoid. Br. Civnd..ory. eat veld WMP Od. al iw gas LORTEe Genny Quel x Ph... A Ora AGorn cay. Cage. 26a., Bua 58ua, Bea LAY. BLN AND ing DOA AB AEA WES {et QAM. CF. Ge. Ke Gros O8..CHUL CoM. aye Wd» Prd Ainsal.. See 0.2) os : Yo SaM Ca a 1oy. Nor SM. yah) whe SM. es Ma x gestions for further Reading 1. bups://books. google. 2 hntp /Awwowe fi 3 huip “www. fieetechbooks.convintroductions iter-yraphics-t892, heal Il 4. bitps:/en wikipedia org/wiki/Book:C Maharashtra State Board of Technical Uducation oevvvvvvvwvewvevwvveweve wee wee ewww ewe er ee ee ee ~ Computer Graphies (22318) VIN. Algorithm yp Stas the Proqvan a) ANPUt 4He object +0 co-ordination S entree +ransiation facto€e - fo tx and +¥ 4) Move Ane o-iginugl Co-ovdinate Po-e scaling © Input tne scaled them sx and sy 6) the transformed Co-ordinates cx, 9) mimwe.6 2 D Display tne oblect ofiee scaling ©) Stop tne Program IX, Flow Chart + the co-ordind+e accept ercecution - distance WPM $f by My = RQ + to Maharashira State Board of Technical Education a | | | ae _|teinctuded muth-h> | Progra: nm Hhindude Minclude< conto = _ at indude < gruphics.Ad. iNt reins 2O %x max =TO , Umint 2: void _prawshape O35 oo |Voi.d doranstosion Ciné teint Ay 5 oe As mv = 110 5 Noid caling C Float Sx flog Sy) 5 Noid main) 2 “3 a | che sevcstirn re fyb ins gd = DEFECT gm tasty Pio at idy 5 | _prrctughup eC), ini regamph Ct ¢ gd ehom,™ paintk cVente-€ + conf Cx yi 7 Bbib eds - print c' Sente-t ty [Scan€ C'nd', £ dys printf (“enter $4 CSxe wi -77)5 Conte CYB 20.87) 5 ee print€c ‘eme-te Sy (Sy euji-=>95 Sconk ('“zl" 2 Sy)3 oe ott,srti‘ar::=sshrt ti“ a coling ae = cracls, 7 OUR GAH Wer Tee A wat emer Ree _gebch C15 |_closegxaph. Os a | “Void praudhap ec) | Act ey at tine C% min, Yimin, moran | Sa tae fea Fe rMeratin, Yee) line CXmin, Yeoin 2 min, Umax); p—tine 0% um min, mine j mae) fos) 32 oy po bial vold aaccingla son Ciok te nt ty) LC Amin} f Amuy = te + Wnt 5 Nmin sity + Nmiin 5 Nimux = ty + Nimo! Setcoloe Cas Dravshape os 5 Z i ——_|_void. | Scaling. Pon 6.6 teat $4) IA Remmi sly Demin 5 BAR aH IR, ART sa THT, eT ‘omputer Graphics (22318) Result (Output of the Pro wv. Conclusions Qane. dobrcdiiea ROY he mmm siioak eee Sy SVL Practical Related Questions Note: Below given are few sauple questions for reference. Teacher must design more such questions so as to ensure the achievement of identified CO. (Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use blank pages provided or attach more pages if needed.) 1 ite the transformation matrix for 2D Translation. 2. Write the transformation matrix for 2D Scaling. 3. What does scaling transformation do? 4. Whether size of object remains same or changed in case of translation? (Space for Answers) “B Qcolan Sens houmoakiGa aac Sve Sh. eed. fur. ang BCeaMsesy. J$220.0.2b9..2.LI2... Cem, oes COAPA AS PL Crm Aoels IME... Mena lraS ia. ms Gag eck... ose d.Qron@ve.va, OF Ska...LORE. Sihoard of Technical Fducation ~ ‘Manarashira Stat Evercise ‘Attempt QU. And teacher shall allot Q. 2/Q.3 from the following: (Note: Use Point VIII to X and XIII to XV for all relevant program blank pages provided or attach more pages if needed.) B EXerCIse 1,4 |.Translate the polygon with co-ordinates A(2,5),B(7,10) and C(10,2) by 3 units ny direction and 4 units in y direction. 2. Scale the polygon with co-ordinates A(2,5),B(7,10) and C(10,2) by 2 units in x direction and 2 units in y direction, 3. Give a 3 encous co-ordinate transformation matrix for cach of the following translations. i. Shift the image to the right 3 units ii, Shift the it iti 1¢ up 2 units down % unit and right | unit iv. Move the image down 2/3 unit and left 4 units. 4. Find the transformation matrix that transforms the given square ABCD to half its size with center still remaining at the same position. The co-ordinates of the square are : A(L.1).BG,1),C(,3) and D(1,3) and center at (2,2).Also find the resultant co- ordinates of square. (Space for Answers) BU PACLS) 2 SCInwd.1. C19, t Be WCAG)... BCA I9I.C.ClOMS At Mo QF Si MOD DAL SIAL MBA AWE an Ete. SY... SLE. YF QLSY. GSM LSM, HD YDS LA ‘Maharashira State Board of Technical Education Where R is the rotation matrix and is represented as Ra | 099 sino ~ |=sind cose The rotation angle can be positive and neg: ative For positive rotation angle, . clockwise or Counterclockwise Wwe ean use the above rotation matrix, H negative angle rotation, the matrix will change as shown below — Re [ cos(—-8) sin(—0) ~ L+8in(-8) cos(—-) lowever, fop cos? —sing = ( cos(—8) = in(—6) = — si; [2% iar |¢ ©08(—8) = cos and sin(—0) sind) Procedure: Step 1: Start the program. Step 2: Input the object coordinates Step 3: For Rotation 4) Enter the radian for rotation angle @ b) Rotate a point at position (x,y.2) through an an, x1=xcos 0 ~ ysin 0 , yl=ycos 0 + xsin 0. ©) Display the object after rotation Step 4: Stop the Program, igle @ about the origin VIL. Algorithm D Srort ; DTU object co-osdinate > Po *rrotaH on , ; anak ° enret ane radivg foe rotation ROLE point C%,V,2zI throuyheo Ubeve phe O*gIN A .=%cOSe ~ Ysine Yi = Ycose + ocsing | econo wW display ane objet oithe s) end Maharashtra State Board of Technical Lducation tt neue RL Conia. n> Ht incladed graphics. h > ea # induce emuth.h> Vaid Mold Roetadien Cint)} LNoid —main©) = IS Clsscx 3 = inrgd2 DETECT ym, theta 5 itgzapnte gd £ 9m. *c'neceu BG12; @ face Hite ee Ne — wavthape Cint «, ,in Yi, ine Pe ie eieP mee = : | Scene cord 2 ehesoon Rosas oo Clheseds getch (i ClosegyaphO 5 arctan, 7 ReTe WR Ne ——— “[Cerashape "O,5 My 5 Mad a5 _prinse Centet theta Cématt hase) —— _ ‘urasha State Hoard of Fectinical ducati Flow Chart Start CeO LP4 Co-ordinate goo) \ine O14, Ka, Ya) Nine (Xa, 42, %3,43) Vine Ca, Ys 4%, 4) accept rotation angle t=94 / Ro =? mx, = C%,COSE -4q sint) eoprogramCode™%q = (Ma COSE ~Ya Sint) muy = OG sine ~ 4, Cost) mas 2 Sint Neo cost) mas 2 CX Cost Y3 8170) mys? Cusine ~ 43 CSU) Vine Cm, oY, 5 M2 Ma) Vine ©%€2,¥. ,%3,N3) Vin€ (%3, 4a, 20, YD END va apes (223818) Resources required XL aI Speeifi uantity Resoireese eo Steere eo Rema Hardware Computer (i3-i5 preferable), 7 1 | Computer RAM minimum 2 GB and System onwards but not limited to = — As per batch i Opera Windows XP/AVindows eee _ Foralt 2 | system T/LINUX version 5.0 or later Experiment, 3 Software Turbo C/C++ Ver e later with DOSBOX. NI. utions 1. Ensure that all C statements must end with a semicolon (;), 2. Use white spaces in ¢ 10 describe blanks and tabs, 3. Ensure use of proper graphics function for relevant object. 4. Follow safety/ethical practices. XIIL Resources used ! Name of Resource Specification = + + — 1 | Computer System TS 11GB ATS ADO- Gindog | 2 [Soi 2 [Ss 3 | Any other resource used [ with broad speci ise i Tivkon C_1C4+t+ XIV Result (Output of the Program) XV. Coneclusion(s) TM.urd.... Loe, Rama... Shak Cecn AroQh ona. B19... Mme PL 1A. OAL. PQS, adh! Oven XVI. Practical Related Questions Note: Below given are few sample questions for reference. Teacher must design ‘more such questions so as to ensure the achievement of identified CO. (Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use blank payes provided or attach more pages if needed.) 1 Write the transformation matrix for 2D Rotation ' 2. Wnite rotation matrix for a rotation angle 30°. i ‘ “aarasva Stic Hoard of Technical 'davaion w ‘ t ica Comput for Answers) nSormncrilon..nadsinva.. Jore..0... Rokeby “f- 9.0. ~=Stael lO BEBO. cnn COSA ‘Maharashiva State Board of Technical b ON encl eca ior ell thaw Space for Saswers DS De ae re 8 ea Computer Graphiies (22318) 2 fe je Sl ul B = . , CoS&S.. Sts, : DEVAS oe HOLA sedenese ‘Maharashira State Board of Technical Education Computer Graphies 22318) vu. at the programy, Ste? 2: Input the object coordinates Step 3 caving Patt the shearing factors shx ang shy ) Shearing related to axis: Transform Coordinat £) Shearing related toy ae Transform coordinate’ oh ) Input the xtet and Yref Values SES Xx and yiny Ply, ©) X axis shear related tye "ference line yerat is gy - Step 4: F Step 5: Algorit PIECH on SS Stop dhe Cr OyrIMy Maharashiva State Board oF a a rari eat gy ee a eee Nclude@ < ga phics.h> es Noid Remection 05 AE indadedccomahd A incleccle<_marhh> Nt Xmin_, Kmaxe, Ymin, Umar NVotd Drowshupe Cint, int, int, Void main : Clegcy 5 intgdxive = DETECT, 9Mode ,thera } initgzoph (2 ydvivet, 4 gmode pH i de = Flore Co Simo oC midy = Proot Cgetmax yO 72); Mri A =lO 5 Mimip =195. —& pyux = 405 Yimax = 705 (ine Cmid a,o, midy ,getmeary 5 \inec midy, gethore 0, micly) 3 __ pravshape Ocmin_, Yamin ,%X mor, Y max) RececH onl _9 2+chQ; srseflet, Me Freearet Rt TTT TER GY Bat Seer were e | Revlection: er ee et OLY sitet aR, OTT BY A ga | eR ay, eae aA puter rapies (22318) Flow Chart “C’ Program Code “shia State Board of o Education| wsvosevveweovweovevweweoweeweweeeweweweseermceemclcermclcermcUCOmcCcrOrmCUCUcCCCFCOlCUl Cc! HS COS Se Computer Graphicn (224) i f (Space for Answers) Eee Mga eNO) \ fe Sea Wire Maing XVIL Exerelve Attempt QU. And (eae HL allot Qs 1/Q.2 from the following: (Note: Use Point VII to X and XIE to XV for all relevant programming exercise use lank pages provided or attach more pages if needed.) 1, A point (4, 3) is rotated counterclockwise by an angle of 45", Find the rotation matrix and the resultant point, Apply the Shearing transformation to square with A(0,0).B(1,0),C(1,1) and D(O,1) as given below : i, Shear parameter value of 0.5 relative to the line Yret™ «1s car parameter value of 0.5 relative to the fine Xref «1; 2. Apply shearing, transformation to square with A(0,0),B(1,0),CC1,1) and DO,D.AE Sh, 0.5 then find the resultant eo-ordi (Space for Answ \ Maharashtra Stare Hoard of Technical Education “ (22318) Computer Gr LOZ, Procedure: Step 1: Start the pr Step 2: Input the object coordinates Step 3: For Translation a) Enter the transla m, (on factors ty, ty and b 'b) Move the original coordinate position (x,y,2) to a new position (sLyLyD.ie. x=xtx1, y=ytyl and z=2421. ©) Display the object after translation Step 4: For Scaling a) Input th caled factors sx.sy and sz. ) The transformed coordinates (x1.y1.21) ,x1=x.5.. yl=y.sy and 212.5 ©) Display the object after scaling Step 5: Stop the Program. VIL. Algorithm: StePi: Stuyv+ tHE prog tam Srep2: Tnpur ine object coordind+es step 3a: Pow svanslaton Step4: pox scaling Meet: gop tes PORass IX. Flow Chart “Maharashira State Board of Technical Education “Computer Graphies 2218) XIV. Result (Output of the Program) XV. Conelusion(s) CAM ue OVC. ShoLd eel pm Gey EOP fark JAE. ODL Conch: 266005. COMMU, XVL_ Practical Related Questions Note: Bel ren are few sample questions for reference. Teacher must design more such questions so ay to ensure the achievement of identified CO. Jse Point VIL to 3 programming exercise use (C839. oh Pon C0. omlin Ube... SShEM cil.geleaticany AOC... pa PLYNE...CU.L Cy Maharashira State Hoard of Technical Ls oy NVIL Exercise \nd teacher shall atlot VQ. from N the f Renee Xd Nite XV all rele = "tach more pag evant pre nes needed ) Sri Ming ery, Aeube in Cy, “sing “bagg = en On, = units in y Units in 2 . nT 2. Write a program to fo drwa cube inc Fits original size ical Eaacation sharsshiva Sate Board of Team

You might also like