Just another WordPress.com site

Posts tagged ‘Java’

Lightbulb Drawing

This is what a real lightbulb looks like:

This is the hand-drawing I made (the stuff to the side are the mathematical stuff to extract the geometric constants).  The picture is a little grainy, because, like all the other drawings,this was taken by webcam.

And this, is the actual computer version of my geometric interpretation of the silhouette of a lightbulb.  Ignore the dot.  And the line below the lightbulb is the wire supplying the electricity.  It’s technically a part of the lightbulb apparatus.

 

And now, you can make lightbulbs too!  All you need is a JFrame that paints a full black screen, then copy-paste this code in front of the black screen in your paint method, with the graphics object being called “g”.  This is java code, and will not work in a C program, or Python, or C++, or Pascal, or Whirl, or PHP, or Perl, or Assembly, or Befunge, or Basic.

g.setColor(Color.WHITE);
g.drawOval(250,400,300,300);
for (int i=0;i<=6;i++) {
g.drawLine(325,250+25*i,475,250+25*i);
if (i!=3) {
g.drawLine(325+25*i,250,325+25*i,550-(int)Math.sqrt(150*150-(325+25*i-400)*(325+25*i-400)));
}
}
g.drawRect(350,225,100,25);
g.drawLine(400,150,400,225);
g.drawLine(400,400,400,600);
g.drawRect(375,400,50,150);
for (int i=0;i<=3;i++) {
g.drawArc(388,425+50*i-32,64,64,129,102);
g.drawArc(348,425+50*i-32,64,64,-51,102);
}

Tag Cloud