{"id":767,"date":"2011-05-17T08:27:53","date_gmt":"2011-05-17T12:27:53","guid":{"rendered":"http:\/\/www.searchenginegenie.com\/web-design-blog\/?p=767"},"modified":"2011-05-17T08:28:34","modified_gmt":"2011-05-17T12:28:34","slug":"rendering-of-3d-colorful-sphere-rotation-using-flash","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/web-design-blog\/rendering-of-3d-colorful-sphere-rotation-using-flash\/","title":{"rendered":"Rendering of 3d colorful sphere rotation using Flash:"},"content":{"rendered":"<p><object id=\"test\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"400\" height=\"410\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"src\" value=\"http:\/\/www.searchenginegenie.com\/web-design-blog\/wp-content\/uploads\/2011\/05\/3d-colorful-glass-rotation-using-Flash.swf\" \/><param name=\"name\" value=\"test1\" \/><embed id=\"test\" type=\"application\/x-shockwave-flash\" width=\"400\" height=\"410\" src=\"http:\/\/www.searchenginegenie.com\/web-design-blog\/wp-content\/uploads\/2011\/05\/3d-colorful-glass-rotation-using-Flash.swf\" name=\"test1\"><\/embed><\/object><\/p>\n<p style=\"text-align: left;\"><span style=\"color: #000000;\">Step-1: Open a new document in flash is about the size of 400 X 410.<\/span><br \/>\n<span style=\"color: #000000;\"><br \/>\nStep-2:In layer-1 type the text which ever you want. Here I gave \u201cMove the Mouse over the surface\u00a0 to rotate the sphere\u201d.<\/span><br \/>\n<span style=\"color: #000000;\"><br \/>\nStep-3:Create layer-2 and write the following action script in keyframe-1(F9).<br \/>\n<\/span><br \/>\n<span style=\"color: #636365;\">var boardSize:Number=350;<br \/>\nvar cubeSize:Number=Math.round(boardSize\/3);<br \/>\nvar rotateFactor:Number=1.2*320\/boardSize;<br \/>\nvar fLen:Number=2000;<br \/>\nvar spBoard:Sprite=new Sprite();<br \/>\nthis.addChild(spBoard);<br \/>\nspBoard.x=200;<br \/>\nspBoard.y=200;<br \/>\nvar shBack:Shape=new Shape();<br \/>\nspBoard.addChild(shBack);<br \/>\ndrawBack();<br \/>\nvar shCube:Shape=new Shape();<br \/>\nspBoard.addChild(shCube);<br \/>\nvar doRotate:Boolean = false;<br \/>\nvar prevX:Number;<br \/>\nvar prevY:Number;<br \/>\nvar curTheta:Number=-10;<br \/>\nvar curPhi:Number=60;<br \/>\nvar examplesTot:uint=11;<br \/>\nvar exampleNum:uint=3;<br \/>\nvar nMesh:Number=40;<br \/>\nvar tilesArray:Array=[];<br \/>\nvar firstRun:Boolean=true;<br \/>\nvar tilesColors:Array=[];<br \/>\nfunction drawBack():void {<br \/>\nshBack.graphics.lineStyle(2,0xFFFFFF);<br \/>\nshBack.graphics.beginFill(0x000000);<br \/>\nshBack.graphics.drawRect(-boardSize\/2,-boardSize\/2,boardSize,boardSize);<br \/>\nshBack.graphics.endFill();<br \/>\n}<br \/>\nsetTilesArray();<br \/>\nrenderView(curTheta,curPhi);<br \/>\nfunction setTilesArray():void {<br \/>\nvar i:int;<br \/>\nvar j:int;<br \/>\nvar istep:Number;<br \/>\nvar jstep:Number;<br \/>\nvar tmin:Number;<br \/>\nvar tmax:Number;<br \/>\nvar smin:Number;<br \/>\nvar smax:Number;<br \/>\nvar curt:Number;<br \/>\nvar curs:Number;<br \/>\nshCube.graphics.clear();<br \/>\ntilesArray=[];<br \/>\ntilesColors=[];<br \/>\nfirstRun=true;<br \/>\ncurTheta=-10;<br \/>\ncurPhi=90;<br \/>\nif(exampleNum==3){<br \/>\ntmin=0;<br \/>\ntmax=1.5*Math.PI;<br \/>\nsmin=0;<br \/>\nsmax=2*Math.PI;<br \/>\n}<br \/>\nistep=(smax-smin)\/nMesh;<br \/>\njstep=(tmax-tmin)\/nMesh;<br \/>\nfor(i=0;i&lt;=nMesh;i++){<br \/>\ncurs=istep*i+smin;<br \/>\ntilesArray[i]=[];<br \/>\nfor(j=0;j&lt;=nMesh;j++){<br \/>\ncurt=jstep*j+tmin;<br \/>\nif(exampleNum==3){<br \/>\ntilesArray[i][j]=[cubeSize\/4.3*Math.cos(curs)*(2+Math.cos(curt)*2),cubeSize\/4.3*Math.sin(curs)*(2+Math.cos(curt)*2),cubeSize\/2.6*(3-curt)-0.3*cubeSize];<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nfunction renderView(t:Number,p:Number):void {<br \/>\nvar i:int;<br \/>\nvar j:int;<br \/>\nvar n:int;<br \/>\nvar distArray=[];<br \/>\nvar dispArray=[];<br \/>\nvar tilesNewArray=[];<br \/>\nvar midPoint:Array=[];<br \/>\nvar dist:Number;<br \/>\nvar depLen:Number;<br \/>\nvar coloFactor=100\/cubeSize;<br \/>\nt=t*Math.PI\/180;<br \/>\np=p*Math.PI\/90;<br \/>\nshCube.graphics.clear();<br \/>\nfor(i=0;i&lt;=nMesh;i++){<br \/>\ntilesNewArray[i]=[];<br \/>\nfor(j=0;j&lt;=nMesh;j++){<br \/>\ntilesNewArray[i][j]=pointNewView(tilesArray[i][j],t,p);<br \/>\n}<br \/>\n}<br \/>\nfor(i=0;i&lt;nMesh;i++){<br \/>\nif(firstRun){<br \/>\ntilesColors[i]=[];<br \/>\n}<br \/>\nfor(j=0;j&lt;nMesh;j++){<br \/>\nmidPoint[0]=(tilesNewArray[i][j][0]+tilesNewArray[i+1][j][0]+tilesNewArray[i][j+1][0]+tilesNewArray[i+1][j+1][0])\/4;<br \/>\nmidPoint[1]=(tilesNewArray[i][j][1]+tilesNewArray[i+1][j][1]+tilesNewArray[i][j+1][1]+tilesNewArray[i+1][j+1][1])\/4;<br \/>\nmidPoint[2]=(tilesNewArray[i][j][2]+tilesNewArray[i+1][j][2]+tilesNewArray[i][j+1][2]+tilesNewArray[i+1][j+1][2])\/4;<br \/>\ndist=Math.sqrt(Math.pow(fLen-midPoint[0],2)+Math.pow(midPoint[1],2)+Math.pow(midPoint[2],2));<br \/>\ndistArray.push([dist,i,j]);<br \/>\nif(firstRun){<br \/>\ntilesColors[i][j]=combineRGB((2*coloFactor*midPoint[2]+100)*0.8+70,(2*coloFactor*midPoint[1]+100)*0.8+70,(2*coloFactor*midPoint[0]+100)*0.8+70);<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\ndistArray.sort(byDist);<br \/>\nfor(i=0;i&lt;=nMesh;i++){<br \/>\ndispArray[i]=[];<br \/>\nfor(j=0;j&lt;=nMesh;j++){<br \/>\ndispArray[i][j]=[fLen\/(fLen-tilesNewArray[i][j][0])*tilesNewArray[i][j][1],-fLen\/(fLen-tilesNewArray[i][j][0])*tilesNewArray[i][j][2]];<br \/>\n}<br \/>\n}<br \/>\ndepLen=distArray.length;<br \/>\nshCube.graphics.lineStyle(1,0&#215;111111);<br \/>\nfor(n=0;n&lt;depLen;n++){<br \/>\ni=distArray[n][1];<br \/>\nj=distArray[n][2];<br \/>\nshCube.graphics.moveTo(dispArray[i][j][0],dispArray[i][j][1]);<br \/>\nshCube.graphics.beginFill(tilesColors[i][j],1.0);<br \/>\nshCube.graphics.lineTo(dispArray[i][j+1][0],dispArray[i][j+1][1]);<br \/>\nshCube.graphics.lineTo(dispArray[i+1][j+1][0],dispArray[i+1][j+1][1]);<br \/>\nshCube.graphics.lineTo(dispArray[i+1][j][0],dispArray[i+1][j][1]);<br \/>\nshCube.graphics.lineTo(dispArray[i][j][0],dispArray[i][j][1]);<br \/>\nshCube.graphics.endFill();<br \/>\n}<br \/>\nfirstRun=false;<br \/>\n}<br \/>\nfunction byDist(v:Array,w:Array):Number {<br \/>\nif (v[0]&gt;w[0]){<br \/>\nreturn -1;<br \/>\n} else if (v[0]&lt;w[0]){<br \/>\nreturn 1;<br \/>\n} else {<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<br \/>\nfunction pointNewView(v:Array,theta:Number,phi:Number):Array {<br \/>\nvar newCoords:Array=[];<br \/>\nnewCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);<br \/>\nnewCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);<br \/>\nnewCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);<br \/>\nreturn newCoords;<br \/>\n}<br \/>\nfunction combineRGB(red:Number,green:Number,blue:Number):Number {<br \/>\nvar RGB:Number;<br \/>\nif(red&gt;255){red=255;}<br \/>\nif(green&gt;255){green=255;}<br \/>\nif(blue&gt;255){blue=255;}<br \/>\nif(red&lt;0){red=0;}<br \/>\nif(green&lt;0){green=0;}<br \/>\nif(blue&lt;0){blue=0;}<br \/>\nRGB=(red&lt;&lt;16) | (green&lt;&lt;8) | (blue&lt;&lt;0);<br \/>\nreturn RGB;<br \/>\n}<br \/>\nspBoard.addEventListener(MouseEvent.ROLL_OUT,boardOut);<br \/>\nspBoard.addEventListener(MouseEvent.MOUSE_MOVE,boardMove);<br \/>\nspBoard.addEventListener(MouseEvent.ROLL_OVER,boardOver);<br \/>\nfunction boardOut(e:MouseEvent):void {<br \/>\ndoRotate=false;<br \/>\n}<br \/>\nfunction boardOver(e:MouseEvent):void {<br \/>\nprevX=spBoard.mouseX;<br \/>\nprevY=spBoard.mouseY;<br \/>\ndoRotate=true;<br \/>\n}<br \/>\nfunction boardMove(e:MouseEvent):void {<br \/>\nvar locX:Number=prevX;<br \/>\nvar locY:Number=prevY;<br \/>\nif(doRotate){<br \/>\nprevX=spBoard.mouseX;<br \/>\nprevY=spBoard.mouseY;<br \/>\ncurTheta+=(prevX-locX)*rotateFactor;<br \/>\ncurPhi+=(prevY-locY)*rotateFactor;<br \/>\nrenderView(curTheta,curPhi);<br \/>\ne.updateAfterEvent();<br \/>\n}<br \/>\n}<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"color: #000000;\">Now run the program.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step-1: Open a new document in flash is about the size of 400 X 410. Step-2:In layer-1 type the text which ever you want. Here I gave \u201cMove the Mouse over the surface\u00a0 to rotate the sphere\u201d. Step-3:Create layer-2 and write the following action script in keyframe-1(F9). var boardSize:Number=350; var cubeSize:Number=Math.round(boardSize\/3); var rotateFactor:Number=1.2*320\/boardSize; var fLen:Number=2000; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[44,45],"class_list":["post-767","post","type-post","status-publish","format-standard","hentry","category-flash","category-web-design","tag-3d-rotating-sphere-using-flash","tag-3d-rotating-sphere-using-flash-action-script"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":12,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"predecessor-version":[{"id":791,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/posts\/767\/revisions\/791"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/web-design-blog\/wp-json\/wp\/v2\/tags?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}