aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * Testing JavaFX canvas run by Nashorn. aoqi@0: * aoqi@0: * @test/nocompare aoqi@0: * @run aoqi@0: * @fork aoqi@0: */ aoqi@0: aoqi@0: TESTNAME = "flyingimage"; aoqi@0: aoqi@0: var WIDTH = 800; aoqi@0: var HEIGHT = 600; aoqi@0: var canvas = new Canvas(WIDTH, HEIGHT); aoqi@0: function fileToURL(file) { aoqi@0: return new File(file).toURI().toURL().toExternalForm(); aoqi@0: } aoqi@0: var imageUrl = fileToURL(__DIR__ + "flyingimage/flyingimage.png"); aoqi@0: var img = new Image(imageUrl); aoqi@0: var isFrameRendered = false; aoqi@0: function renderFrame() { aoqi@0: var t = frame; aoqi@0: var gc = canvas.graphicsContext2D; aoqi@0: gc.setFill(Color.web("#cccccc")); aoqi@0: gc.fillRect(0, 0, WIDTH, HEIGHT); aoqi@0: gc.setStroke(Color.web("#000000")); aoqi@0: gc.setLineWidth(1); aoqi@0: gc.strokeRect(5, 5, WIDTH - 10, HEIGHT - 10); aoqi@0: var c = 200; aoqi@0: var msc= 0.5 * HEIGHT / img.height; aoqi@0: var sp0 = 0.003; aoqi@0: for (var h = 0; h < c; h++) { aoqi@0: gc.setTransform(1, 0, 0, 1, 0, 0); aoqi@0: var yh = h / (c - 1); aoqi@0: gc.translate((0.5 + Math.sin(t * sp0 + h * 0.1) / 3) * WIDTH, 25 + (HEIGHT * 3 / 4 - 40) * (yh * yh)); aoqi@0: var sc = 30 / img.height + msc * yh * yh; aoqi@0: gc.rotate(90 * Math.sin(t * sp0 + h * 0.1 + Math.PI)); aoqi@0: gc.scale(sc, sc); aoqi@0: gc.drawImage(img, -img.width / 2, -img.height / 2); aoqi@0: } aoqi@0: gc.setTransform(1, 0, 0, 1, 0, 0); aoqi@0: isFrameRendered = true; aoqi@0: } aoqi@0: var stack = new StackPane(); aoqi@0: var pane = new BorderPane(); aoqi@0: pane.setCenter(canvas); aoqi@0: stack.getChildren().add(pane); aoqi@0: $STAGE.scene = new Scene(stack); aoqi@0: var frame = 0; aoqi@0: var timer = new AnimationTimerExtend() { aoqi@0: handle: function handle(now) { aoqi@0: if (frame < 200) { aoqi@0: renderFrame(); aoqi@0: frame++; aoqi@0: } else { aoqi@0: checkImageAndExit(); aoqi@0: timer.stop(); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: timer.start(); aoqi@0: