java - JavaFX Olympic Rings overlap in the correct order -
this first time posting here. i'm doing assignment need create olympic rings in javafx , make them intersect in correct places.
this it's supposed like:
currently, rings intersect dominate in order created objects. blue gets covered yellow when intersect, yellow gets covered black when intersect, etc. can see in picture of olympic rings, first time yellow , blue intersect, yellow covers blue, blue covers yellow second time. each of rings gets covered other ring 1 time intersect, covers other time.
if point me in right direction how make them intersect properly, fantastic.
here code have far:
package com.company; import javafx.application.application; import javafx.scene.scene; import javafx.scene.layout.pane; import javafx.scene.paint.color; import javafx.scene.shape.circle; import javafx.stage.stage; public class olympicrings extends application{ public void start(stage primarystage) { //creates new object, first circle circle circle1 = new circle(); circle1.setcenterx(100); //sets x coordinate center of circle circle1.setcentery(100); //sets y coordinate center of circle circle1.setradius(50); //sets radius of circle 50, makes diameter 100 circle1.setstroke(color.blue); //sets color of circle circle1.setstrokewidth(10); //sets thickness of lines circle1.setfill(null); //sets color of inside of circle, set null enable overlap circle circle2 = new circle(); //creates additional circles circle2.setcenterx(160); circle2.setcentery(150); circle2.setradius(50); circle2.setstroke(color.yellow); circle2.setstrokewidth(10); circle2.setfill(null); circle circle3 = new circle(); circle3.setcenterx(220); circle3.setcentery(100); circle3.setradius(50); circle3.setstroke(color.black); circle3.setstrokewidth(10); circle3.setfill(null); circle circle4 = new circle(); circle4.setcenterx(280); circle4.setcentery(150); circle4.setradius(50); circle4.setstroke(color.green); circle4.setstrokewidth(10); circle4.setfill(null); circle circle5 = new circle(); circle5.setcenterx(340); circle5.setcentery(100); circle5.setradius(50); circle5.setstroke(color.red); circle5.setstrokewidth(10); circle5.setfill(null); //creating pane display circle pane pane = new pane(); pane.getchildren().add(circle1); //each of these adds various circles display of pane pane.getchildren().add(circle2); pane.getchildren().add(circle3); pane.getchildren().add(circle4); pane.getchildren().add(circle5); scene scene1 = new scene(pane, 440, 250); //creates parameters of pane primarystage.settitle("olympic rings"); //names pane primarystage.setscene(scene1); //picks go in pane primarystage.show(); //shows scene i've created } }
this hard achieve circle
s. heavy use of clip
property , resulting code wouldn't readable.
instead arc
s can used draw parts of rings. add covered part of ring parent before adding covering part.
example first 2 rings:
private static arc createarc(double radius, double centerx, double centery, double fromangle, double toangle, paint stroke, double strokewidth) { arc arc = new arc(centerx, centery, radius, radius, fromangle, toangle - fromangle); arc.setfill(null); arc.setstroke(stroke); arc.setstrokewidth(strokewidth); return arc; } @override public void start(stage primarystage) { pane pane = new pane( createarc(50, 60, 60, 90, 315, color.blue, 10), // part of blue ring containing part covered yellow createarc(50, 110, 110, 0, 360, color.yellow, 10), createarc(50, 60, 60, -45, 90, color.blue, 10) // part covering yellow ring ); scene scene = new scene(pane); primarystage.setscene(scene); primarystage.show(); }
Comments
Post a Comment