Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/jfx/flyingimage.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 = "flyingimage";3233var WIDTH = 800;34var HEIGHT = 600;35var canvas = new Canvas(WIDTH, HEIGHT);36function fileToURL(file) {37return new File(file).toURI().toURL().toExternalForm();38}39var imageUrl = fileToURL(__DIR__ + "flyingimage/flyingimage.png");40var img = new Image(imageUrl);41var isFrameRendered = false;42function renderFrame() {43var t = frame;44var gc = canvas.graphicsContext2D;45gc.setFill(Color.web("#cccccc"));46gc.fillRect(0, 0, WIDTH, HEIGHT);47gc.setStroke(Color.web("#000000"));48gc.setLineWidth(1);49gc.strokeRect(5, 5, WIDTH - 10, HEIGHT - 10);50var c = 200;51var msc= 0.5 * HEIGHT / img.height;52var sp0 = 0.003;53for (var h = 0; h < c; h++) {54gc.setTransform(1, 0, 0, 1, 0, 0);55var yh = h / (c - 1);56gc.translate((0.5 + Math.sin(t * sp0 + h * 0.1) / 3) * WIDTH, 25 + (HEIGHT * 3 / 4 - 40) * (yh * yh));57var sc = 30 / img.height + msc * yh * yh;58gc.rotate(90 * Math.sin(t * sp0 + h * 0.1 + Math.PI));59gc.scale(sc, sc);60gc.drawImage(img, -img.width / 2, -img.height / 2);61}62gc.setTransform(1, 0, 0, 1, 0, 0);63isFrameRendered = true;64}65var stack = new StackPane();66var pane = new BorderPane();67pane.setCenter(canvas);68stack.getChildren().add(pane);69$STAGE.scene = new Scene(stack);70var frame = 0;71var timer = new AnimationTimerExtend() {72handle: function handle(now) {73if (frame < 200) {74renderFrame();75frame++;76} else {77checkImageAndExit();78timer.stop();79}80}81};82timer.start();83848586