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