logo
down
shadow

How to make Circle with Four Color in Java


How to make Circle with Four Color in Java

By : ppatel
Date : November 23 2020, 03:01 PM
Hope this helps You can use java.awt.geom.Arc2D to draw slices of the Circle
see below code ,
code :
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class CircleDraw extends Frame {

    public void paint(Graphics g) {
        Graphics2D ga = (Graphics2D) g;

        ga.setPaint(Color.YELLOW);
        Arc2D arc2D4 = new Arc2D.Double(100.0f, 100.0f, 100.0f, 100.0f, 90, 270, Arc2D.PIE);
        ga.fill(arc2D4);
        ga.draw(arc2D4);

        ga.setPaint(Color.GREEN);
        Arc2D arc2D1 = new Arc2D.Double(100.0f, 100.0f, 100.0f, 100.0f, 90, 90d, Arc2D.PIE);
        ga.fill(arc2D1);
        ga.draw(arc2D1);

        ga.setPaint(Color.RED);
        Arc2D arc2D2 = new Arc2D.Double(100.0f, 100.0f, 100.0f, 100.0f, 360, 90d, Arc2D.PIE);
        ga.fill(arc2D2);
        ga.draw(arc2D2);

        ga.setPaint(Color.BLUE);
        Arc2D arc2D3 = new Arc2D.Double(100.0f, 100.0f, 100.0f, 100.0f, 180, 90d, Arc2D.PIE);
        ga.fill(arc2D3);
        ga.draw(arc2D3);

    }

    public static void main(String args[]) {
        Frame frame = new CircleDraw();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
        frame.setSize(300, 250);
        frame.setVisible(true);
    }
}


Share : facebook icon twitter icon
how to make border color only in the circle UIButton top?

how to make border color only in the circle UIButton top?


By : Kennet Trediente
Date : March 29 2020, 07:55 AM
I wish this help you I'm making center circle UIButton in UITabBarController. I need to paint the border color only where UIButton comes out of the tabBar border. How can I make it? We need border color only there https://monosnap.com/file/7MDqGzpUdIbClvnAvAiY2kJYKUro7z , I have done differently
code :
     private func setupLifelineButton() {
        lifelineButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
        var lifelineButtonFrame = lifelineButton.frame
        lifelineButtonFrame.origin.y = view.bounds.height - lifelineButtonFrame.height - 13 // default without 13
        lifelineButtonFrame.origin.x = view.bounds.width / 2 - lifelineButtonFrame.size.width / 2
        lifelineButton.frame = lifelineButtonFrame

        lifelineButton.backgroundColor = .whiteColor()
        lifelineButton.layer.cornerRadius = lifelineButtonFrame.height / 2

        lifelineButton.addTarget(self, action: #selector(showLifelineScreen), forControlEvents: .TouchUpInside)

        // icon 
        let lifelineImageView = UIImageView(image: UIImage(named: "LifeLineBarButtonIcon"))
        view.addSubview(lifelineButton)
        lifelineButton.addSubview(lifelineImageView)

        lifelineImageView.snp_makeConstraints { (make) in
            make.width.equalTo(ConstraintManager.widthByMainScreenByOriginalDigit(30))
            make.height.equalTo(ConstraintManager.heightByMainScreenByOriginalDigit(40))
            make.center.equalTo(lifelineButton)
        }


        // second view
        let path = UIBezierPath(arcCenter: CGPoint(x: lifelineButton.frame.width / 2, y: lifelineButton.frame.height / 2), radius: lifelineButtonFrame.height / 2, startAngle: CGFloat(-M_PI_2), endAngle: CGFloat(M_PI * 2 - M_PI_2), clockwise: true)

        let arc = Arc.sharedInstance
        arc.addFigure(path.CGPath, fillColor: .clearColor(), strokeColor: ColorManager.tabBarLayerColor, strokeStart: 0, strokeEnd: 0.23, lineWidth: 0.5, miterLimit: 0, lineDashPhase: 0, layer: lifelineButton.layer)
        arc.addFigure(path.CGPath, fillColor: .clearColor(), strokeColor: .whiteColor(), strokeStart: 0.23, strokeEnd: 0.77, lineWidth: 0.5, miterLimit: 0, lineDashPhase: 0, layer: lifelineButton.layer)
        arc.addFigure(path.CGPath, fillColor: .clearColor(), strokeColor: ColorManager.tabBarLayerColor, strokeStart: 0.77, strokeEnd: 1, lineWidth: 0.5, miterLimit: 0, lineDashPhase: 0, layer: lifelineButton.layer)

        view.layoutIfNeeded()
    }

public class Arc {

    public init() { }

    public static let sharedInstance = Arc()

    public func addFigure(path: CGPath, fillColor: UIColor, strokeColor: UIColor, strokeStart: CGFloat, strokeEnd: CGFloat, lineWidth: CGFloat, miterLimit: CGFloat, lineDashPhase: CGFloat, layer: CALayer) {
        let shape = CAShapeLayer()
        shape.path = path
        shape.fillColor = fillColor.CGColor
        shape.strokeColor = strokeColor.CGColor
        shape.strokeStart = strokeStart
        shape.strokeEnd = strokeEnd
        shape.lineWidth = lineWidth
        shape.miterLimit = miterLimit
        shape.lineDashPhase = lineDashPhase
        layer.addSublayer(shape)
    }

    public func drawCircle(arcRadius: CGFloat, miniRadius: CGFloat, fillColor: UIColor, strokeColor: UIColor, view: UIView) {

    }
}
how to change the color of circle to back with original color on clicking of another circle in D3 Js chart

how to change the color of circle to back with original color on clicking of another circle in D3 Js chart


By : ankit
Date : March 29 2020, 07:55 AM
help you fix your problem I have a D3 JS chart which draws Circle for each Class and radius for each circle is NoOfStudents in that particular class. , Give the circles a class to select them later :
code :
.attr("class", "bar allCircles") //i didnt use 'bar' on purpose as you may have used it elsewhere
circles.on("click", function (d) {
        d3.selectAll('.allCircles').style('fill','black'); //fill all circles black
        d3.select(this).style("fill", "lightcoral"); //then fill this circle lightcoral
    });
React Native - ios - circle with border - circle background color spilling out of circle

React Native - ios - circle with border - circle background color spilling out of circle


By : shallu
Date : March 29 2020, 07:55 AM
Hope that helps This looks like a bug in React Native. You can work around it by using 2 circles:
code :
class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.outerCircle}>
      	  <View style={styles.innerCircle} />
      	</View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'white',
  },
  outerCircle: {
    borderRadius: 40,
    width: 80,
    height: 80,
    backgroundColor: 'white',
  },
  innerCircle: {
    borderRadius: 35,
    width: 70,
    height: 70,
    margin: 5,
    backgroundColor: 'black'
  },
});
CSS: how to make a circle with 60% one color and 40% other color around an image?

CSS: how to make a circle with 60% one color and 40% other color around an image?


By : user1487343
Date : March 29 2020, 07:55 AM
Hope this helps Is it possible to make a circle with 60% one color and 40% other color around an image. , you can do it like this:
code :
.box {
  border-radius:50%;
  display:inline-block;
  padding:5px;
  background:
   linear-gradient(-40deg, grey 50%,transparent 0), /*adjust the deg value here to control the %*/
   linear-gradient(to right, red 50%,transparent 0),
   grey;
}
.box img {
  border-radius:50%;
  display:block;
}
<div class="box">
<img src="https://picsum.photos/100/100?image=1069" >
</div>
how to make a circle changes its color for every second?

how to make a circle changes its color for every second?


By : Kerlis
Date : March 29 2020, 07:55 AM
I hope this helps . Although the response of @f.wue works apparently is not correct since you should not use time.sleep() in the GUI thread since it freezes the application, for example try to resize the window while running the time.sleep().
Instead you should use a QTimer as you say, that timer must connect to a function that changes the color and call the update() method that indirectly invokes the paintEvent()event. Since you want colors to change colors cyclically, you must create a cyclic iterator.
code :
from itertools import cycle
from PyQt5 import QtCore, QtGui, QtWidgets

class TrafficLight(QtWidgets.QMainWindow):
    def __init__(self,parent = None):
        super(TrafficLight, self).__init__(parent)
        self.setWindowTitle("TrafficLight ")
        self.traffic_light_colors = cycle([
            QtGui.QColor('red'),
            QtGui.QColor('yellow'),
            QtGui.QColor('green')
        ])
        self._current_color = next(self.traffic_light_colors)
        timer = QtCore.QTimer(
            self, 
            interval=2000, 
            timeout=self.change_color
        )
        timer.start()
        self.resize(200, 400)

    @QtCore.pyqtSlot()
    def change_color(self):
        self._current_color = next(self.traffic_light_colors)
        self.update()

    def paintEvent(self, event):
        p = QtGui.QPainter(self)
        p.setBrush(self._current_color)
        p.setPen(QtCore.Qt.black)
        p.drawEllipse(self.rect().center(), 50, 50)

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = TrafficLight()
    w.show() 
    sys.exit(app.exec_())
shadow
Privacy Policy - Terms - Contact Us © voile276.org