1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * Testing JavaFX canvas run by Nashorn. 26 * 27 * @test/nocompare 28 * @run 29 * @fork 30 */ 31 32 TESTNAME = "kaleidoscope"; 33 34 var WIDTH = 800; 35 var HEIGHT = 600; 36 var canvas = new Canvas(WIDTH, HEIGHT); 37 var context = canvas.graphicsContext2D; 38 39 var x,y; 40 var p_x,p_y; 41 var a=0; 42 var b=0; 43 var angle=Math.PI/180*8; 44 var color=0; 45 var limit1=Math.PI*1.5; 46 var limit2=Math.PI*1.79; 47 var c=new Array(6); 48 var d=new Array(6); 49 var r,e; 50 var fade; 51 var prv_x,prv_y,prv_x2,prv_y2; 52 var isFrameRendered = false; 53 54 function renderFrame() { 55 if (!isFrameRendered) { 56 a=0.2*angle; 57 b=0.7*angle; 58 r=0; 59 fade=32; 60 for(var i=0;i<6;i++) 61 { 62 c[i]=1.0/(i+1)/2; 63 d[i]=1.0/(i+1)/2; 64 } 65 radius=Math.round((WIDTH+HEIGHT)/8); 66 e=radius*0.2; 67 p_x=Math.round(WIDTH/2); 68 p_y=Math.round(HEIGHT/2); 69 x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]); 70 y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]); 71 isFrameRendered = true; 72 } 73 anim(); 74 } 75 76 function anim() { 77 var a1=Math.cos(a*2); 78 var a2=Math.cos(a*4); 79 var a3=Math.cos(a); 80 var a4=Math.sin(a); 81 if(b>limit1&&b<limit2) { 82 r+=radius*0.02*a1; 83 prv_x=x; 84 prv_y=y; 85 x=prv_x2+r*a3; 86 y=prv_y2+r*a4; 87 } else { 88 prv_x=x; 89 prv_y=y; 90 prv_x2=x; 91 prv_y2=y; 92 x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]); 93 y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]); 94 } 95 var c3=16*Math.cos(a*10); 96 var c1=Math.floor(56*Math.cos(a*angle*4)+c3); 97 var c2=Math.floor(56*Math.sin(a*angle*4)-c3); 98 context.lineCap=StrokeLineCap.ROUND; 99 context.setStroke(Paint.valueOf('rgba('+(192+c1)+','+(192+c2)+','+(192-c1)+','+(0.01-0.005*-a1)+')')); 100 context.lineWidth=e*1.4+e*0.8*a3; 101 draw_line(p_x,p_y,prv_x,prv_y,x,y); 102 context.lineWidth=e+e*0.8*a3; 103 draw_line(p_x,p_y,prv_x,prv_y,x,y); 104 context.setStroke(Paint.valueOf('rgba('+(192+c1)+','+(192+c2)+','+(192-c1)+','+(0.06-0.03*-a1)+')')); 105 context.lineWidth=e*0.6+e*0.35*a3; 106 draw_line(p_x,p_y,prv_x,prv_y,x,y); 107 context.setStroke(Paint.valueOf('rgba(0,0,0,0.06)')); 108 context.lineWidth=e*0.4+e*0.225*a3; 109 draw_line(p_x,p_y,prv_x,prv_y,x,y); 110 context.setStroke(Paint.valueOf('rgba('+(192+c1)+','+(192+c2)+','+(192-c1)+','+(0.1-0.075*-a1)+')')); 111 context.lineWidth=e*0.2+e*0.1*a3; 112 draw_line(p_x,p_y,prv_x,prv_y,x,y); 113 context.setStroke(Paint.valueOf('rgba(255,255,255,0.4)')); 114 context.lineWidth=e*(0.1-0.05*-a2); 115 draw_line(p_x,p_y,prv_x,prv_y,x,y); 116 a+=angle*Math.cos(b); 117 b+=angle*0.1; 118 } 119 120 function draw_line(x,y,x1,y1,x2,y2) { 121 context.beginPath(); 122 context.moveTo(x+x1,y+y1); 123 context.lineTo(x+x2,y+y2); 124 context.moveTo(x-x1,y+y1); 125 context.lineTo(x-x2,y+y2); 126 context.moveTo(x-x1,y-y1); 127 context.lineTo(x-x2,y-y2); 128 context.moveTo(x+x1,y-y1); 129 context.lineTo(x+x2,y-y2); 130 context.moveTo(x+y1,y+x1); 131 context.lineTo(x+y2,y+x2); 132 context.moveTo(x-y1,y+x1); 133 context.lineTo(x-y2,y+x2); 134 context.moveTo(x-y1,y-x1); 135 context.lineTo(x-y2,y-x2); 136 context.moveTo(x+y1,y-x1); 137 context.lineTo(x+y2,y-x2); 138 context.moveTo(x,y+x2); 139 context.lineTo(x,y+x1); 140 context.moveTo(x,y-x2); 141 context.lineTo(x,y-x1); 142 context.moveTo(x+x2,y); 143 context.lineTo(x+x1,y); 144 context.moveTo(x-x2,y); 145 context.lineTo(x-x1,y); 146 context.stroke(); 147 context.closePath(); 148 } 149 150 var stack = new StackPane(); 151 var pane = new BorderPane(); 152 pane.setCenter(canvas); 153 stack.getChildren().add(pane); 154 $STAGE.scene = new Scene(stack); 155 var frame = 0; 156 var timer = new AnimationTimerExtend() { 157 handle: function handle(now) { 158 if (frame < 800) { 159 renderFrame(); 160 frame++; 161 } else { 162 checkImageAndExit(); 163 timer.stop(); 164 } 165 } 166 }; 167 timer.start();