This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xenthera's profile picture

Computercraft Graphics Library

Started by Xenthera, 29 October 2014 - 02:12 AM
Xenthera #1
Posted 29 October 2014 - 03:12 AM
After messing around in Slick2D, I realized computercraft doesn't really have a standard library to draw primitive shapes. paintutils has drawLine, but that's about it.

I've written this from various sources around the web, and hopefully this can become a standard library included in computercraft. (here's to hoping)

You are allowed, and even encouraged to modify, tidy up and/or optimize the source. Post the changes here and i'll update this thread

http://pastebin.com/sA0A9wzL





Methods:


--//line		args:(x1,y1,x2,y1)
--//rect		args:(x,y,width,height)
--//circle	  args:(x,y,radius)
--//ellipse	 args:(x,y,width,height)
--//arc		 args:(x,y,radius,startAngle,endAngle,segments --filled only)
--//triangle	args:(x1,y1,x2,y2,x3,y3)

To use it, i'd personally use

g = dofile("graphicsUtils") – or whatever you saved it as
g.methodName()


drawMethod draw the outline of specified shape ex: drawCircle(args)

fillMethod draw the filled version of specified shape ex: fillCircle(args)


demo source: http://pastebin.com/QxLJsbu9

TODO:
  1. Bezier curves
  2. Line width
  3. Polygons
Edited on 29 October 2014 - 02:37 AM
com_kieffer #2
Posted 29 October 2014 - 10:17 AM
This looks awesome. I'll remember it in future projects.
Bomb Bloke #3
Posted 29 October 2014 - 10:48 AM
A suggestion: how about rigging it to account for the fact that characters aren't square? The width of three characters is equal to the height of two characters.
Xenthera #4
Posted 29 October 2014 - 05:56 PM
A suggestion: how about rigging it to account for the fact that characters aren't square? The width of three characters is equal to the height of two characters.

I didn't do that, because that's the charm of computercraft.

However, if you multiply the height by 0.66 you can get some pretty evenly proportioned objects

Xenthera #5
Posted 14 November 2014 - 12:53 AM
I sincerely apologize. Apparently some characters that didn't belong found their way into the code. If you tried to download this and it didn't work, that's probably why. I tested everything inside and out before I posted, so i'm not sure how it happened.

With great embarrassment,
- X

P.S. In less than 3 weeks i'm shipping off to join the U.S. Navy and I will no longer be around. This community has been great and I thank everyone who puts their time and effort into programs that do some amazing things.
RoD #6
Posted 17 February 2015 - 11:12 PM
if you multiply the height by 0.66 you can get some pretty evenly proportioned objects

How does multiplying the height makes it more proportional, if the cc pixels are higher than their width? Shouldn't you divide instead? Or multiply the width?
Bomb Bloke #7
Posted 17 February 2015 - 11:32 PM
That particular multiplication reduces the height down to two thirds. It's about the same as multiplying by two and then dividing by three.
RoD #8
Posted 18 February 2015 - 06:34 PM
That particular multiplication reduces the height down to two thirds. It's about the same as multiplying by two and then dividing by three.
lol fail, i am so stupid… its 0.66 not 1.66 i didnt noticed that it was a 0, my bad :P/>
CCJJSax #9
Posted 29 August 2016 - 06:49 PM
Hey I'm just checking with you to see if it's ok. I am making a tunnel program with some graphics on it. I have my own graphics api, but it is clearly not as good as yours. Can I have my program download this file as long as I give you full credit and link to this page? I don't want to up and steal it.
Bomb Bloke #10
Posted 30 August 2016 - 06:34 AM
Xenthera hasn't been around for a while, so I'll go ahead and say that he uploaded it in the specific hope that someone else would use it. ;)/>
Lupus590 #11
Posted 30 August 2016 - 08:58 AM
Feel free to modify and use as you see fit
- Source: http://pastebin.com/sA0A9wzL Line 3
TheRockettek #12
Posted 30 August 2016 - 09:07 AM
In less than 3 weeks i'm shipping off to join the U.S. Navy and I will no longer be around. This community has been great and I thank everyone who puts their time and effort into programs that do some amazing things.
MarcoPolo0306 #13
Posted 09 September 2016 - 11:49 PM
is dat pacman?