Tue, 16 Aug 2016 21:41:28 -0700
Added tag jdk8u102-b33 for changeset 36e3c21b5fca
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 = "kaleidoscope"; |
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 | var context = canvas.graphicsContext2D; |
kshefov@638 | 38 | |
kshefov@638 | 39 | var x,y; |
kshefov@638 | 40 | var p_x,p_y; |
kshefov@638 | 41 | var a=0; |
kshefov@638 | 42 | var b=0; |
kshefov@638 | 43 | var angle=Math.PI/180*8; |
kshefov@638 | 44 | var color=0; |
kshefov@638 | 45 | var limit1=Math.PI*1.5; |
kshefov@638 | 46 | var limit2=Math.PI*1.79; |
kshefov@638 | 47 | var c=new Array(6); |
kshefov@638 | 48 | var d=new Array(6); |
kshefov@638 | 49 | var r,e; |
kshefov@638 | 50 | var fade; |
kshefov@638 | 51 | var prv_x,prv_y,prv_x2,prv_y2; |
kshefov@667 | 52 | var isFrameRendered = false; |
kshefov@638 | 53 | |
kshefov@638 | 54 | function renderFrame() { |
attila@962 | 55 | if (!isFrameRendered) { |
kshefov@667 | 56 | a=0.2*angle; |
attila@962 | 57 | b=0.7*angle; |
attila@962 | 58 | r=0; |
attila@962 | 59 | fade=32; |
attila@962 | 60 | for(var i=0;i<6;i++) |
attila@962 | 61 | { |
attila@962 | 62 | c[i]=1.0/(i+1)/2; |
attila@962 | 63 | d[i]=1.0/(i+1)/2; |
attila@962 | 64 | } |
attila@962 | 65 | radius=Math.round((WIDTH+HEIGHT)/8); |
attila@962 | 66 | e=radius*0.2; |
attila@962 | 67 | p_x=Math.round(WIDTH/2); |
attila@962 | 68 | p_y=Math.round(HEIGHT/2); |
attila@962 | 69 | x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]); |
attila@962 | 70 | y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]); |
kshefov@667 | 71 | isFrameRendered = true; |
kshefov@638 | 72 | } |
kshefov@667 | 73 | anim(); |
kshefov@638 | 74 | } |
kshefov@638 | 75 | |
kshefov@638 | 76 | function anim() { |
attila@962 | 77 | var a1=Math.cos(a*2); |
attila@962 | 78 | var a2=Math.cos(a*4); |
attila@962 | 79 | var a3=Math.cos(a); |
attila@962 | 80 | var a4=Math.sin(a); |
attila@962 | 81 | if(b>limit1&&b<limit2) { |
attila@962 | 82 | r+=radius*0.02*a1; |
attila@962 | 83 | prv_x=x; |
attila@962 | 84 | prv_y=y; |
attila@962 | 85 | x=prv_x2+r*a3; |
attila@962 | 86 | y=prv_y2+r*a4; |
attila@962 | 87 | } else { |
attila@962 | 88 | prv_x=x; |
attila@962 | 89 | prv_y=y; |
attila@962 | 90 | prv_x2=x; |
attila@962 | 91 | prv_y2=y; |
attila@962 | 92 | x=(radius*c[0])*Math.cos(a*d[1])+(radius*c[2])*Math.sin(a*d[3])+(radius*c[4])*Math.sin(a*d[5]); |
attila@962 | 93 | y=(radius*c[5])*Math.sin(a*d[4])+(radius*c[3])*Math.cos(a*d[2])+(radius*c[1])*Math.cos(a*d[0]); |
attila@962 | 94 | } |
attila@962 | 95 | var c3=16*Math.cos(a*10); |
attila@962 | 96 | var c1=Math.floor(56*Math.cos(a*angle*4)+c3); |
attila@962 | 97 | var c2=Math.floor(56*Math.sin(a*angle*4)-c3); |
attila@962 | 98 | context.lineCap=StrokeLineCap.ROUND; |
attila@962 | 99 | context.setStroke(Paint.valueOf('rgba('+(192+c1)+','+(192+c2)+','+(192-c1)+','+(0.01-0.005*-a1)+')')); |
attila@962 | 100 | context.lineWidth=e*1.4+e*0.8*a3; |
attila@962 | 101 | draw_line(p_x,p_y,prv_x,prv_y,x,y); |
attila@962 | 102 | context.lineWidth=e+e*0.8*a3; |
attila@962 | 103 | draw_line(p_x,p_y,prv_x,prv_y,x,y); |
attila@962 | 104 | context.setStroke(Paint.valueOf('rgba('+(192+c1)+','+(192+c2)+','+(192-c1)+','+(0.06-0.03*-a1)+')')); |
attila@962 | 105 | context.lineWidth=e*0.6+e*0.35*a3; |
attila@962 | 106 | draw_line(p_x,p_y,prv_x,prv_y,x,y); |
attila@962 | 107 | context.setStroke(Paint.valueOf('rgba(0,0,0,0.06)')); |
attila@962 | 108 | context.lineWidth=e*0.4+e*0.225*a3; |
attila@962 | 109 | draw_line(p_x,p_y,prv_x,prv_y,x,y); |
attila@962 | 110 | context.setStroke(Paint.valueOf('rgba('+(192+c1)+','+(192+c2)+','+(192-c1)+','+(0.1-0.075*-a1)+')')); |
attila@962 | 111 | context.lineWidth=e*0.2+e*0.1*a3; |
attila@962 | 112 | draw_line(p_x,p_y,prv_x,prv_y,x,y); |
attila@962 | 113 | context.setStroke(Paint.valueOf('rgba(255,255,255,0.4)')); |
attila@962 | 114 | context.lineWidth=e*(0.1-0.05*-a2); |
attila@962 | 115 | draw_line(p_x,p_y,prv_x,prv_y,x,y); |
attila@962 | 116 | a+=angle*Math.cos(b); |
attila@962 | 117 | b+=angle*0.1; |
kshefov@638 | 118 | } |
kshefov@638 | 119 | |
kshefov@638 | 120 | function draw_line(x,y,x1,y1,x2,y2) { |
attila@962 | 121 | context.beginPath(); |
attila@962 | 122 | context.moveTo(x+x1,y+y1); |
attila@962 | 123 | context.lineTo(x+x2,y+y2); |
attila@962 | 124 | context.moveTo(x-x1,y+y1); |
attila@962 | 125 | context.lineTo(x-x2,y+y2); |
attila@962 | 126 | context.moveTo(x-x1,y-y1); |
attila@962 | 127 | context.lineTo(x-x2,y-y2); |
attila@962 | 128 | context.moveTo(x+x1,y-y1); |
attila@962 | 129 | context.lineTo(x+x2,y-y2); |
attila@962 | 130 | context.moveTo(x+y1,y+x1); |
attila@962 | 131 | context.lineTo(x+y2,y+x2); |
attila@962 | 132 | context.moveTo(x-y1,y+x1); |
attila@962 | 133 | context.lineTo(x-y2,y+x2); |
attila@962 | 134 | context.moveTo(x-y1,y-x1); |
attila@962 | 135 | context.lineTo(x-y2,y-x2); |
attila@962 | 136 | context.moveTo(x+y1,y-x1); |
attila@962 | 137 | context.lineTo(x+y2,y-x2); |
attila@962 | 138 | context.moveTo(x,y+x2); |
attila@962 | 139 | context.lineTo(x,y+x1); |
attila@962 | 140 | context.moveTo(x,y-x2); |
attila@962 | 141 | context.lineTo(x,y-x1); |
attila@962 | 142 | context.moveTo(x+x2,y); |
attila@962 | 143 | context.lineTo(x+x1,y); |
attila@962 | 144 | context.moveTo(x-x2,y); |
attila@962 | 145 | context.lineTo(x-x1,y); |
attila@962 | 146 | context.stroke(); |
attila@962 | 147 | context.closePath(); |
kshefov@638 | 148 | } |
kshefov@638 | 149 | |
kshefov@638 | 150 | var stack = new StackPane(); |
kshefov@638 | 151 | var pane = new BorderPane(); |
kshefov@638 | 152 | pane.setCenter(canvas); |
kshefov@638 | 153 | stack.getChildren().add(pane); |
kshefov@638 | 154 | $STAGE.scene = new Scene(stack); |
kshefov@667 | 155 | var frame = 0; |
kshefov@667 | 156 | var timer = new AnimationTimerExtend() { |
kshefov@667 | 157 | handle: function handle(now) { |
kshefov@667 | 158 | if (frame < 800) { |
kshefov@667 | 159 | renderFrame(); |
kshefov@667 | 160 | frame++; |
kshefov@667 | 161 | } else { |
kshefov@667 | 162 | checkImageAndExit(); |
kshefov@667 | 163 | timer.stop(); |
kshefov@667 | 164 | } |
kshefov@667 | 165 | } |
kshefov@667 | 166 | }; |
kshefov@667 | 167 | timer.start(); |