Sun, 23 Jul 2017 23:24:00 -0700
Merge
kshefov@638 | 1 | /* |
kshefov@638 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
kshefov@638 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
kshefov@638 | 4 | * |
kshefov@638 | 5 | * This code is free software; you can redistribute it and/or modify it |
kshefov@638 | 6 | * under the terms of the GNU General Public License version 2 only, as |
kshefov@638 | 7 | * published by the Free Software Foundation. |
kshefov@638 | 8 | * |
kshefov@638 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
kshefov@638 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
kshefov@638 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
kshefov@638 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
kshefov@638 | 13 | * accompanied this code). |
kshefov@638 | 14 | * |
kshefov@638 | 15 | * You should have received a copy of the GNU General Public License version |
kshefov@638 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
kshefov@638 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
kshefov@638 | 18 | * |
kshefov@638 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
kshefov@638 | 20 | * or visit www.oracle.com if you need additional information or have any |
kshefov@638 | 21 | * questions. |
kshefov@638 | 22 | */ |
kshefov@638 | 23 | |
kshefov@638 | 24 | /** |
kshefov@638 | 25 | * Testing JavaFX canvas run by Nashorn. |
kshefov@638 | 26 | * |
kshefov@638 | 27 | * @test/nocompare |
kshefov@638 | 28 | * @run |
kshefov@638 | 29 | * @fork |
kshefov@638 | 30 | */ |
kshefov@638 | 31 | |
kshefov@638 | 32 | TESTNAME = "flyingimage"; |
kshefov@638 | 33 | |
kshefov@638 | 34 | var WIDTH = 800; |
kshefov@638 | 35 | var HEIGHT = 600; |
kshefov@638 | 36 | var canvas = new Canvas(WIDTH, HEIGHT); |
kshefov@638 | 37 | function fileToURL(file) { |
kshefov@638 | 38 | return new File(file).toURI().toURL().toExternalForm(); |
kshefov@638 | 39 | } |
kshefov@638 | 40 | var imageUrl = fileToURL(__DIR__ + "flyingimage/flyingimage.png"); |
kshefov@638 | 41 | var img = new Image(imageUrl); |
kshefov@638 | 42 | var isFrameRendered = false; |
kshefov@638 | 43 | function renderFrame() { |
kshefov@667 | 44 | var t = frame; |
kshefov@638 | 45 | var gc = canvas.graphicsContext2D; |
kshefov@638 | 46 | gc.setFill(Color.web("#cccccc")); |
kshefov@638 | 47 | gc.fillRect(0, 0, WIDTH, HEIGHT); |
kshefov@638 | 48 | gc.setStroke(Color.web("#000000")); |
kshefov@638 | 49 | gc.setLineWidth(1); |
kshefov@638 | 50 | gc.strokeRect(5, 5, WIDTH - 10, HEIGHT - 10); |
kshefov@638 | 51 | var c = 200; |
kshefov@638 | 52 | var msc= 0.5 * HEIGHT / img.height; |
kshefov@638 | 53 | var sp0 = 0.003; |
kshefov@667 | 54 | for (var h = 0; h < c; h++) { |
kshefov@638 | 55 | gc.setTransform(1, 0, 0, 1, 0, 0); |
kshefov@638 | 56 | var yh = h / (c - 1); |
kshefov@638 | 57 | gc.translate((0.5 + Math.sin(t * sp0 + h * 0.1) / 3) * WIDTH, 25 + (HEIGHT * 3 / 4 - 40) * (yh * yh)); |
kshefov@638 | 58 | var sc = 30 / img.height + msc * yh * yh; |
kshefov@638 | 59 | gc.rotate(90 * Math.sin(t * sp0 + h * 0.1 + Math.PI)); |
kshefov@638 | 60 | gc.scale(sc, sc); |
kshefov@638 | 61 | gc.drawImage(img, -img.width / 2, -img.height / 2); |
kshefov@667 | 62 | } |
kshefov@638 | 63 | gc.setTransform(1, 0, 0, 1, 0, 0); |
kshefov@638 | 64 | isFrameRendered = true; |
kshefov@638 | 65 | } |
kshefov@638 | 66 | var stack = new StackPane(); |
kshefov@638 | 67 | var pane = new BorderPane(); |
kshefov@638 | 68 | pane.setCenter(canvas); |
kshefov@638 | 69 | stack.getChildren().add(pane); |
kshefov@638 | 70 | $STAGE.scene = new Scene(stack); |
kshefov@667 | 71 | var frame = 0; |
kshefov@667 | 72 | var timer = new AnimationTimerExtend() { |
kshefov@667 | 73 | handle: function handle(now) { |
kshefov@667 | 74 | if (frame < 200) { |
kshefov@667 | 75 | renderFrame(); |
kshefov@667 | 76 | frame++; |
kshefov@667 | 77 | } else { |
kshefov@667 | 78 | checkImageAndExit(); |
kshefov@667 | 79 | timer.stop(); |
kshefov@667 | 80 | } |
kshefov@667 | 81 | } |
kshefov@667 | 82 | }; |
kshefov@667 | 83 | timer.start(); |
kshefov@667 | 84 |