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